[schema] Add a new TYPE_PROPERTIES for adding new data types on the fly

In particular, this allows to adding specific properties to a type, and can be used for user-defined type, e.g. postgis Geometry.

authorVincent Michel <vincent.michel@logilab.fr>
changeset490deb287d19
branchdefault
phasedraft
hiddenyes
parent revision#b739d650ba6a add a script which compares two yams schemas (closes #112914)
child revision#1fb1755142fa [buildobj] Allow to define specific parameters in _make_type function , closes #124342
files modified by this revision
schema.py
# HG changeset patch
# User Vincent Michel <vincent.michel@logilab.fr>
# Date 1365164144 -7200
# Fri Apr 05 14:15:44 2013 +0200
# Node ID 490deb287d197641f4e018c78ff81bcd60b4bd4e
# Parent b739d650ba6aff7b6bfa49faf950b16b55e6a646
[schema] Add a new TYPE_PROPERTIES for adding new data types on the fly

In particular, this allows to adding specific properties to a type,
and can be used for user-defined type, e.g. postgis Geometry.

diff --git a/schema.py b/schema.py
@@ -952,13 +952,14 @@
1                      'permissions': None}
2      _NONFINAL_RPROPERTIES = {'composite': None}
3      _FINAL_RPROPERTIES = {'default': None,
4                            'uid': False,
5                            'indexed': False}
6 -    _STRING_RPROPERTIES = {'fulltextindexed': False,
7 -                           'internationalizable': False}
8 -    _BYTES_RPROPERTIES = {'fulltextindexed': False}
9 +    # Use a TYPE_PROPERTIES dictionnary to store type-dependant parameters.
10 +    BASE_TYPE_PROPERTIES = {'String': {'fulltextindexed': False,
11 +                                       'internationalizable': False},
12 +                            'Bytes': {'fulltextindexed': False}}
13 
14      def __init__(self, subject, rtype, object, values=None):
15          if values is not None:
16              self.update(values)
17          self.subject = subject
@@ -1006,14 +1007,11 @@
18          propdefs = cls._RPROPERTIES.copy()
19          if not desttype in BASE_TYPES:
20              propdefs.update(cls._NONFINAL_RPROPERTIES)
21          else:
22              propdefs.update(cls._FINAL_RPROPERTIES)
23 -            if desttype == 'String':
24 -                propdefs.update(cls._STRING_RPROPERTIES)
25 -            elif desttype == 'Bytes':
26 -                propdefs.update(cls._BYTES_RPROPERTIES)
27 +            propdefs.update(cls.BASE_TYPE_PROPERTIES.get(desttype, {}))
28          return propdefs
29 
30      def rproperties(self):
31          """same as .rproperty_defs class method, but for instances (hence
32          destination is known to be self.object).