aboutsummaryrefslogtreecommitdiff
path: root/databases/py-Elixir/files/patch-2to3
blob: ab5974dac8a36de2f8a81f3016428e81a5652376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
--- elixir/entity.py.orig	2009-11-13 19:50:38 UTC
+++ elixir/entity.py
@@ -3,7 +3,7 @@ This module provides the ``Entity`` base class, as wel
 ``EntityMeta``.
 '''
 
-from py23compat import sorted
+from .py23compat import sorted
 
 import sys
 import types
@@ -172,7 +172,7 @@ class EntityDescriptor(object):
             self.identity = self.identity(entity)
 
         if self.polymorphic:
-            if not isinstance(self.polymorphic, basestring):
+            if not isinstance(self.polymorphic, str):
                 self.polymorphic = options.DEFAULT_POLYMORPHIC_COL_NAME
 
     #---------------------
@@ -226,7 +226,7 @@ class EntityDescriptor(object):
                         if col.primary_key:
                             self.add_column(col.copy())
             elif not self.has_pk and self.auto_primarykey:
-                if isinstance(self.auto_primarykey, basestring):
+                if isinstance(self.auto_primarykey, str):
                     colname = self.auto_primarykey
                 else:
                     colname = options.DEFAULT_AUTO_PRIMARYKEY_NAME
@@ -298,7 +298,7 @@ class EntityDescriptor(object):
                                        options.POLYMORPHIC_COL_TYPE))
 
             if self.version_id_col:
-                if not isinstance(self.version_id_col, basestring):
+                if not isinstance(self.version_id_col, str):
                     self.version_id_col = options.DEFAULT_VERSION_ID_COL_NAME
                 self.add_column(Column(self.version_id_col, Integer))
 
@@ -306,7 +306,7 @@ class EntityDescriptor(object):
         self.entity.table = Table(self.tablename, self.metadata,
                                   *args, **kwargs)
         if DEBUG:
-            print self.entity.table.repr2()
+            print(self.entity.table.repr2())
 
     def setup_reltables(self):
         self.call_builders('create_tables')
@@ -365,7 +365,7 @@ class EntityDescriptor(object):
         return children
 
     def translate_order_by(self, order_by):
-        if isinstance(order_by, basestring):
+        if isinstance(order_by, str):
             order_by = [order_by]
 
         order = []
@@ -505,12 +505,12 @@ class EntityDescriptor(object):
         # get one in any case.
         table = type.__getattribute__(self.entity, 'table')
         if table is not None:
-            if check_duplicate and col.key in table.columns.keys():
+            if check_duplicate and col.key in list(table.columns.keys()):
                 raise Exception("Column '%s' already exist in table '%s' ! " %
                                 (col.key, table.name))
             table.append_column(col)
             if DEBUG:
-                print "table.append_column(%s)" % col
+                print("table.append_column(%s)" % col)
 
     def add_constraint(self, constraint):
         self.constraints.append(constraint)
@@ -537,7 +537,7 @@ class EntityDescriptor(object):
         if mapper:
             mapper.add_property(name, property)
             if DEBUG:
-                print "mapper.add_property('%s', %s)" % (name, repr(property))
+                print("mapper.add_property('%s', %s)" % (name, repr(property)))
 
     def add_mapper_extension(self, extension):
         extensions = self.mapper_options.get('extension', [])
@@ -795,7 +795,7 @@ def instrument_class(cls):
 
     # Process attributes (using the assignment syntax), looking for
     # 'Property' instances and attaching them to this entity.
-    properties = [(name, attr) for name, attr in cls.__dict__.iteritems()
+    properties = [(name, attr) for name, attr in cls.__dict__.items()
                                if isinstance(attr, Property)]
     sorted_props = sorted(base_props + properties,
                           key=lambda i: i[1]._counter)
@@ -924,7 +924,7 @@ def setup_entities(entities):
         # delete all Elixir properties so that it doesn't interfere with
         # SQLAlchemy. At this point they should have be converted to
         # builders.
-        for name, attr in entity.__dict__.items():
+        for name, attr in list(entity.__dict__.items()):
             if isinstance(attr, Property):
                 delattr(entity, name)
 
@@ -1004,7 +1004,7 @@ class EntityBase(object):
         self.set(**kwargs)
 
     def set(self, **kwargs):
-        for key, value in kwargs.iteritems():
+        for key, value in kwargs.items():
             setattr(self, key, value)
 
     def update_or_create(cls, data, surrogate=True):
@@ -1038,7 +1038,7 @@ class EntityBase(object):
 
         mapper = sqlalchemy.orm.object_mapper(self)
 
-        for key, value in data.iteritems():
+        for key, value in data.items():
             if isinstance(value, dict):
                 dbvalue = getattr(self, key)
                 rel_class = mapper.get_property(key).mapper.class_
@@ -1074,7 +1074,7 @@ class EntityBase(object):
                                       if isinstance(p, ColumnProperty)]
         data = dict([(name, getattr(self, name))
                      for name in col_prop_names if name not in exclude])
-        for rname, rdeep in deep.iteritems():
+        for rname, rdeep in deep.items():
             dbdata = getattr(self, rname)
             #FIXME: use attribute names (ie coltoprop) instead of column names
             fks = self.mapper.get_property(rname).remote_side
@@ -1145,7 +1145,7 @@ class EntityBase(object):
     get = classmethod(get)
 
 
-class Entity(EntityBase):
+class Entity(EntityBase, metaclass=EntityMeta):
     '''
     The base class for all entities
 
