fix regression introduced in 666:4d25fa7c13d9 and remove ambiguity on format_constraint on the way

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset7227371af9a9
branchdefault
phasepublic
hiddenno
parent revision#4468670c3abe [buildobjs] avoid module level dynamic object creation to avoid useless pylint errors (closes #83869)
child revision#045519650511 Take into account of inheritance relations in schema2dot (closes #88599).
files modified by this revision
buildobjs.py
constraints.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1324040573 -3600
# Fri Dec 16 14:02:53 2011 +0100
# Node ID 7227371af9a99a2126040aa8a5ee7887998a471b
# Parent 4468670c3abef23774b23b19affbb8a9b14ecc2d
fix regression introduced in 666:4d25fa7c13d9 and remove ambiguity on format_constraint on the way

diff --git a/buildobjs.py b/buildobjs.py
@@ -24,11 +24,11 @@
1  from logilab.common import attrdict
2  from logilab.common.decorators import iclassmethod
3 
4  from yams import BASE_TYPES, MARKER, BadSchemaDefinition, KNOWN_METAATTRIBUTES
5  from yams.constraints import (SizeConstraint, UniqueConstraint,
6 -                              StaticVocabularyConstraint, format_constraint)
7 +                              StaticVocabularyConstraint, FORMAT_CONSTRAINT)
8 
9  __all__ = ('EntityType', 'RelationType', 'RelationDefinition',
10             'SubjectRelation', 'ObjectRelation', 'BothWayRelation',
11             'RichString', ) + tuple(BASE_TYPES)
12 
@@ -733,17 +733,19 @@
13 
14      is equivalent to::
15 
16        class Card(EntityType):
17            content_format = String(internationalizable=True,
18 -                                  default='text/rest', constraints=[format_constraint])
19 +                                  default='text/rest', constraints=[FORMAT_CONSTRAINT])
20            content  = String(fulltextindexed=True)
21      """
22      format_args = {'default': default_format,
23                     'maxsize': 50}
24 -    if format_constraints is not None:
25 -        format_args['constraints'] = [format_constraints]
26 +    if format_constraints is None:
27 +        format_args['constraints'] = [FORMAT_CONSTRAINT]
28 +    else:
29 +        format_args['constraints'] = format_constraints
30      meta = {'format':String(internationalizable=True, **format_args)}
31      return String(metadata=meta, **kwargs)
32 
33 
34  # various derivated classes with some predefined values XXX deprecated
diff --git a/constraints.py b/constraints.py
@@ -382,11 +382,11 @@
35          return self.regular_formats
36 
37      def __str__(self):
38          return 'value in (%s)' % u', '.join(repr(unicode(word)) for word in self.vocabulary())
39 
40 -format_constraint = FormatConstraint()
41 +FORMAT_CONSTRAINT = FormatConstraint()
42 
43 
44  class MultipleStaticVocabularyConstraint(StaticVocabularyConstraint):
45      """Enforce a list of values to be in a predefined set vocabulary."""
46      # XXX never used