[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. Prepares #124342

authorVincent Michel <vincent.michel@logilab.fr>
changeset99ef582141c7
branchdefault
phasepublic
hiddenno
parent revision#b739d650ba6a add a script which compares two yams schemas (closes #112914)
child revision#94a420079825 [buildobj] Allow to define specific parameters in _make_type function , prepares #124342
files modified by this revision
schema.py
# HG changeset patch
# User Vincent Michel <vincent.michel@logilab.fr>
# Date 1366117006 -7200
# Tue Apr 16 14:56:46 2013 +0200
# Node ID 99ef582141c7e3facee0a4956f5faf6fbc6e1b95
# 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.
Prepares #124342

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).