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

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

authorVincent Michel <vincent.michel@logilab.fr>
changesetf9fa1687ea63
branchdefault
phasedraft
hiddenyes
parent revision#13cc4ee3396e [buildobj] Allow to define specific parameters in _make_type function , closes #124342
child revision<not specified>
files modified by this revision
schema.py
# HG changeset patch
# User Vincent Michel <vincent.michel@logilab.fr>
# Date 1364394167 -3600
# Wed Mar 27 15:22:47 2013 +0100
# Node ID f9fa1687ea639962fd984d786478f7e31029d3f5
# Parent 13cc4ee3396e2e644f04330cef270c97d4ac35eb
[schema] Add a new _TYPE_PROPERTIES for adding new data types on the fly

In particular, this allow to add 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
@@ -955,10 +955,18 @@
1                            'uid': False,
2                            'indexed': False}
3      _STRING_RPROPERTIES = {'fulltextindexed': False,
4                             'internationalizable': False}
5      _BYTES_RPROPERTIES = {'fulltextindexed': False}
6 +    # TYPE_PROPERTIES allow to add specific properties to a type,
7 +    # and can be used for user-defined type, e.g. postgis Geometry:
8 +    # Geometry(geom_type='POINT', srid=-1, coord_dimension=2)
9 +    # will have an entry in _TYPE_PROPERTIES
10 +    # with the following properties:
11 +    # {'geom_type': None, 'srid': None, 'coord_dimension': None}
12 +    _TYPE_PROPERTIES = {'String': _STRING_RPROPERTIES,
13 +                        'Bytes': _BYTES_RPROPERTIES}
14 
15      def __init__(self, subject, rtype, object, values=None):
16          if values is not None:
17              self.update(values)
18          self.subject = subject
@@ -1006,14 +1014,11 @@
19          propdefs = cls._RPROPERTIES.copy()
20          if not desttype in BASE_TYPES:
21              propdefs.update(cls._NONFINAL_RPROPERTIES)
22          else:
23              propdefs.update(cls._FINAL_RPROPERTIES)
24 -            if desttype == 'String':
25 -                propdefs.update(cls._STRING_RPROPERTIES)
26 -            elif desttype == 'Bytes':
27 -                propdefs.update(cls._BYTES_RPROPERTIES)
28 +            propdefs.update(cls._TYPE_PROPERTIES.get(desttype, {}))
29          return propdefs
30 
31      def rproperties(self):
32          """same as .rproperty_defs class method, but for instances (hence
33          destination is known to be self.object).