Line 0
Link Here
|
|
|
1 |
--- python/datamodel.py.orig 2014-07-03 07:47:07 UTC |
2 |
+++ python/datamodel.py |
3 |
@@ -26,7 +26,7 @@ import os.path |
4 |
import gettext |
5 |
import time |
6 |
import sys |
7 |
-gettext.install("zeitgeist", unicode=1) |
8 |
+gettext.install("zeitgeist") |
9 |
|
10 |
__all__ = [ |
11 |
'Interpretation', |
12 |
@@ -121,12 +121,12 @@ class Symbol(str): |
13 |
def _ensure_all_children (self): |
14 |
if self._all_children is not None : return |
15 |
self._all_children = dict() |
16 |
- for child in self._children.itervalues(): |
17 |
+ for child in self._children.values(): |
18 |
child._visit(self._all_children) |
19 |
|
20 |
def _visit (self, dikt): |
21 |
dikt[self.name] = self |
22 |
- for child in self._children.itervalues(): |
23 |
+ for child in self._children.values(): |
24 |
child._visit(dikt) |
25 |
|
26 |
@staticmethod |
27 |
@@ -141,7 +141,7 @@ class Symbol(str): |
28 |
children = list(symbol.get_all_children()) |
29 |
children.append(uri) |
30 |
return children |
31 |
- except KeyError, e: |
32 |
+ except KeyError as e: |
33 |
return [uri] |
34 |
|
35 |
|
36 |
@@ -174,7 +174,7 @@ class Symbol(str): |
37 |
""" |
38 |
Returns a list of immediate child symbols |
39 |
""" |
40 |
- return frozenset(self._children.itervalues()) |
41 |
+ return frozenset(self._children.values()) |
42 |
|
43 |
def iter_all_children(self): |
44 |
""" |
45 |
@@ -182,7 +182,7 @@ class Symbol(str): |
46 |
of this symbol |
47 |
""" |
48 |
self._ensure_all_children() |
49 |
- return self._all_children.itervalues() |
50 |
+ return self._all_children.values() |
51 |
|
52 |
def get_all_children(self): |
53 |
""" |
54 |
@@ -194,7 +194,7 @@ class Symbol(str): |
55 |
""" |
56 |
Returns a list of immediate parent symbols |
57 |
""" |
58 |
- return frozenset(self._parents.itervalues()) |
59 |
+ return frozenset(self._parents.values()) |
60 |
|
61 |
def is_child_of (self, parent): |
62 |
""" |
63 |
@@ -203,7 +203,7 @@ class Symbol(str): |
64 |
if not isinstance (parent, Symbol): |
65 |
try: |
66 |
parent = _SYMBOLS_BY_URI[parent] |
67 |
- except KeyError, e: |
68 |
+ except KeyError as e: |
69 |
# Parent is not a known URI |
70 |
return self.uri == parent |
71 |
|
72 |
@@ -226,7 +226,7 @@ class Symbol(str): |
73 |
if isinstance (child, basestring): |
74 |
try: |
75 |
child = _SYMBOLS_BY_URI[child] |
76 |
- except KeyError, e: |
77 |
+ except KeyError as e: |
78 |
# Child is not a know URI |
79 |
if isinstance (parent, basestring): |
80 |
return child == parent |
81 |
@@ -1170,7 +1170,7 @@ _SYMBOLS_BY_URI["Manifestation"] = Manifestation |
82 |
# Load the ontology definitions |
83 |
ontology_file = os.path.join(os.path.dirname(__file__), "_ontology.py") |
84 |
try: |
85 |
- execfile(ontology_file) |
86 |
+ exec(open(ontology_file).read()) |
87 |
except IOError: |
88 |
raise ImportError("Unable to load Zeitgeist ontology. Did you run `make`?") |
89 |
|
90 |
@@ -1178,23 +1178,23 @@ except IOError: |
91 |
# Bootstrap the symbol relations. We use a 2-pass strategy: |
92 |
# |
93 |
# 1) Make sure that all parents and children are registered on each symbol |
94 |
-for symbol in _SYMBOLS_BY_URI.itervalues(): |
95 |
+for symbol in _SYMBOLS_BY_URI.values(): |
96 |
for parent in symbol._parents: |
97 |
try: |
98 |
_SYMBOLS_BY_URI[parent]._children[symbol.uri] = None |
99 |
- except KeyError, e: |
100 |
- print "ERROR", e, parent, symbol.uri |
101 |
+ except KeyError as e: |
102 |
+ print ("ERROR", e, parent, symbol.uri) |
103 |
pass |
104 |
for child in symbol._children: |
105 |
try: |
106 |
_SYMBOLS_BY_URI[child]._parents.add(symbol.uri) |
107 |
except KeyError: |
108 |
- print "ERROR", e, child, symbol.uri |
109 |
+ print ("ERROR", e, child, symbol.uri) |
110 |
pass |
111 |
|
112 |
# 2) Resolve all child and parent URIs to their actual Symbol instances |
113 |
-for symbol in _SYMBOLS_BY_URI.itervalues(): |
114 |
- for child_uri in symbol._children.iterkeys(): |
115 |
+for symbol in _SYMBOLS_BY_URI.values(): |
116 |
+ for child_uri in symbol._children.keys(): |
117 |
symbol._children[child_uri] = _SYMBOLS_BY_URI[child_uri] |
118 |
|
119 |
parents = {} |
120 |
@@ -1204,8 +1204,8 @@ for symbol in _SYMBOLS_BY_URI.itervalues(): |
121 |
|
122 |
|
123 |
if __name__ == "__main__": |
124 |
- print "Success" |
125 |
+ print ("Success") |
126 |
end_symbols = time.time() |
127 |
- print >> sys.stderr, "Import time: %s" % (end_symbols - start_symbols) |
128 |
+ print ("Import time: %s" % (end_symbols - start_symbols), sys.stderr) |
129 |
|
130 |
# vim:noexpandtab:ts=4:sw=4 |