Changeset 3561

Show
Ignore:
Timestamp:
09/15/07 15:33:22 (1 year ago)
Author:
mscott
Message:

Merge #67:

schevo.test.test_field, schevo.test.test_field_factory_aliases

  • Use a new method to record deprecation warnings in a doctest-able manner. The old method worked under Python 2.4 but did not work under Python 2.5.

SchevoZodb?

  • Require 3.8.0 series of ZODB3, as the 3.7.0 series will not work with Python 2.5

wiki:Twitabit

  • depend on newer version of AuthKit? 0.4-dev

Not related to #67, to be handled further in #68:

schevopolicy.rentity, schevopolicy.rtransaction

  • Some fixes for regressions unrelated to Python 2.5
  • Will make separate branch to fix these regressions

    schevo.field:EntityList._transform, schevo.field:EntitySet._transform, schevo.field:EntitySetSet._transform
  • Pay closer attention to original value type, and use that type when creating the new value.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Policy/schevopolicy/rentity.py

    r3383 r3561  
    99from schevo import base 
    1010from schevo.entity import Entity 
     11from schevo import field 
    1112from schevo.label import label, with_label 
    1213 
     
    4849 
    4950    def __getattr__(self, name): 
    50         entity = self._entity 
    5151        if name not in self._field_spec: 
    5252            raise AttributeError('Field %r not in %r' % (name, self)) 
    5353        self._unauthorized_if_getattr_disallowed() 
    54         value = getattr(entity, name) 
    55         # XXX: Also needs to handle EntityList, etc. 
    56         if isinstance(value, Entity): 
     54        f = self._entity.f[name] 
     55        # Copy the field if it is an entity field, and transform it. 
     56        if f.may_store_entities: 
     57            f = f.copy() 
    5758            db = self._db 
    58             value = RestrictedEntity( 
    59                 self._policy, self._context, db, db.extent(value._extent), 
    60                 value) 
    61         return value 
     59            policy = self._policy 
     60            context = self._context 
     61            extent = db.extent 
     62            def to_rentity(e): 
     63                return RestrictedEntity( 
     64                    policy, context, db, extent(e._extent), e) 
     65            f._transform(to_rentity) 
     66        return f.get() 
    6267 
    6368    def __hash__(self): 
    6469        return hash(self._entity) 
     70 
     71    @property 
     72    def _default_key(self): 
     73        return self._entity._default_key 
    6574 
    6675    @property 
  • trunk/Policy/schevopolicy/rtransaction.py

    r3383 r3561  
    4444        if name not in self._field_spec: 
    4545            raise AttributeError('Field %r not in %r' % (name, self)) 
    46         # Convert to RestrictedEntity as necessary. 
    47         # XXX: Short-term code; need to generalize this to support 
    48         # EntityList etc. 
     46##         f = self._tx.f[name] 
     47##         # Copy the field if it is an entity field, and transform it. 
     48##         if f.may_store_entities: 
     49##             f = f.copy() 
     50##             db = self._db 
     51##             policy = self._policy 
     52##             context = self._context 
     53##             extent = db.extent 
     54##             def to_rentity(e): 
     55##                 return RestrictedEntity( 
     56##                     policy, context, db, extent(e._extent), e) 
     57##             f._transform(to_rentity) 
     58##         return f.get() 
    4959        value = getattr(self._tx, name) 
    5060        if isinstance(value, Entity): 
     
    112122            field = field.copy() 
    113123            db = self._db 
     124            policy = self._policy 
     125            context = self._context 
     126            extent = db.extent 
    114127            def to_rentity(e): 
    115128                return RestrictedEntity( 
    116                     self._policy, self._context, db, db.extent(e._extent), e) 
     129                    policy, context, db, extent(e._extent), e) 
    117130            field._transform(to_rentity) 
    118131        return field 
  • trunk/Schevo/schevo/field.py

    r3513 r3561  
    13631363    def _transform(self, transform_entity): 
    13641364        value = self._value 
    1365         if isinstance(value, list): 
    1366             self._value = [transform_entity(entity) for entity in value] 
     1365        if isinstance(value, (list, tuple)): 
     1366            L = [] 
     1367            for entity in value: 
     1368                if entity is not UNASSIGNED: 
     1369                    L.append(transform_entity(entity)) 
     1370                else: 
     1371                    L.append(UNASSIGNED) 
     1372            if isinstance(value, tuple): 
     1373                self._value = tuple(L) 
     1374            else: 
     1375                self._value = L 
    13671376 
    13681377    def _unassign(self, member): 
     
    14741483        value = self._value 
    14751484        if isinstance(value, (set, frozenset)): 
    1476             self._value = set(transform_entity(entity) for entity in value) 
     1485            self._value = type(value)( 
     1486                transform_entity(entity) for entity in value) 
    14771487 
    14781488    def validate(self, value): 
     
    15771587        value = self._value 
    15781588        if isinstance(value, (set, frozenset)): 
    1579             self._value = set
     1589            self._value = type(value)
    15801590                frozenset(transform_entity(entity) for entity in item_set) 
    15811591                for item_set in value 
  • trunk/Schevo/schevo/test/test_field.py

    r3382 r3561  
    546546 
    547547class TestPasswordIsDeprecated(object): 
    548  
    549548    """ 
    550     Change `showwarning` to log to a list instead of to stderr, so w
    551     can test the deprecation warning below:: 
     549    Change `showwarning` to record deprecation warnings somewher
     550    other than stderr, so we can test the deprecation warning below:: 
    552551 
    553552        >>> import warnings 
    554553        >>> old_showwarning = warnings.showwarning 
    555         >>> captured_warnings = [] 
    556554        >>> def showwarning(message, category, filename, lineno, file=None): 
    557         ...     captured_warnings.append((message, category, filename, lineno)) 
     555        ...     warnings.last_lineno = lineno 
     556        ...     warnings.last_message = message 
    558557        >>> warnings.showwarning = showwarning 
    559558 
     
    567566 
    568567    When using the schema, a deprecation warning is given for the `p` 
    569     field definition:: 
     568    field definition.  The line number that the warning is on appears 
     569    to be line four above, but since a two-line header is prepended to 
     570    the body during unit testing, it's actually line six that the 
     571    warning occurs at:: 
    570572 
    571573        >>> from schevo.test import DocTest 
    572         >>> len_before = len(captured_warnings) 
    573574        >>> t = DocTest(body) 
    574         >>> len_after = len(captured_warnings) 
    575         >>> len_after - len_before 
    576         1 
    577         >>> message, category, filename, lineno = captured_warnings[-1] 
    578         >>> print str(message)  #doctest: +ELLIPSIS 
    579         'password' is a deprecated field type. ... 
    580  
    581     The line number that the warning is on appears to be line four 
    582     above, but since a two-line header is prepended to the body during 
    583     unit testing, it's actually line six that the warning occurs at:: 
    584  
    585         >>> lineno 
     575        >>> print warnings.last_message  #doctest: +ELLIPSIS 
     576        'password' is a deprecated field type.  See ... 
     577        >>> warnings.last_lineno 
    586578        6 
    587579 
     
    590582 
    591583        >>> warnings.showwarning = old_showwarning 
    592  
    593584    """ 
    594585 
  • trunk/Schevo/schevo/test/test_field_factory_aliases.py

    r3382 r3561  
    88 
    99class TestFieldFactoryDeprecatedNames(BaseTest): 
    10  
    1110    """ 
    12     Change `showwarning` to log to a list instead of to stderr, so we can 
    13     test the deprecation warning below:: 
     11    Change `showwarning` to record deprecation warnings somewhere 
     12    other than stderr, so we can test the deprecation warning below:: 
    1413 
    1514        >>> import warnings 
    1615        >>> old_showwarning = warnings.showwarning 
    17         >>> captured_warnings = [] 
    1816        >>> def showwarning(message, category, filename, lineno, file=None): 
    19         ...     captured_warnings.append((message, category, filename, lineno)) 
     17        ...     warnings.last_lineno = lineno 
     18        ...     warnings.last_message = message 
    2019        >>> warnings.showwarning = showwarning 
    2120 
     
    3332        ...     ''' 
    3433 
    35     When using the schema, a deprecation warning is given for the field 
    36     definition that used the camelCase version of the name, which is now 
    37     deprecated:: 
     34    When using the schema, a deprecation warning is given for the 
     35    field definition that used the camelCase version of the name, 
     36    which is now deprecated. The line number that the warning is on 
     37    appears to be line eight above, but since a two-line header is 
     38    prepended to the body during unit testing, it's actually line 10 
     39    that the warning occurs at:: 
    3840 
    3941        >>> from schevo.test import DocTest 
    40         >>> len_before = len(captured_warnings) 
    4142        >>> t = DocTest(body) 
    42         >>> len_after = len(captured_warnings) 
    43         >>> len_after - len_before 
    44         1 
    45         >>> message, category, filename, lineno = captured_warnings[-1] 
    46         >>> print str(message)  #doctest: +ELLIPSIS 
     43        >>> print warnings.last_message  #doctest: +ELLIPSIS 
    4744        'someUnicodeThing' is a deprecated field definition name. ... 
    48  
    49     The line number that the warning is on appears to be line eight above, 
    50     but since a two-line header is prepended to the body during unit testing, 
    51     it's actually line 10 that the warning occurs at:: 
    52  
    53         >>> lineno 
     45        >>> warnings.last_lineno 
    5446        10 
    5547 
     
    5749 
    5850        >>> warnings.showwarning = old_showwarning 
    59  
    6051    """ 
    6152 
  • trunk/Zodb/setup.py

    r3509 r3561  
    5454 
    5555    install_requires=[ 
    56     'Schevo == dev, >= 3.1a1dev-r3444', 
    57     'ZODB3 == 3.7.0', 
     56    'Schevo == dev, >= 3.1a1dev-r3555', 
     57    'ZODB3 >= 3.8.0b3', 
    5858    ], 
    5959 
  • trunk/apps/Twitabit/setup.py

    r3433 r3561  
    5656    'Schevo == dev, >= 3.1a1dev-r3383', 
    5757    'SchevoPolicy == dev, >= 1.0a1dev-r3384', 
    58     'AuthKit == dev, >= 0.4.0dev-r98', 
     58    'AuthKit == dev, >= 0.4.0dev-r114', 
    5959    ], 
    6060