merge back stable changes

authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
changeset12978e52f712
branchdefault
phasepublic
hiddenno
parent revision#5b71f36a316b fixed control, #4b2f4e5ad2a0 Stop setting/using the __hashmode__ attribute on schemas
child revision#0e27cf112c97 enhance error message
files modified by this revision
debian/changelog
schema.py
test/unittest_schema.py
# HG changeset patch
# User Alexandre Fayolle <alexandre.fayolle@logilab.fr>
# Date 1317371812 -7200
# Fri Sep 30 10:36:52 2011 +0200
# Node ID 12978e52f7126fa3655731c84bd6dc0d64a890c5
# Parent 5b71f36a316bc1bc691751480e80b4434bf2d6fc
# Parent 4b2f4e5ad2a0ad689bd9e39ca229088c8090c8e9
merge back stable changes

diff --git a/debian/changelog b/debian/changelog
@@ -24,11 +24,11 @@
1 
2  yams (0.30.2-1) unstable; urgency=low
3 
4    * new upstream release
5 
6 - -- Pierre-Yves David <pierre-yves.david@logilab.fr> Tue, 23 Nov 2010 15:27:46 +0200
7 + -- Pierre-Yves David <pierre-yves.david@logilab.fr>  Tue, 23 Nov 2010 15:27:46 +0200
8 
9  yams (0.30.1-1) unstable; urgency=low
10 
11    * new upstream release
12 
diff --git a/schema.py b/schema.py
@@ -118,22 +118,20 @@
13      def __cmp__(self, other):
14          return cmp(self.type, getattr(other, 'type', other))
15 
16      def __hash__(self):
17          try:
18 -            if self.schema.__hashmode__ is None:
19 -                return hash(self.type)
20 +            return hash(self.type)
21          except AttributeError:
22              pass
23          return hash(id(self))
24 
25      def __deepcopy__(self, memo):
26          clone = self.__class__()
27          memo[id(self)] = clone
28          clone.type = deepcopy(self.type, memo)
29          clone.schema = deepcopy(self.schema, memo)
30 -        clone.schema.__hashmode__ = None
31          clone.__dict__ = deepcopy(self.__dict__, memo)
32          return clone
33 
34      def __str__(self):
35          return self.type
@@ -731,10 +729,14 @@
36              for cstr in constraints:
37                  cstr.check_consistency(subjschema, objschema, rdef)
38          if (subjschema, objschema) in self.rdefs and self.symmetric:
39              return
40          # update our internal struct
41 +        if final:
42 +            assert not self.symmetric, 'no sense on final relation'
43 +            assert not self.inlined, 'no sense on final relation'
44 +            assert not self.fulltext_container, 'no sense on final relation'
45          self.final = final
46          rdefs = self.init_rproperties(subjschema, objschema, rdef)
47          self._add_rdef(rdefs)
48          return rdefs
49 
@@ -1049,29 +1051,22 @@
50      __implements__ = ISchema
51      entity_class = EntitySchema
52      relation_class = RelationSchema
53      # relation that should not be infered according to entity type inheritance
54      no_specialization_inference = ()
55 -    # __hashmode__ is a evil hack to support schema pickling
56 -    # it should be set to 'pickle' before pickling is done and reset to None
57 -    # once it's done
58 -    __hashmode__ = 'pickle' # None | 'pickle'
59 
60      def __init__(self, name, construction_mode='strict'):
61          super(Schema, self).__init__()
62 -        self.__hashmode__ = None
63          self.name = name
64          # with construction_mode != 'strict', no error when trying to add a
65          # relation using an undefined entity type, simply log the error
66          self.construction_mode = construction_mode
67          self._entities = {}
68          self._relations = {}
69 
70      def __setstate__(self, state):
71          self.__dict__.update(state)
72 -        # restore __hashmode__
73 -        self.__hashmode__ = None
74          self._rehash()
75 
76      def _rehash(self):
77          """rehash schema's internal structures"""
78          for eschema in self._entities.values():
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
@@ -439,16 +439,13 @@
79      def test_pickle(self):
80          """schema should be pickeable"""
81          import pickle
82          picklefile = mktemp()
83          picklestream = open(picklefile, 'w')
84 -        schema.__hashmode__ = 'pickle'
85          pickle.dump(schema, picklestream)
86          picklestream.close()
87          pschema = pickle.load(open(picklefile))
88 -        schema.__hashmode__ = None
89 -        self.assertEqual(pschema.__hashmode__, None)
90          self.assertFalse(eperson is pschema['Person'])
91          self.assertEqual(eperson, pschema['Person'])
92          self.assertEqual('Person', pschema['Person'])
93          self.assertEqual(eperson.ordered_relations(), pschema['Person'].ordered_relations())
94          self.assertEqual(eperson.object_relations(), pschema['Person'].object_relations())