Remove dead and deprecated code (closes #149361)

That is, up to 0.28 (included). That's around early 2010.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeset45f486c54ad5
branchdefault
phasedraft
hiddenyes
parent revision#99d6f01f853d [schema] add a warning to avoid a potential silent bug (follows #109207)
child revision#ad6204fe11c2 "add" permission for attributes (to distinguish from "update")
files modified by this revision
__init__.py
buildobjs.py
reader.py
schema.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1372251828 -7200
# Wed Jun 26 15:03:48 2013 +0200
# Node ID 45f486c54ad58abf2e7ca15e0b602b9cb60231c5
# Parent 99d6f01f853db229223d8df2a95ba17cf9201343
Remove dead and deprecated code (closes #149361)

That is, up to 0.28 (included). That's around early 2010.

diff --git a/__init__.py b/__init__.py
@@ -52,46 +52,10 @@
1      'Time' : strptime_time
2      }
3 
4  KNOWN_METAATTRIBUTES = set(('format', 'encoding', 'name'))
5 
6 -# work in progress ###
7 -
8 -class _RelationRole(int):
9 -    def __eq__(self, other):
10 -        if isinstance(other, _RelationRole):
11 -            return other is self
12 -        if self:
13 -            return other == 'object'
14 -        return other == 'subject'
15 -    def __nonzero__(self):
16 -        if self is SUBJECT:
17 -            return OBJECT
18 -        return SUBJECT
19 -
20 -
21 -SUBJECT = _RelationRole(0)
22 -OBJECT  = _RelationRole(1)
23 -
24 -from warnings import warn
25 -
26 -def ensure_new_subjobj(val, cls=None, attr=None):
27 -    if isinstance(val, int):
28 -        return val
29 -    if val == 'subject':
30 -        msg = 'using string instead of cubicweb.SUBJECT'
31 -        if cls:
32 -            msg += ' for attribute %s of class %s' % (attr, cls.__name__)
33 -        warn(DeprecationWarning, msg)
34 -        return SUBJECT
35 -    if val == 'object':
36 -        msg = 'using string instead of cubicweb.OBJECT'
37 -        if cls:
38 -            msg += ' for attribute %s of class %s' % (attr, cls.__name__)
39 -        warn(DeprecationWarning, msg)
40 -        return SUBJECT
41 -
42  def register_base_type(name, parameters=(), check_function=None):
43      """register a yams base (final) type. You'll have to call
44      base_type_class to generate the class.
45      """
46      from yams.schema import RelationDefinitionSchema
diff --git a/buildobjs.py b/buildobjs.py
@@ -108,16 +108,11 @@
47          setattr(toobj, attr, value)
48 
49  def register_base_types(schema):
50      """add base (final) entity types to the given schema"""
51      for etype in BASE_TYPES:
52 -        edef = EntityType(
53 -            name=etype,
54 -            # unused actually
55 -            # XXX add a group in read perms to satisfy schema constraints in cw
56 -            __permissions__={'read': ('users',), 'add': (), 'delete': (),
57 -                             'update': ()})
58 +        edef = EntityType(name=etype)
59          schema.add_entity_type(edef)
60 
61  # XXX use a "frozendict"
62  DEFAULT_RELPERMS = {'read': ('managers', 'users', 'guests',),
63                      'delete': ('managers', 'users'),
@@ -182,38 +177,11 @@
64          permissions = cls.get_permissions().copy()
65          permissions[action] = actionperms
66          cls.__permissions__ = permissions
67 
68 
69 -class XXX_backward_permissions_compat(type):
70 -    stacklevel = 2
71 -    def __new__(mcs, name, bases, classdict):
72 -        if 'permissions' in classdict:
73 -            classdict['__permissions__'] = classdict.pop('permissions')
74 -            warn('[yams 0.27.0] permissions is deprecated, use __permissions__ instead (class %s)' % name,
75 -                 DeprecationWarning, stacklevel=mcs.stacklevel)
76 -        if 'symetric' in classdict:
77 -            classdict['symmetric'] = classdict.pop('symetric')
78 -            warn('[yams 0.27.0] symetric has been respelled symmetric (class %s)' % name,
79 -                 DeprecationWarning, stacklevel=mcs.stacklevel)
80 -        return super(XXX_backward_permissions_compat, mcs).__new__(mcs, name, bases, classdict)
81 -
82 -    # XXX backward compatiblity
83 -    def get_permissions(cls):
84 -        warn('[yams 0.27.0] %s.permissions is deprecated, use .__permissions__ instead'
85 -             % cls.__name__, DeprecationWarning, stacklevel=2)
86 -        return cls.__permissions__
87 -
88 -    def set_permissions(cls, newperms):
89 -        warn('[yams 0.27.0] %s.permissions is deprecated, use .__permissions__ instead'
90 -             % cls.__name__, DeprecationWarning, stacklevel=2)
91 -        cls.__permissions__ = newperms
92 -
93 -    permissions = property(get_permissions, set_permissions)
94 -
95 -
96 -class metadefinition(XXX_backward_permissions_compat):
97 +class metadefinition(type):
98      """Metaclass that builds the __relations__ attribute of
99      EntityType's subclasses.
100      """
101      stacklevel = 3
102      def __new__(mcs, name, bases, classdict):
@@ -425,21 +393,17 @@
103          assert len(relations) == 1, "can't use get_relation for relation with multiple definitions"
104          return relations[0]
105 
106 
107  class RelationType(Definition):
108 -    __metaclass__ = XXX_backward_permissions_compat
109 -
110      symmetric = MARKER
111      inlined = MARKER
112      fulltext_container = MARKER
113 
114      def __init__(self, name=None, **kwargs):
115          """kwargs must have values in RTYPE_PROPERTIES"""
116          super(RelationType, self).__init__(name)
117 -        if kwargs.pop('meta', None):
118 -            warn('[yams 0.25] meta is deprecated', DeprecationWarning, stacklevel=2)
119          _check_kwargs(kwargs, RTYPE_PROPERTIES + ('description', '__permissions__'))
120          self.__dict__.update(kwargs)
121 
122      def __str__(self):
123          return 'relation type %r' % self.name
@@ -502,16 +466,10 @@
124              self.object = self.__class__.object
125          super(RelationDefinition, self).__init__(name)
126          global CREATION_RANK
127          CREATION_RANK += 1
128          self.creation_rank = CREATION_RANK
129 -        if kwargs.pop('meta', None):
130 -            warn('[yams 0.25] meta is deprecated', DeprecationWarning)
131 -        if 'symetric' in kwargs:
132 -            warn('[yams 0.27.0] symetric has been respelled symmetric',
133 -                 DeprecationWarning, stacklevel=2)
134 -            kwargs['symmetric'] = kwargs.pop('symetric')
135          rdefprops = _RDEF_PROPERTIES()
136          _check_kwargs(kwargs, rdefprops)
137          _copy_attributes(attrdict(**kwargs), self, rdefprops)
138          if self.constraints:
139              self.constraints = list(self.constraints)
@@ -525,15 +483,10 @@
140 
141          register definition objects by adding them to the `defined` dictionnary
142          """
143          name = getattr(cls, 'name', cls.__name__)
144          rtype = RelationType(name)
145 -        if hasattr(cls, 'symetric'):
146 -            cls.symmetric = cls.symetric
147 -            del cls.symetric
148 -            warn('[yams 0.27.0] symetric has been respelled symmetric (class %s)' % name,
149 -                 DeprecationWarning)
150          _copy_attributes(cls, rtype, RTYPE_PROPERTIES)
151          if name in defined:
152              _copy_attributes(rtype, defined[name], RTYPE_PROPERTIES)
153          else:
154              defined[name] = rtype
@@ -571,12 +524,10 @@
155              assert cardinality[0] in '1?+*'
156              assert cardinality[1] in '1?+*'
157          if not self.constraints:
158              self.constraints = ()
159          rschema = schema.rschema(name)
160 -        if self.subject == '**' or self.object == '**':
161 -            warn('[yams 0.25] ** is deprecated, use * (%s)' % rtype, DeprecationWarning)
162          if self.__permissions__ is MARKER:
163              final = iter(_actual_types(schema, self.object)).next() in BASE_TYPES
164              permissions = rtype.get_permissions(final)
165          else:
166              permissions = self.__permissions__
@@ -585,11 +536,11 @@
167                  rdef = RelationDefinition(subj, name, obj, __permissions__=permissions)
168                  _copy_attributes(self, rdef, rdefprops)
169                  schema.add_relation_def(rdef)
170 
171  def _actual_types(schema, etype):
172 -    if etype in ('**', '*'): # XXX ** is deprecated
173 +    if etype == '*':
174          return _pow_etypes(schema)
175      if isinstance(etype, (list, tuple)):
176          return etype
177      if not isinstance(etype, basestring):
178          raise RuntimeError('Entity types must not be instances but strings '
@@ -627,18 +578,10 @@
179          self.name = '<undefined>'
180          self.etype = etype
181          if self.constraints:
182              self.constraints = list(self.constraints)
183          self.override = kwargs.pop('override', False)
184 -        if 'symetric' in kwargs:
185 -            kwargs['symmetric'] = kwargs.pop('symetric')
186 -            warn('[yams 0.27.0] symetric has been respelled symmetric',
187 -                 DeprecationWarning, stacklevel=2)
188 -        if kwargs.pop('meta', None):
189 -            # actually deprecated in 0.25 but not properly warned here
190 -            warn('[yams 0.37.0] meta is deprecated',
191 -                 DeprecationWarning, stacklevel=3)
192          try:
193              _check_kwargs(kwargs, _REL_PROPERTIES())
194          except BadSchemaDefinition, bad:
195              # XXX (auc) bad field name + required attribute can lead there instead of schema.py ~ 920
196              bsd_ex = BadSchemaDefinition(('%s in relation to entity %r (also is %r defined ? (check two '
@@ -797,39 +740,5 @@
197      else:
198          format_args['constraints'] = format_constraints
199      meta = {'format':String(internationalizable=True, **format_args)}
200      return String(metadata=meta, **kwargs)
201 
202 -
203 -# various derivated classes with some predefined values XXX deprecated
204 -
205 -class MetaEntityType(EntityType):
206 -    __permissions__ = {
207 -        'read':   ('managers', 'users', 'guests',),
208 -        'add':    ('managers',),
209 -        'update': ('managers', 'owners',),
210 -        'delete': ('managers',),
211 -        }
212 -
213 -class MetaUserEntityType(EntityType):
214 -    pass
215 -
216 -class MetaRelationType(RelationType):
217 -    __permissions__ = {
218 -        'read':   ('managers', 'users', 'guests',),
219 -        'add':    ('managers',),
220 -        'delete': ('managers',),
221 -        }
222 -
223 -class MetaUserRelationType(RelationType):
224 -    pass
225 -
226 -class MetaAttributeRelationType(RelationType):
227 -    # just set permissions to None so default permissions are set
228 -    __permissions__ = MARKER
229 -
230 -
231 -__all__ += ('MetaEntityType', 'MetaUserEntityType',
232 -            'MetaRelationType', 'MetaUserRelationType',
233 -            'MetaAttributeRelationType')
234 -
235 -
diff --git a/reader.py b/reader.py
@@ -47,21 +47,10 @@
236              not obj is constraints.BaseConstraint):
237              CONSTRAINTS[objname] = obj
238      except TypeError:
239          continue
240 
241 -class DeprecatedDict(dict):
242 -    def __init__(self, context, message):
243 -        dict.__init__(self, context)
244 -        self.message = message
245 -
246 -    def __getitem__(self, key):
247 -        warn(self.message, DeprecationWarning, stacklevel=2)
248 -        return super(DeprecatedDict, self).__getitem__(key)
249 -    def __contains__(self, key):
250 -        warn(self.message, DeprecationWarning, stacklevel=2)
251 -        return super(DeprecatedDict, self).__contains__(key)
252 
253  def obsolete(cls):
254      def wrapped(*args, **kwargs):
255          reason = '%s should be explictly imported from %s' % (
256              cls.__name__, cls.__module__)
@@ -254,13 +243,10 @@
257                  if key in BASE_TYPES or key == 'RichString' or key in CONSTRAINTS or \
258                         key in ('SubjectRelation', 'ObjectRelation', 'BothWayRelation'):
259                      val = obsolete(val)
260                  setattr(__builtin__, key, val)
261              __builtin__.import_erschema = self.import_erschema
262 -            __builtin__.defined_types = DeprecatedDict(self.defined,
263 -                                                        'defined_types is deprecated, '
264 -                                                        'use yams.reader.context')
265              fglobals['__file__'] = filepath
266              fglobals['__name__'] = modname
267              package = '.'.join(modname.split('.')[:-1])
268              if package and not package in sys.modules:
269                  __import__(package)
@@ -271,16 +257,10 @@
270                  if isinstance(obj, type) and \
271                         issubclass(obj, buildobjs.Definition) and \
272                         obj.__module__ == modname:
273                      for parent in obj.__bases__:
274                          pname = parent.__name__
275 -                        if pname in ('MetaEntityType', 'MetaUserEntityType',
276 -                                     'MetaRelationType', 'MetaUserRelationType',
277 -                                     'MetaAttributeRelationType'):
278 -                            warn('%s: %s is deprecated, use EntityType/RelationType'
279 -                                 ' with explicit permission (%s)' % (filepath, pname, name),
280 -                                 DeprecationWarning)
281                          if pname in fglobals or not pname in self.context:
282                              # imported
283                              continue
284                          warn('%s: please explicitly import %s (%s)'
285                               % (filepath, pname, name), DeprecationWarning)
diff --git a/schema.py b/schema.py
@@ -26,11 +26,10 @@
286  from itertools import chain
287 
288  from logilab.common import attrdict
289  from logilab.common.decorators import cached, clear_cache
290  from logilab.common.interface import implements
291 -from logilab.common.deprecation import deprecated
292 
293  import yams
294  from yams import (BASE_TYPES, MARKER, ValidationError, BadSchemaDefinition,
295                    KNOWN_METAATTRIBUTES)
296  from yams.interfaces import (ISchema, IRelationSchema, IEntitySchema,
@@ -45,19 +44,12 @@
297 
298  def check_permission_definitions(schema):
299      """check permissions are correctly defined"""
300      # already initialized, check everything is fine
301      for action, groups in schema.permissions.items():
302 -        # bw compat
303 -        if action in ('add', 'delete') and isinstance(schema, RelationDefinitionSchema) and schema.final:
304 -            warnings.warn('[yams 0.28] %s: "delete"/"add" permissions on attribute '
305 -                          'have been replaced by "update"' % schema,
306 -                          DeprecationWarning)
307 -            schema.permissions['update'] = schema.permissions['add']
308 -        else:
309 -            assert action in schema.ACTIONS, \
310 -                   'unknown action %s for %s' % (action, schema)
311 +        assert action in schema.ACTIONS, \
312 +            'unknown action %s for %s' % (action, schema)
313          assert isinstance(groups, tuple), \
314                 ('permission for action %s of %s isn\'t a tuple as '
315                  'expected' % (action, schema))
316      for action in schema.ACTIONS:
317          assert action in schema.permissions, \
@@ -210,18 +202,12 @@
318          return '<%s %s - %s>' % (self.type,
319                                   [rs.type for rs in self.subject_relations()],
320                                   [rs.type for rs in self.object_relations()])
321 
322      def _rehash(self):
323 -        try:
324 -            self.subjrels = rehash(self.subjrels)
325 -            self.objrels = rehash(self.objrels)
326 -        except AttributeError:
327 -            # yams < 0.25 pyro compat
328 -            self.subjrels = rehash(self._subj_relations)
329 -            self.objrels = rehash(self._obj_relations)
330 -            self.final = self.is_final()
331 +        self.subjrels = rehash(self.subjrels)
332 +        self.objrels = rehash(self.objrels)
333 
334      # schema building methods #################################################
335 
336      def add_subject_relation(self, rschema):
337          """register the relation schema as possible subject relation"""
@@ -597,93 +583,10 @@
338          if cstr is None:
339              raise AssertionError('field %s of entity %s has no vocabulary' %
340                                   (rtype, self))
341          return cstr.vocabulary()
342 
343 -    # deprecated stuff #########################################################
344 -    rproperties = deprecated()(rdef)
345 -
346 -    @deprecated('[0.26]')
347 -    def rproperty(self, rtype, prop):
348 -        """convenience method to access a property of a final subject relation"""
349 -        rdef = self.rdef(rtype, 'subject', self.destination(rtype))
350 -        return getattr(rdef, prop)
351 -
352 -    @deprecated('[0.26]')
353 -    def set_rproperty(self, rtype, prop, value):
354 -        """convenience method to set the value of a property of a subject relation"""
355 -        rdef = self.rdef(rtype, 'subject', self.destination(rtype))
356 -        setattr(rdef, prop, value)
357 -
358 -    @deprecated('[0.26] use .rdef(rtype, role).role_cardinality(role)')
359 -    def cardinality(self, rtype, role):
360 -        """return cardinality (a single letter in 1?*+) for the given relation"""
361 -        return self.rdef(rtype, role).role_cardinality(role)
362 -
363 -    @deprecated('[0.26] use .rdef(rtype).<prop>')
364 -    def subjrproperty(self, rtype, prop):
365 -        """convenience method to access a property of a subject relation"""
366 -        return getattr(self.rdef(rtype), prop)
367 -
368 -    @deprecated('[0.26] use .rdef(rtype, "object").<prop>')
369 -    def objrproperty(self, rtype, prop):
370 -        """convenience method to access a property of an object relation"""
371 -        return getattr(self.rdef(rtype, 'object'), prop)
372 -
373 -    @deprecated('[0.26] use .rdef(rtype, [role, [ttype]]).<prop>')
374 -    def role_rproperty(self, role, rtype, prop, ttype=None):
375 -        """convenience method to access a property of a relation according to
376 -        this schema role
377 -        """
378 -        return getattr(self.rdef(rtype, role, ttype), prop)
379 -
380 -    @deprecated('[0.26] use rdef(rtype).constraints')
381 -    def constraints(self, rtype):
382 -        """return constraint of type <cstrtype> associated to the <rtype>
383 -        subjet relation
384 -
385 -        returns None if no constraint of type <cstrtype> is found
386 -        """
387 -        return self.rdef(rtype).constraints
388 -
389 -    @deprecated('[0.25] use .final attribute')
390 -    def is_final(self):
391 -        """return true if the entity is a final entity (and so cannot be used as
392 -        subject of a relation)
393 -        """
394 -        return self.type in BASE_TYPES
395 -
396 -    @deprecated('[0.25] use rtype in .subjrels')
397 -    def has_subject_relation(self, rtype):
398 -        """if this entity type as a `rtype` subject relation, return its schema
399 -        else return None
400 -        """
401 -        return self.subjrels.get(rtype)
402 -
403 -    @deprecated('[0.25] use .subjrels[rtype]')
404 -    def subject_relation(self, rtype):
405 -        """return the relation schema for the rtype subject relation
406 -
407 -        Raise `KeyError` if rtype is not a subject relation of this entity type
408 -        """
409 -        return self.subjrels[rtype]
410 -
411 -    @deprecated('[0.25] use rtype in .objrels')
412 -    def has_object_relation(self, rtype):
413 -        """if this entity type as a `rtype` object relation, return its schema
414 -        else return None
415 -        """
416 -        return self.objrels.get(rtype)
417 -
418 -    @deprecated('[0.25] use .objrels[rtype]')
419 -    def object_relation(self, rtype):
420 -        """return the relation schema for the rtype object relation
421 -
422 -        Raise `KeyError` if rtype is not an object relation of this entity type
423 -        """
424 -        return self.objrels[rtype]
425 -
426 
427 
428  class RelationSchema(ERSchema):
429      """A relation is a named and oriented link between two entities.
430      A relation schema defines the possible types of both extremities.
@@ -821,19 +724,10 @@
431 
432      # relation definitions properties handling ################################
433 
434      # XXX move to RelationDefinitionSchema
435 
436 -    @deprecated('[0.26] use RelationDefinitionSchema.rproperty_defs(desttype)')
437 -    def rproperty_defs(self, desttype):
438 -        """return a dictionary mapping property name to its definition for each
439 -        allowable properties when the relation has `desttype` as target entity's
440 -        type
441 -        """
442 -        desttype = self.schema.eschema(desttype)
443 -        return RelationDefinitionSchema.rproperty_defs(desttype)
444 -
445      def init_rproperties(self, subject, object, buildrdef):
446          key = subject, object
447          if key in self.rdefs:
448              msg = '(%s, %s) already defined for %s' % (subject, object, self)
449              raise BadSchemaDefinition(msg)
@@ -910,41 +804,10 @@
450      def check_permission_definitions(self):
451          """check permissions are correctly defined"""
452          for rdef in self.rdefs.itervalues():
453              rdef.check_permission_definitions()
454 
455 -    # deprecated stuff #########################################################
456 -
457 -    rproperties = deprecated()(rdef)
458 -
459 -    @deprecated('[0.25] use .final attribute')
460 -    def is_final(self):
461 -        """return true if this relation has final object entity's types
462 -
463 -        (we enforce that a relation can't point to both final and non final
464 -        entity's type)
465 -        """
466 -        return self.final
467 -
468 -    @deprecated('[0.26] use self.rdefs.iterkeys()')
469 -    def iter_rdefs(self):
470 -        """return an iterator on (subject, object) of this relation"""
471 -        return self.rdefs.iterkeys()
472 -
473 -    @deprecated('[0.26] use (subj, obj) in self.rdefs')
474 -    def has_rdef(self, subj, obj):
475 -        return (subj, obj) in self.rdefs
476 -
477 -    @deprecated('[0.26] use .rdef(subject, object).<property>')
478 -    def rproperty(self, subject, object, property):
479 -        """return the property for a relation definition"""
480 -        return getattr(self.rdef(subject, object), property)
481 -
482 -    @deprecated('[0.26] use .rdef(subject, object).<property> = value')
483 -    def set_rproperty(self, subject, object, pname, value):
484 -        """set value for a subject relation specific property"""
485 -        setattr(self.rdefs[(subject, object)], pname, value)
486 
487 
488  class RelationDefinitionSchema(PermissionMixIn):
489      """a relation definition is fully caracterized relation, eg
490 
@@ -999,18 +862,10 @@
491              self.subject, self.rtype, self.object)
492 
493      def __repr__(self):
494          return '<%s at @%#x>' % (self, id(self))
495 
496 -    def __getitem__(self, key):
497 -        warnings.warn('[yams 0.27] use attribute notation',
498 -                      DeprecationWarning, stacklevel=2)
499 -        try:
500 -            return getattr(self, key)
501 -        except AttributeError:
502 -            raise KeyError
503 -
504      def as_triple(self):
505          return (self.subject, self.rtype, self.object)
506 
507      @classmethod
508      def rproperty_defs(cls, desttype):