diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-12-10 18:35:41 -0800 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2017-12-11 20:26:58 -0800 |
commit | 8ad2098b74ee90f341e69937a1503e29decf4594 (patch) | |
tree | ca6bb581c11fcb1a4cbe56b24aa9b83662293f3a /lib/extras.py | |
parent | f35465231f76039fae8677d48beacbdd2479095a (diff) | |
download | psycopg2-8ad2098b74ee90f341e69937a1503e29decf4594.tar.gz |
Drop 2to3 build step; make all code compatible with all Pythons
Make all library code compatible with both Python 2 and Python 3. Helps
move to modern Python idioms. Can now write for Python 3 (with
workarounds for Python 2) instead of the other way around.
In the future, when it is eventually time to drop Python 2, the library
will be in a better position to remove workarounds
Added a very small comparability module compat.py where required. It
includes definitions for:
- text_type -- A type. str on Python 3. unicode on Python 2.
- string_types -- A tuple. Contains only str on Python 3. Contains str &
unicode on Python 2.
Diffstat (limited to 'lib/extras.py')
-rw-r--r-- | lib/extras.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/extras.py b/lib/extras.py index 64467a8..1b0b2b6 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -318,14 +318,14 @@ class NamedTupleCursor(_cursor): nt = self.Record if nt is None: nt = self.Record = self._make_nt() - return map(nt._make, ts) + return list(map(nt._make, ts)) def fetchall(self): ts = super(NamedTupleCursor, self).fetchall() nt = self.Record if nt is None: nt = self.Record = self._make_nt() - return map(nt._make, ts) + return list(map(nt._make, ts)) def __iter__(self): try: @@ -566,7 +566,7 @@ class ReplicationCursor(_replicationCursor): "cannot specify output plugin options for physical replication") command += " (" - for k, v in options.iteritems(): + for k, v in options.items(): if not command.endswith('('): command += ", " command += "%s %s" % (quote_ident(k, self), _A(str(v))) @@ -762,7 +762,7 @@ class HstoreAdapter(object): adapt = _ext.adapt rv = [] - for k, v in self.wrapped.iteritems(): + for k, v in self.wrapped.items(): k = adapt(k) k.prepare(self.conn) k = k.getquoted() @@ -784,9 +784,9 @@ class HstoreAdapter(object): if not self.wrapped: return b"''::hstore" - k = _ext.adapt(self.wrapped.keys()) + k = _ext.adapt(list(self.wrapped.keys())) k.prepare(self.conn) - v = _ext.adapt(self.wrapped.values()) + v = _ext.adapt(list(self.wrapped.values())) v.prepare(self.conn) return b"hstore(" + k.getquoted() + b", " + v.getquoted() + b")" @@ -1112,7 +1112,7 @@ def _paginate(seq, page_size): it = iter(seq) while 1: try: - for i in xrange(page_size): + for i in range(page_size): page.append(next(it)) yield page page = [] |