mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-08-04 12:20:09 +03:00
Python3.4, fix lib python3 issues
This commit is contained in:
parent
a0d4c3f365
commit
ee04e4bc54
|
@ -59,7 +59,7 @@ from psycopg2._psycopg import NotSupportedError, OperationalError
|
||||||
from psycopg2._psycopg import _connect, apilevel, threadsafety, paramstyle
|
from psycopg2._psycopg import _connect, apilevel, threadsafety, paramstyle
|
||||||
from psycopg2._psycopg import __version__
|
from psycopg2._psycopg import __version__
|
||||||
|
|
||||||
from psycopg2 import tz
|
from psycopg2 import tz, _py3
|
||||||
|
|
||||||
|
|
||||||
# Register default adapters.
|
# Register default adapters.
|
||||||
|
@ -147,7 +147,7 @@ def connect(dsn=None,
|
||||||
if port is not None:
|
if port is not None:
|
||||||
items.append(('port', port))
|
items.append(('port', port))
|
||||||
|
|
||||||
items.extend([(k, v) for (k, v) in kwargs.iteritems() if v is not None])
|
items.extend([(k, v) for (k, v) in _py3.iteritems(kwargs) if v is not None])
|
||||||
|
|
||||||
if dsn is not None and items:
|
if dsn is not None and items:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
|
|
19
lib/_py3.py
Normal file
19
lib/_py3.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
PY3 = sys.version_info[0] == 3
|
||||||
|
|
||||||
|
|
||||||
|
if PY3:
|
||||||
|
import _thread
|
||||||
|
|
||||||
|
def iteritems(d, **kw):
|
||||||
|
return iter(d.items(**kw))
|
||||||
|
|
||||||
|
thread = _thread
|
||||||
|
else:
|
||||||
|
import thread as _thread
|
||||||
|
|
||||||
|
def iteritems(d, **kw):
|
||||||
|
return iter(d.iteritems(**kw))
|
||||||
|
|
||||||
|
thread = _thread
|
|
@ -29,6 +29,9 @@ This module contains symbolic names for all PostgreSQL error codes.
|
||||||
# http://www.postgresql.org/docs/current/static/errcodes-appendix.html
|
# http://www.postgresql.org/docs/current/static/errcodes-appendix.html
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from psycopg2 import _py3
|
||||||
|
|
||||||
|
|
||||||
def lookup(code, _cache={}):
|
def lookup(code, _cache={}):
|
||||||
"""Lookup an error code or class code and return its symbolic name.
|
"""Lookup an error code or class code and return its symbolic name.
|
||||||
|
|
||||||
|
@ -38,7 +41,7 @@ def lookup(code, _cache={}):
|
||||||
return _cache[code]
|
return _cache[code]
|
||||||
|
|
||||||
# Generate the lookup map at first usage.
|
# Generate the lookup map at first usage.
|
||||||
for k, v in globals().iteritems():
|
for k, v in _py3.iteritems(globals()):
|
||||||
if isinstance(v, str) and len(v) in (2, 5):
|
if isinstance(v, str) and len(v) in (2, 5):
|
||||||
_cache[v] = k
|
_cache[v] = k
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ and classes until a better place in the distribution is found.
|
||||||
# License for more details.
|
# License for more details.
|
||||||
|
|
||||||
import os as _os
|
import os as _os
|
||||||
import sys as _sys
|
|
||||||
import time as _time
|
import time as _time
|
||||||
import re as _re
|
import re as _re
|
||||||
|
|
||||||
|
@ -37,6 +36,7 @@ except:
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import extensions as _ext
|
from psycopg2 import extensions as _ext
|
||||||
|
from psycopg2 import _py3
|
||||||
from psycopg2.extensions import cursor as _cursor
|
from psycopg2.extensions import cursor as _cursor
|
||||||
from psycopg2.extensions import connection as _connection
|
from psycopg2.extensions import connection as _connection
|
||||||
from psycopg2.extensions import adapt as _A
|
from psycopg2.extensions import adapt as _A
|
||||||
|
@ -191,7 +191,7 @@ class DictRow(list):
|
||||||
self._index = data[1]
|
self._index = data[1]
|
||||||
|
|
||||||
# drop the crusty Py2 methods
|
# drop the crusty Py2 methods
|
||||||
if _sys.version_info[0] > 2:
|
if _py3.PY3:
|
||||||
items = iteritems; del iteritems
|
items = iteritems; del iteritems
|
||||||
keys = iterkeys; del iterkeys
|
keys = iterkeys; del iterkeys
|
||||||
values = itervalues; del itervalues
|
values = itervalues; del itervalues
|
||||||
|
@ -788,7 +788,7 @@ def register_hstore(conn_or_curs, globally=False, unicode=False,
|
||||||
array_oid = tuple([x for x in array_oid if x])
|
array_oid = tuple([x for x in array_oid if x])
|
||||||
|
|
||||||
# create and register the typecaster
|
# create and register the typecaster
|
||||||
if _sys.version_info[0] < 3 and unicode:
|
if not _py3.PY3 and unicode:
|
||||||
cast = HstoreAdapter.parse_unicode
|
cast = HstoreAdapter.parse_unicode
|
||||||
else:
|
else:
|
||||||
cast = HstoreAdapter.parse
|
cast = HstoreAdapter.parse
|
||||||
|
|
|
@ -26,6 +26,7 @@ This module implements thread-safe (and not) connection pools.
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions as _ext
|
import psycopg2.extensions as _ext
|
||||||
|
from psycopg2 import _py3
|
||||||
|
|
||||||
|
|
||||||
class PoolError(psycopg2.Error):
|
class PoolError(psycopg2.Error):
|
||||||
|
@ -204,8 +205,7 @@ class PersistentConnectionPool(AbstractConnectionPool):
|
||||||
|
|
||||||
# we we'll need the thread module, to determine thread ids, so we
|
# we we'll need the thread module, to determine thread ids, so we
|
||||||
# import it here and copy it in an instance variable
|
# import it here and copy it in an instance variable
|
||||||
import thread
|
self.__thread = _py3.thread
|
||||||
self.__thread = thread
|
|
||||||
|
|
||||||
def getconn(self):
|
def getconn(self):
|
||||||
"""Generate thread id and return a connection."""
|
"""Generate thread id and return a connection."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user