Changeset 504
- Timestamp:
- 10/15/09 11:48:08 (4 years ago)
- Location:
- elixir/trunk
- Files:
-
- 5 modified
-
AUTHORS (modified) (1 diff)
-
CHANGES (modified) (1 diff)
-
elixir/entity.py (modified) (4 diffs)
-
elixir/ext/versioned.py (modified) (2 diffs)
-
tests/test_custombase.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/AUTHORS
r409 r504 20 20 - Remi Jolin 21 21 - Robin Munn 22 - Valentin Lab 22 23 - some anonymous contributions I couldn't trace to someone in particular -
elixir/trunk/CHANGES
r490 r504 2 2 3 3 Changes: 4 Dropped support for python 2.3, SQLAlchemy 0.4 and deprecated stuff from Elixir 5 0.7 6 4 - Dropped support for python 2.3, SQLAlchemy 0.4 and deprecated stuff from 5 Elixir 0.7 6 7 Bug fixes: 8 - Fixed custom bases classes along side zope interfaces (closes #98, patch from 9 Valentin Lab) 7 10 8 11 0.7.0 - 2009-10-01 -
elixir/trunk/elixir/entity.py
r500 r504 5 5 6 6 import sys 7 import inspect8 7 import types 9 8 import warnings … … 319 318 # create a list of callbacks for each event 320 319 methods = {} 321 entity = self.entity 322 323 # Note that we don't use inspect.getmembers because of 324 # http://bugs.python.org/issue1785 325 # See also http://elixir.ematia.de/trac/changeset/262 326 327 # dir returns the attributes of the class and *all its parents* listed 328 # alphabetically. 329 for key in dir(entity): 330 try: 331 value = getattr(entity, key) 332 if isinstance(value, types.MethodType): 333 for event in getattr(value, '_elixir_events', []): 334 event_methods = methods.setdefault(event, []) 335 event_methods.append(value) 336 except AttributeError: 337 pass 320 321 all_methods = getmembers(self.entity, 322 lambda a: isinstance(a, types.MethodType)) 323 324 for name, method in all_methods: 325 for event in getattr(method, '_elixir_events', []): 326 event_methods = methods.setdefault(event, []) 327 event_methods.append(method) 328 338 329 if not methods: 339 330 return … … 691 682 692 683 684 # Note that we don't use inspect.getmembers because of 685 # http://bugs.python.org/issue1785 686 # See also http://elixir.ematia.de/trac/changeset/262 687 def getmembers(object, predicate=None): 688 base_props = [] 689 for key in dir(object): 690 try: 691 value = getattr(object, key) 692 except AttributeError: 693 continue 694 if not predicate or predicate(value): 695 base_props.append((key, value)) 696 return base_props 697 698 693 699 def instrument_class(cls): 694 700 """ … … 710 716 # We use inspect.getmembers (instead of __dict__) so that we also 711 717 # get the properties from the parents of the base_class if any. 712 base_props = inspect.getmembers(entity_base,713 lambda a: isinstance(a, Property))718 base_props = getmembers(entity_base, 719 lambda a: isinstance(a, Property)) 714 720 base_props = [(name, copy(attr)) for name, attr in base_props] 715 721 else: -
elixir/trunk/elixir/ext/versioned.py
r409 r504 56 56 from elixir.statements import Statement 57 57 from elixir.properties import EntityBuilder 58 from elixir.entity import getmembers 58 59 59 60 __all__ = ['acts_as_versioned', 'after_revert'] … … 177 178 # look for events 178 179 after_revert_events = [] 179 for name, func in inspect.getmembers(entity, inspect.ismethod):180 for name, func in getmembers(entity, inspect.ismethod): 180 181 if getattr(func, '_elixir_after_revert', False): 181 182 after_revert_events.append(func) -
elixir/trunk/tests/test_custombase.py
r490 r504 35 35 36 36 assert a.name == 'a1' 37 38 def test_bad_property(self): 39 # create a meta entity which mimick cases where dir() method 40 # will report attribute that can't be directly accessed. 41 # Note: this happens with zope.interface. See ticket #98. 42 class BrokenDescriptor(object): 43 def __get__(*args): 44 raise AttributeError 45 46 class MyEntity(EntityBase): 47 __metaclass__ = EntityMeta 48 49 d = BrokenDescriptor() 50 51 class A(MyEntity): 52 value = Field(Unicode) 53 54 # we just check that the instrument_class phases doesn't trigger an 55 # exception 37 56 38 57 def test_inherit(self):
