# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1372255951 -7200
# Wed Jun 26 16:12:31 2013 +0200
# Node ID d7d6c6f763c1e03cedc0f0d0de5debab9b1fc0c1
# Parent 535e71683e7cd1ec1eafdb9a435b0b6d487539c1
Remove dead and deprecated code (closes #149361)
That is, up to 0.28 (included). That's around early 2010.
The meta deprecation is set to 0.37 (meta has been deprecated for ages
but the warning was missing).
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1372255951 -7200
# Wed Jun 26 16:12:31 2013 +0200
# Node ID d7d6c6f763c1e03cedc0f0d0de5debab9b1fc0c1
# Parent 535e71683e7cd1ec1eafdb9a435b0b6d487539c1
Remove dead and deprecated code (closes #149361)
That is, up to 0.28 (included). That's around early 2010.
The meta deprecation is set to 0.37 (meta has been deprecated for ages
but the warning was missing).
@@ -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
@@ -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,19 @@
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 + warn('[yams 0.37] meta is deprecated', DeprecationWarning, stacklevel=2) 120 _check_kwargs(kwargs, RTYPE_PROPERTIES + ('description', '__permissions__')) 121 self.__dict__.update(kwargs) 122 123 def __str__(self): 124 return 'relation type %r' % self.name
@@ -503,15 +469,11 @@
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 + warn('[yams 0.37] meta is deprecated', DeprecationWarning) 136 rdefprops = _RDEF_PROPERTIES() 137 _check_kwargs(kwargs, rdefprops) 138 _copy_attributes(attrdict(**kwargs), self, rdefprops) 139 if self.constraints: 140 self.constraints = list(self.constraints)
@@ -525,15 +487,10 @@
141 142 register definition objects by adding them to the `defined` dictionnary 143 """ 144 name = getattr(cls, 'name', cls.__name__) 145 rtype = RelationType(name) 146 - if hasattr(cls, 'symetric'): 147 - cls.symmetric = cls.symetric 148 - del cls.symetric 149 - warn('[yams 0.27.0] symetric has been respelled symmetric (class %s)' % name, 150 - DeprecationWarning) 151 _copy_attributes(cls, rtype, RTYPE_PROPERTIES) 152 if name in defined: 153 _copy_attributes(rtype, defined[name], RTYPE_PROPERTIES) 154 else: 155 defined[name] = rtype
@@ -587,12 +544,10 @@
156 assert cardinality[0] in '1?+*' 157 assert cardinality[1] in '1?+*' 158 if not self.constraints: 159 self.constraints = () 160 rschema = schema.rschema(name) 161 - if self.subject == '**' or self.object == '**': 162 - warn('[yams 0.25] ** is deprecated, use * (%s)' % rtype, DeprecationWarning) 163 if self.__permissions__ is MARKER: 164 final = iter(_actual_types(schema, self.object)).next() in BASE_TYPES 165 permissions = rtype.get_permissions(final) 166 else: 167 permissions = self.__permissions__
@@ -601,11 +556,11 @@
168 rdef = RelationDefinition(subj, name, obj, __permissions__=permissions) 169 _copy_attributes(self, rdef, rdefprops) 170 schema.add_relation_def(rdef) 171 172 def _actual_types(schema, etype): 173 - if etype in ('**', '*'): # XXX ** is deprecated 174 + if etype == '*': 175 return _pow_etypes(schema) 176 if isinstance(etype, (list, tuple)): 177 return etype 178 if not isinstance(etype, basestring): 179 raise RuntimeError('Entity types must not be instances but strings '
@@ -643,16 +598,11 @@
180 self.name = '<undefined>' 181 self.etype = etype 182 if self.constraints: 183 self.constraints = list(self.constraints) 184 self.override = kwargs.pop('override', False) 185 - if 'symetric' in kwargs: 186 - kwargs['symmetric'] = kwargs.pop('symetric') 187 - warn('[yams 0.27.0] symetric has been respelled symmetric', 188 - DeprecationWarning, stacklevel=2) 189 if kwargs.pop('meta', None): 190 - # actually deprecated in 0.25 but not properly warned here 191 warn('[yams 0.37.0] meta is deprecated', 192 DeprecationWarning, stacklevel=3) 193 try: 194 _check_kwargs(kwargs, _REL_PROPERTIES()) 195 except BadSchemaDefinition, bad:
@@ -813,39 +763,5 @@
196 else: 197 format_args['constraints'] = format_constraints 198 meta = {'format':String(internationalizable=True, **format_args)} 199 return String(metadata=meta, **kwargs) 200 201 - 202 -# various derivated classes with some predefined values XXX deprecated 203 - 204 -class MetaEntityType(EntityType): 205 - __permissions__ = { 206 - 'read': ('managers', 'users', 'guests',), 207 - 'add': ('managers',), 208 - 'update': ('managers', 'owners',), 209 - 'delete': ('managers',), 210 - } 211 - 212 -class MetaUserEntityType(EntityType): 213 - pass 214 - 215 -class MetaRelationType(RelationType): 216 - __permissions__ = { 217 - 'read': ('managers', 'users', 'guests',), 218 - 'add': ('managers',), 219 - 'delete': ('managers',), 220 - } 221 - 222 -class MetaUserRelationType(RelationType): 223 - pass 224 - 225 -class MetaAttributeRelationType(RelationType): 226 - # just set permissions to None so default permissions are set 227 - __permissions__ = MARKER 228 - 229 - 230 -__all__ += ('MetaEntityType', 'MetaUserEntityType', 231 - 'MetaRelationType', 'MetaUserRelationType', 232 - 'MetaAttributeRelationType') 233 - 234 -
@@ -47,21 +47,10 @@
235 not obj is constraints.BaseConstraint): 236 CONSTRAINTS[objname] = obj 237 except TypeError: 238 continue 239 240 -class DeprecatedDict(dict): 241 - def __init__(self, context, message): 242 - dict.__init__(self, context) 243 - self.message = message 244 - 245 - def __getitem__(self, key): 246 - warn(self.message, DeprecationWarning, stacklevel=2) 247 - return super(DeprecatedDict, self).__getitem__(key) 248 - def __contains__(self, key): 249 - warn(self.message, DeprecationWarning, stacklevel=2) 250 - return super(DeprecatedDict, self).__contains__(key) 251 252 def obsolete(cls): 253 def wrapped(*args, **kwargs): 254 reason = '%s should be explictly imported from %s' % ( 255 cls.__name__, cls.__module__)
@@ -256,13 +245,10 @@
256 if key in BASE_TYPES or key == 'RichString' or key in CONSTRAINTS or \ 257 key in ('SubjectRelation', 'ObjectRelation', 'BothWayRelation'): 258 val = obsolete(val) 259 setattr(__builtin__, key, val) 260 __builtin__.import_erschema = self.import_erschema 261 - __builtin__.defined_types = DeprecatedDict(self.defined, 262 - 'defined_types is deprecated, ' 263 - 'use yams.reader.context') 264 fglobals['__file__'] = filepath 265 fglobals['__name__'] = modname 266 package = '.'.join(modname.split('.')[:-1]) 267 if package and not package in sys.modules: 268 __import__(package)
@@ -273,16 +259,10 @@
269 if isinstance(obj, type) and \ 270 issubclass(obj, buildobjs.Definition) and \ 271 obj.__module__ == modname: 272 for parent in obj.__bases__: 273 pname = parent.__name__ 274 - if pname in ('MetaEntityType', 'MetaUserEntityType', 275 - 'MetaRelationType', 'MetaUserRelationType', 276 - 'MetaAttributeRelationType'): 277 - warn('%s: %s is deprecated, use EntityType/RelationType' 278 - ' with explicit permission (%s)' % (filepath, pname, name), 279 - DeprecationWarning) 280 if pname in fglobals or not pname in self.context: 281 # imported 282 continue 283 warn('%s: please explicitly import %s (%s)' 284 % (filepath, pname, name), DeprecationWarning)
@@ -26,11 +26,10 @@
285 from itertools import chain 286 287 from logilab.common import attrdict 288 from logilab.common.decorators import cached, clear_cache 289 from logilab.common.interface import implements 290 -from logilab.common.deprecation import deprecated 291 292 import yams 293 from yams import (BASE_TYPES, MARKER, ValidationError, BadSchemaDefinition, 294 KNOWN_METAATTRIBUTES) 295 from yams.interfaces import (ISchema, IRelationSchema, IEntitySchema,
@@ -45,19 +44,12 @@
296 297 def check_permission_definitions(schema): 298 """check permissions are correctly defined""" 299 # already initialized, check everything is fine 300 for action, groups in schema.permissions.items(): 301 - # bw compat 302 - if action in ('add', 'delete') and isinstance(schema, RelationDefinitionSchema) and schema.final: 303 - warnings.warn('[yams 0.28] %s: "delete"/"add" permissions on attribute ' 304 - 'have been replaced by "update"' % schema, 305 - DeprecationWarning) 306 - schema.permissions['update'] = schema.permissions['add'] 307 - else: 308 - assert action in schema.ACTIONS, \ 309 - 'unknown action %s for %s' % (action, schema) 310 + assert action in schema.ACTIONS, \ 311 + 'unknown action %s for %s' % (action, schema) 312 assert isinstance(groups, tuple), \ 313 ('permission for action %s of %s isn\'t a tuple as ' 314 'expected' % (action, schema)) 315 for action in schema.ACTIONS: 316 assert action in schema.permissions, \
@@ -210,18 +202,12 @@
317 return '<%s %s - %s>' % (self.type, 318 [rs.type for rs in self.subject_relations()], 319 [rs.type for rs in self.object_relations()]) 320 321 def _rehash(self): 322 - try: 323 - self.subjrels = rehash(self.subjrels) 324 - self.objrels = rehash(self.objrels) 325 - except AttributeError: 326 - # yams < 0.25 pyro compat 327 - self.subjrels = rehash(self._subj_relations) 328 - self.objrels = rehash(self._obj_relations) 329 - self.final = self.is_final() 330 + self.subjrels = rehash(self.subjrels) 331 + self.objrels = rehash(self.objrels) 332 333 # schema building methods ################################################# 334 335 def add_subject_relation(self, rschema): 336 """register the relation schema as possible subject relation"""
@@ -597,93 +583,10 @@
337 if cstr is None: 338 raise AssertionError('field %s of entity %s has no vocabulary' % 339 (rtype, self)) 340 return cstr.vocabulary() 341 342 - # deprecated stuff ######################################################### 343 - rproperties = deprecated()(rdef) 344 - 345 - @deprecated('[0.26]') 346 - def rproperty(self, rtype, prop): 347 - """convenience method to access a property of a final subject relation""" 348 - rdef = self.rdef(rtype, 'subject', self.destination(rtype)) 349 - return getattr(rdef, prop) 350 - 351 - @deprecated('[0.26]') 352 - def set_rproperty(self, rtype, prop, value): 353 - """convenience method to set the value of a property of a subject relation""" 354 - rdef = self.rdef(rtype, 'subject', self.destination(rtype)) 355 - setattr(rdef, prop, value) 356 - 357 - @deprecated('[0.26] use .rdef(rtype, role).role_cardinality(role)') 358 - def cardinality(self, rtype, role): 359 - """return cardinality (a single letter in 1?*+) for the given relation""" 360 - return self.rdef(rtype, role).role_cardinality(role) 361 - 362 - @deprecated('[0.26] use .rdef(rtype).<prop>') 363 - def subjrproperty(self, rtype, prop): 364 - """convenience method to access a property of a subject relation""" 365 - return getattr(self.rdef(rtype), prop) 366 - 367 - @deprecated('[0.26] use .rdef(rtype, "object").<prop>') 368 - def objrproperty(self, rtype, prop): 369 - """convenience method to access a property of an object relation""" 370 - return getattr(self.rdef(rtype, 'object'), prop) 371 - 372 - @deprecated('[0.26] use .rdef(rtype, [role, [ttype]]).<prop>') 373 - def role_rproperty(self, role, rtype, prop, ttype=None): 374 - """convenience method to access a property of a relation according to 375 - this schema role 376 - """ 377 - return getattr(self.rdef(rtype, role, ttype), prop) 378 - 379 - @deprecated('[0.26] use rdef(rtype).constraints') 380 - def constraints(self, rtype): 381 - """return constraint of type <cstrtype> associated to the <rtype> 382 - subjet relation 383 - 384 - returns None if no constraint of type <cstrtype> is found 385 - """ 386 - return self.rdef(rtype).constraints 387 - 388 - @deprecated('[0.25] use .final attribute') 389 - def is_final(self): 390 - """return true if the entity is a final entity (and so cannot be used as 391 - subject of a relation) 392 - """ 393 - return self.type in BASE_TYPES 394 - 395 - @deprecated('[0.25] use rtype in .subjrels') 396 - def has_subject_relation(self, rtype): 397 - """if this entity type as a `rtype` subject relation, return its schema 398 - else return None 399 - """ 400 - return self.subjrels.get(rtype) 401 - 402 - @deprecated('[0.25] use .subjrels[rtype]') 403 - def subject_relation(self, rtype): 404 - """return the relation schema for the rtype subject relation 405 - 406 - Raise `KeyError` if rtype is not a subject relation of this entity type 407 - """ 408 - return self.subjrels[rtype] 409 - 410 - @deprecated('[0.25] use rtype in .objrels') 411 - def has_object_relation(self, rtype): 412 - """if this entity type as a `rtype` object relation, return its schema 413 - else return None 414 - """ 415 - return self.objrels.get(rtype) 416 - 417 - @deprecated('[0.25] use .objrels[rtype]') 418 - def object_relation(self, rtype): 419 - """return the relation schema for the rtype object relation 420 - 421 - Raise `KeyError` if rtype is not an object relation of this entity type 422 - """ 423 - return self.objrels[rtype] 424 - 425 426 427 class RelationSchema(ERSchema): 428 """A relation is a named and oriented link between two entities. 429 A relation schema defines the possible types of both extremities.
@@ -821,19 +724,10 @@
430 431 # relation definitions properties handling ################################ 432 433 # XXX move to RelationDefinitionSchema 434 435 - @deprecated('[0.26] use RelationDefinitionSchema.rproperty_defs(desttype)') 436 - def rproperty_defs(self, desttype): 437 - """return a dictionary mapping property name to its definition for each 438 - allowable properties when the relation has `desttype` as target entity's 439 - type 440 - """ 441 - desttype = self.schema.eschema(desttype) 442 - return RelationDefinitionSchema.rproperty_defs(desttype) 443 - 444 def init_rproperties(self, subject, object, buildrdef): 445 key = subject, object 446 if key in self.rdefs: 447 msg = '(%s, %s) already defined for %s' % (subject, object, self) 448 raise BadSchemaDefinition(msg)
@@ -910,41 +804,10 @@
449 def check_permission_definitions(self): 450 """check permissions are correctly defined""" 451 for rdef in self.rdefs.itervalues(): 452 rdef.check_permission_definitions() 453 454 - # deprecated stuff ######################################################### 455 - 456 - rproperties = deprecated()(rdef) 457 - 458 - @deprecated('[0.25] use .final attribute') 459 - def is_final(self): 460 - """return true if this relation has final object entity's types 461 - 462 - (we enforce that a relation can't point to both final and non final 463 - entity's type) 464 - """ 465 - return self.final 466 - 467 - @deprecated('[0.26] use self.rdefs.iterkeys()') 468 - def iter_rdefs(self): 469 - """return an iterator on (subject, object) of this relation""" 470 - return self.rdefs.iterkeys() 471 - 472 - @deprecated('[0.26] use (subj, obj) in self.rdefs') 473 - def has_rdef(self, subj, obj): 474 - return (subj, obj) in self.rdefs 475 - 476 - @deprecated('[0.26] use .rdef(subject, object).<property>') 477 - def rproperty(self, subject, object, property): 478 - """return the property for a relation definition""" 479 - return getattr(self.rdef(subject, object), property) 480 - 481 - @deprecated('[0.26] use .rdef(subject, object).<property> = value') 482 - def set_rproperty(self, subject, object, pname, value): 483 - """set value for a subject relation specific property""" 484 - setattr(self.rdefs[(subject, object)], pname, value) 485 486 487 class RelationDefinitionSchema(PermissionMixIn): 488 """a relation definition is fully caracterized relation, eg 489
@@ -999,18 +862,10 @@
490 self.subject, self.rtype, self.object) 491 492 def __repr__(self): 493 return '<%s at @%#x>' % (self, id(self)) 494 495 - def __getitem__(self, key): 496 - warnings.warn('[yams 0.27] use attribute notation', 497 - DeprecationWarning, stacklevel=2) 498 - try: 499 - return getattr(self, key) 500 - except AttributeError: 501 - raise KeyError 502 - 503 def as_triple(self): 504 return (self.subject, self.rtype, self.object) 505 506 @classmethod 507 def rproperty_defs(cls, desttype):