| 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | ########################################################################## |
| 4 | # |
| 5 | # Wrapper générique |
| 6 | # |
| 7 | ########################################################################## |
| 8 | # WxGeometrie |
| 9 | # Dynamic geometry, graph plotter, and more for french mathematic teachers. |
| 10 | # Copyright (C) 2005-2013 Nicolas Pourcelot |
| 11 | # |
| 12 | # This program is free software; you can redistribute it and/or modify |
| 13 | # it under the terms of the GNU General Public License as published by |
| 14 | # the Free Software Foundation; either version 2 of the License, or |
| 15 | # (at your option) any later version. |
| 16 | # |
| 17 | # This program is distributed in the hope that it will be useful, |
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | # GNU General Public License for more details. |
| 21 | # |
| 22 | # You should have received a copy of the GNU General Public License |
| 23 | # along with this program; if not, write to the Free Software |
| 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | |
| 26 | |
| 27 | # Motivation: |
| 28 | # http://docs.python.org/reference/datamodel.html#more-attribute-access-for-new-style-classes |
| 29 | |
| 30 | |
| 31 | #TODO:this must wrap all special methods |
| 32 | |
| 33 | |
| 34 | class GenericWrapper(object): |
| 35 | |
| 36 | slots = '__val' |
| 37 | |
| 38 | def __init__(self, val): |
| 39 | object.__setattr__(self, '_GenericWrapper__val', val) |
| 40 | |
| 41 | def __getattribute__(self, name): |
| 42 | val = object.__getattribute__(self, '_GenericWrapper__val') |
| 43 | return getattr(val, name) |
| 44 | |
| 45 | def __setattr__(self, name, val): |
| 46 | val = object.__getattribute__(self, '_GenericWrapper__val') |
| 47 | return setattr(val, name, val) |