@@ -1167,6 +1167,5 @@ class Entity(EntityBase):
     For further information, please refer to the provided examples or
     tutorial.
     '''
-    __metaclass__ = EntityMeta
 
 
--- elixir/py23compat.py.orig	2009-10-02 10:19:50 UTC
+++ elixir/py23compat.py
@@ -11,7 +11,7 @@ orig_cmp = cmp
 def sort_list(l, cmp=None, key=None, reverse=False):
     try:
         l.sort(cmp, key, reverse)
-    except TypeError, e:
+    except TypeError as e:
         if not str(e).startswith('sort expected at most 1 arguments'):
             raise
         if cmp is None:
--- elixir/relationships.py.orig	2009-11-13 20:04:26 UTC
+++ elixir/relationships.py
@@ -412,7 +412,7 @@ from sqlalchemy import ForeignKeyConstraint, Column, T
 from sqlalchemy.orm import relation, backref, class_mapper
 from sqlalchemy.ext.associationproxy import association_proxy
 
-import options
+from . import options
 from elixir.statements import ClassMutator
 from elixir.properties import Property
 from elixir.entity import EntityMeta, DEBUG
@@ -495,7 +495,7 @@ class Relationship(Property):
 
     def target(self):
         if not self._target:
-            if isinstance(self.of_kind, basestring):
+            if isinstance(self.of_kind, str):
                 collection = self.entity._descriptor.collection
                 self._target = collection.resolve(self.of_kind, self.entity)
             else:
@@ -1115,7 +1115,7 @@ class ManyToMany(Relationship):
             self.table = Table(tablename, e1_desc.metadata,
                                schema=schema, *args, **complete_kwargs)
             if DEBUG:
-                print self.table.repr2()
+                print(self.table.repr2())
 
     def _build_join_clauses(self):
         # In the case we have a self-reference, we need to build join clauses
@@ -1222,7 +1222,7 @@ def _get_join_clauses(local_table, local_cols1, local_
     # match.
 
 #TODO: rewrite this. Even with the comment, I don't even understand it myself.
-    for cols, constraint in constraint_map.iteritems():
+    for cols, constraint in constraint_map.items():
         if cols == cols1 or (cols != cols2 and
                              not cols1 and (cols2 in constraint_map or
                                             cols2 is None)):