Deal with python3's dict method changes

Related to #267910.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset6b39467e7e5d
branchdefault
phasepublic
hiddenno
parent revision#0b75574d2314 [buildobjs] deal with py3k's dict method changes
child revision#3cab8d5497df [pkg] add dependency on six
files modified by this revision
diff.py
reader.py
schema.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1413464851 -7200
# Thu Oct 16 15:07:31 2014 +0200
# Node ID 6b39467e7e5d0ced4b5251805b339cdf1add3898
# Parent 0b75574d231442d5bba2a34a58addaa27bf30fde
Deal with python3's dict method changes

Related to #267910.

diff --git a/diff.py b/diff.py
@@ -55,11 +55,11 @@
1  def identity(x):
2      return x
3 
4  def format_props(props, scope, ignore=()):
5      out = []
6 -    for prop, val in sorted(props.iteritems()):
7 +    for prop, val in sorted(props.items()):
8          if prop in ignore:
9              continue
10          out.append('\t' * scope.indentation +
11                     '%s%s=%s%s' % (prop, scope.spacer, scope.spacer, val))
12      return ('%s\n' % scope.nextline).join(out)
diff --git a/reader.py b/reader.py
@@ -62,11 +62,11 @@
13  def fill_schema(schema, erdefs, register_base_types=True,
14                  remove_unused_rtypes=False, post_build_callbacks=[]):
15      if register_base_types:
16          buildobjs.register_base_types(schema)
17      # relation definitions may appear multiple times
18 -    erdefs_vals = set(erdefs.itervalues())
19 +    erdefs_vals = set(erdefs.values())
20      # register relation types and non final entity types
21      for definition in erdefs_vals:
22          if isinstance(definition, type):
23              definition = definition()
24          if isinstance(definition, buildobjs.RelationType):
diff --git a/schema.py b/schema.py
@@ -268,17 +268,17 @@
25 
26      def subject_relations(self):
27          """return a list of relations that may have this type of entity as
28          subject
29          """
30 -        return self.subjrels.values()
31 +        return list(self.subjrels.values())
32 
33      def object_relations(self):
34          """return a list of relations that may have this type of entity as
35          object
36          """
37 -        return self.objrels.values()
38 +        return list(self.objrels.values())
39 
40      def rdef(self, rtype, role='subject', targettype=None, takefirst=False):
41          """return a relation definition schema for a relation of this entity type
42 
43          Notice that when targettype is not specified and the relation may lead
@@ -747,11 +747,11 @@
44          if key in self.rdefs and not self.rdefs[key].infered:
45              msg = '(%s, %s) already defined for %s' % (subject, object, self)
46              raise BadSchemaDefinition(msg)
47          self.rdefs[key] = rdef = RelationDefinitionSchema(subject, self, object,
48                                                            buildrdef.package)
49 -        for prop, default in rdef.rproperties().iteritems():
50 +        for prop, default in rdef.rproperties().items():
51              rdefval = getattr(buildrdef, prop, MARKER)
52              if rdefval is MARKER:
53                  if prop == 'permissions':
54                      rdefval = default = buildrdef.get_permissions(self.final).copy()
55                  if prop == 'cardinality':
@@ -766,11 +766,11 @@
56      def associations(self):
57          """return a list of (subject, [objects]) defining between which types
58          this relation may exists
59          """
60          # XXX deprecates in favor of iter_rdefs() ?
61 -        return self._subj_schemas.items()
62 +        return list(self._subj_schemas.items())
63 
64      def subjects(self, etype=None):
65          """Return a list of entity schemas which can be subject of this relation.
66 
67          If etype is not None, return a list of schemas which can be subject of
@@ -818,11 +818,11 @@
68              return self.rdefs[(etype, ttype)]
69          return self.rdefs[(ttype, etype)]
70 
71      def check_permission_definitions(self):
72          """check permissions are correctly defined"""
73 -        for rdef in self.rdefs.itervalues():
74 +        for rdef in self.rdefs.values():
75              rdef.check_permission_definitions()
76          if self.rule and (self.permissions.get('add')
77                            or self.permissions.get('delete')):
78              raise BadSchemaDefinition(
79                  'Cannot set add/delete permissions on computed relation %s'
@@ -855,11 +855,11 @@
80      @classmethod
81      def ALL_PROPERTIES(cls):
82          return set(chain(cls._RPROPERTIES,
83                           cls._NONFINAL_RPROPERTIES,
84                           cls._FINAL_RPROPERTIES,
85 -                         *cls.BASE_TYPE_PROPERTIES.itervalues()))
86 +                         *cls.BASE_TYPE_PROPERTIES.values()))
87 
88      def __init__(self, subject, rtype, object, package, values=None):
89          if values is not None:
90              self.update(values)
91          self.subject = subject
@@ -1111,14 +1111,14 @@
92          if not self.rschema(rtype).rdefs:
93              del self._relations[rtype]
94 
95      def del_entity_type(self, etype):
96          eschema = self._entities[etype]
97 -        for rschema in eschema.subjrels.values():
98 +        for rschema in list(eschema.subjrels.values()):
99              for objtype in rschema.objects(etype):
100                  self.del_relation_def(eschema, rschema, objtype)
101 -        for rschema in eschema.objrels.values():
102 +        for rschema in list(eschema.objrels.values()):
103              for subjtype in rschema.subjects(etype):
104                  self.del_relation_def(subjtype, rschema, eschema)
105          if eschema.specializes():
106              eschema.specializes()._specialized_by.remove(eschema)
107          if eschema.specialized_by():
@@ -1128,11 +1128,11 @@
108 
109      def infer_specialization_rules(self):
110          for rschema in self.relations():
111              if rschema in self.no_specialization_inference:
112                  continue
113 -            for (subject, object), rdef in rschema.rdefs.items():
114 +            for (subject, object), rdef in list(rschema.rdefs.items()):
115                  subjeschemas = [subject] + subject.specialized_by(recursive=True)
116                  objeschemas = [object] + object.specialized_by(recursive=True)
117                  for subjschema in subjeschemas:
118                      for objschema in objeschemas:
119                          # don't try to add an already defined relation
@@ -1147,11 +1147,11 @@
120          `infer_specialization_rules`
121          """
122          for rschema in self.relations():
123              if rschema.final:
124                  continue
125 -            for (subject, object), rdef in rschema.rdefs.items():
126 +            for (subject, object), rdef in list(rschema.rdefs.items()):
127                  if rdef.infered:
128                      rschema.del_relation_def(subject, object)
129 
130      def rebuild_infered_relations(self):
131          """remove any infered definitions and rebuild them"""
@@ -1164,11 +1164,11 @@
132          """return a list of possible entity's type
133 
134          :rtype: list
135          :return: defined entity's types (str) or schemas (`EntitySchema`)
136          """
137 -        return self._entities.values()
138 +        return list(self._entities.values())
139 
140      def has_entity(self, etype):
141          """return true the type is defined in the schema
142 
143          :type etype: str
@@ -1197,11 +1197,11 @@
144          """return the list of possible relation'types
145 
146          :rtype: list
147          :return: defined relation's types (str) or schemas (`RelationSchema`)
148          """
149 -        return self._relations.values()
150 +        return list(self._relations.values())
151 
152      def has_relation(self, rtype):
153          """return true the relation is defined in the schema
154 
155          :type rtype: str