Changeset 504

Show
Ignore:
Timestamp:
10/15/09 11:48:08 (4 years ago)
Author:
ged
Message:

- Fixed custom bases classes and versioned extension when used with zope

interfaces (closes #98, patch from Valentin Lab)

Location:
elixir/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/AUTHORS

    r409 r504  
    2020- Remi Jolin 
    2121- Robin Munn 
     22- Valentin Lab 
    2223- some anonymous contributions I couldn't trace to someone in particular 
  • elixir/trunk/CHANGES

    r490 r504  
    22 
    33Changes: 
    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 
     7Bug fixes: 
     8- Fixed custom bases classes along side zope interfaces (closes #98, patch from 
     9  Valentin Lab) 
    710 
    8110.7.0 - 2009-10-01 
  • elixir/trunk/elixir/entity.py

    r500 r504  
    55 
    66import sys 
    7 import inspect 
    87import types 
    98import warnings 
     
    319318        # create a list of callbacks for each event 
    320319        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 
    338329        if not methods: 
    339330            return 
     
    691682 
    692683 
     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 
     687def 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 
    693699def instrument_class(cls): 
    694700    """ 
     
    710716        # We use inspect.getmembers (instead of __dict__) so that we also 
    711717        # 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)) 
    714720        base_props = [(name, copy(attr)) for name, attr in base_props] 
    715721    else: 
  • elixir/trunk/elixir/ext/versioned.py

    r409 r504  
    5656from elixir.statements     import Statement 
    5757from elixir.properties     import EntityBuilder 
     58from elixir.entity         import getmembers 
    5859 
    5960__all__ = ['acts_as_versioned', 'after_revert'] 
     
    177178        # look for events 
    178179        after_revert_events = [] 
    179         for name, func in inspect.getmembers(entity, inspect.ismethod): 
     180        for name, func in getmembers(entity, inspect.ismethod): 
    180181            if getattr(func, '_elixir_after_revert', False): 
    181182                after_revert_events.append(func) 
  • elixir/trunk/tests/test_custombase.py

    r490 r504  
    3535 
    3636        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 
    3756 
    3857    def test_inherit(self):