|
25 | 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, |
26 | 26 | USA. |
27 | 27 | """ |
28 | | - |
| 28 | +import sys |
29 | 29 | import threading |
30 | 30 | import weakref |
31 | 31 | import types |
|
41 | 41 | from . import events |
42 | 42 | from .sresults import SelectResults |
43 | 43 | from .util.threadinglocal import local |
| 44 | +from sqlobject.compat import with_metaclass |
44 | 45 |
|
45 | | -import sys |
46 | 46 | if ((sys.version_info[0] == 2) and (sys.version_info[:3] < (2, 6, 0))) or \ |
47 | 47 | ((sys.version_info[0] == 3) and (sys.version_info[:3] < (3, 4, 0))): |
48 | 48 | raise ImportError("SQLObject requires Python 2.6, 2.7 or 3.4+") |
49 | 49 |
|
50 | 50 | if sys.version_info[0] > 2: |
51 | 51 | # alias for python 3 compatability |
52 | 52 | long = int |
| 53 | + unicode = str |
53 | 54 |
|
54 | 55 | """ |
55 | 56 | This thread-local storage is needed for RowCreatedSignals. It gathers |
@@ -180,8 +181,7 @@ class CreateNewSQLObject: |
180 | 181 | pass |
181 | 182 |
|
182 | 183 |
|
183 | | -class sqlmeta(object): |
184 | | - |
| 184 | +class sqlmeta(with_metaclass(declarative.DeclarativeMeta, object)): |
185 | 185 | """ |
186 | 186 | This object is the object we use to keep track of all sorts of |
187 | 187 | information. Subclasses are made for each SQLObject subclass |
@@ -254,8 +254,6 @@ class sqlmeta(object): |
254 | 254 | # Default encoding for UnicodeCol's |
255 | 255 | dbEncoding = None |
256 | 256 |
|
257 | | - __metaclass__ = declarative.DeclarativeMeta |
258 | | - |
259 | 257 | def __classinit__(cls, new_attrs): |
260 | 258 | for attr in cls._unshared_attributes: |
261 | 259 | if attr not in new_attrs: |
@@ -757,9 +755,7 @@ def __get__(self, obj, type=None): |
757 | 755 | # MetaSQLObject. |
758 | 756 |
|
759 | 757 |
|
760 | | -class SQLObject(object): |
761 | | - |
762 | | - __metaclass__ = declarative.DeclarativeMeta |
| 758 | +class SQLObject(with_metaclass(declarative.DeclarativeMeta, object)): |
763 | 759 |
|
764 | 760 | _connection = sqlhub |
765 | 761 |
|
@@ -903,7 +899,7 @@ def _SO_setupSqlmeta(cls, new_attrs, is_base): |
903 | 899 | "(while fixing up sqlmeta %r inheritance)" |
904 | 900 | % cls.sqlmeta) |
905 | 901 | values = dict(cls.sqlmeta.__dict__) |
906 | | - for key in values.keys(): |
| 902 | + for key in list(values.keys()): |
907 | 903 | if key.startswith('__') and key.endswith('__'): |
908 | 904 | # Magic values shouldn't be passed through: |
909 | 905 | del values[key] |
@@ -1361,7 +1357,8 @@ def _SO_finishCreate(self, id=None): |
1361 | 1357 | # These are all the column values that were supposed |
1362 | 1358 | # to be set, but were delayed until now: |
1363 | 1359 | setters = self._SO_createValues.items() |
1364 | | - setters.sort(key=lambda c: self.sqlmeta.columns[c[0]].creationOrder) |
| 1360 | + setters = sorted( |
| 1361 | + setters, key=lambda c: self.sqlmeta.columns[c[0]].creationOrder) |
1365 | 1362 | # Here's their database names: |
1366 | 1363 | names = [self.sqlmeta.columns[v[0]].dbName for v in setters] |
1367 | 1364 | values = [v[1] for v in setters] |
@@ -1740,7 +1737,7 @@ def _reprItems(self): |
1740 | 1737 |
|
1741 | 1738 | @classmethod |
1742 | 1739 | def setConnection(cls, value): |
1743 | | - if isinstance(value, basestring): |
| 1740 | + if isinstance(value, (str, unicode)): |
1744 | 1741 | value = dbconnection.connectionForURI(value) |
1745 | 1742 | cls._connection = value |
1746 | 1743 |
|
|
0 commit comments