summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-08-15 01:55:57 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-08-15 01:56:36 +0100
commit78649f8e905f04c3000abef23725d557a103abef (patch)
tree60afa4c1829f9a0068ae9ea34ef3374eb86fd0f8 /lib
parent3b41c3a6f373af0100a399cea150a9420ecc4acb (diff)
downloadpsycopg2-78649f8e905f04c3000abef23725d557a103abef.tar.gz
Dropped use of b() "macro" and 2to3 fixer
Just use the b"" strings syntax supported from python 2.6.
Diffstat (limited to 'lib')
-rw-r--r--lib/_range.py14
-rw-r--r--lib/extensions.py13
-rw-r--r--lib/extras.py17
3 files changed, 17 insertions, 27 deletions
diff --git a/lib/_range.py b/lib/_range.py
index b6fe0bd..4cfd387 100644
--- a/lib/_range.py
+++ b/lib/_range.py
@@ -27,7 +27,7 @@
import re
from psycopg2._psycopg import ProgrammingError, InterfaceError
-from psycopg2.extensions import ISQLQuote, adapt, register_adapter, b
+from psycopg2.extensions import ISQLQuote, adapt, register_adapter
from psycopg2.extensions import new_type, new_array_type, register_type
class Range(object):
@@ -240,7 +240,7 @@ class RangeAdapter(object):
r = self.adapted
if r.isempty:
- return b("'empty'::" + self.name)
+ return b"'empty'::" + self.name.encode('utf8')
if r.lower is not None:
a = adapt(r.lower)
@@ -248,7 +248,7 @@ class RangeAdapter(object):
a.prepare(self._conn)
lower = a.getquoted()
else:
- lower = b('NULL')
+ lower = b'NULL'
if r.upper is not None:
a = adapt(r.upper)
@@ -256,10 +256,10 @@ class RangeAdapter(object):
a.prepare(self._conn)
upper = a.getquoted()
else:
- upper = b('NULL')
+ upper = b'NULL'
- return b(self.name + '(') + lower + b(', ') + upper \
- + b(", '%s')" % r._bounds)
+ return self.name.encode('utf8') + b'(' + lower + b', ' + upper \
+ + b", '" + r._bounds.encode('utf8') + b"')"
class RangeCaster(object):
@@ -459,7 +459,7 @@ class NumberRangeAdapter(RangeAdapter):
def getquoted(self):
r = self.adapted
if r.isempty:
- return b("'empty'")
+ return b"'empty'"
if not r.lower_inf:
# not exactly: we are relying that none of these object is really
diff --git a/lib/extensions.py b/lib/extensions.py
index 2130098..309c6ee 100644
--- a/lib/extensions.py
+++ b/lib/extensions.py
@@ -103,15 +103,6 @@ TRANSACTION_STATUS_INERROR = 3
TRANSACTION_STATUS_UNKNOWN = 4
-# Return bytes from a string
-if _sys.version_info[0] < 3:
- def b(s):
- return s
-else:
- def b(s):
- return s.encode('utf8')
-
-
def register_adapter(typ, callable):
"""Register 'callable' as an ISQLQuote adapter for type 'typ'."""
adapters[(typ, ISQLQuote)] = callable
@@ -136,7 +127,7 @@ class SQL_IN(object):
if hasattr(obj, 'prepare'):
obj.prepare(self._conn)
qobjs = [o.getquoted() for o in pobjs]
- return b('(') + b(', ').join(qobjs) + b(')')
+ return b'(' + b', '.join(qobjs) + b')'
def __str__(self):
return str(self.getquoted())
@@ -151,7 +142,7 @@ class NoneAdapter(object):
def __init__(self, obj):
pass
- def getquoted(self, _null=b("NULL")):
+ def getquoted(self, _null=b"NULL"):
return _null
diff --git a/lib/extras.py b/lib/extras.py
index 6ae9851..7a3a925 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -40,7 +40,6 @@ from psycopg2 import extensions as _ext
from psycopg2.extensions import cursor as _cursor
from psycopg2.extensions import connection as _connection
from psycopg2.extensions import adapt as _A, quote_ident
-from psycopg2.extensions import b
from psycopg2._psycopg import REPLICATION_PHYSICAL, REPLICATION_LOGICAL
from psycopg2._psycopg import ReplicationConnection as _replicationConnection
from psycopg2._psycopg import ReplicationCursor as _replicationCursor
@@ -575,7 +574,7 @@ class UUID_adapter(object):
return self
def getquoted(self):
- return b("'%s'::uuid" % self._uuid)
+ return ("'%s'::uuid" % self._uuid).encode('utf8')
def __str__(self):
return "'%s'::uuid" % self._uuid
@@ -635,7 +634,7 @@ class Inet(object):
obj = _A(self.addr)
if hasattr(obj, 'prepare'):
obj.prepare(self._conn)
- return obj.getquoted() + b("::inet")
+ return obj.getquoted() + b"::inet"
def __conform__(self, proto):
if proto is _ext.ISQLQuote:
@@ -742,7 +741,7 @@ class HstoreAdapter(object):
def _getquoted_8(self):
"""Use the operators available in PG pre-9.0."""
if not self.wrapped:
- return b("''::hstore")
+ return b"''::hstore"
adapt = _ext.adapt
rv = []
@@ -756,23 +755,23 @@ class HstoreAdapter(object):
v.prepare(self.conn)
v = v.getquoted()
else:
- v = b('NULL')
+ v = b'NULL'
# XXX this b'ing is painfully inefficient!
- rv.append(b("(") + k + b(" => ") + v + b(")"))
+ rv.append(b"(" + k + b" => " + v + b")")
- return b("(") + b('||').join(rv) + b(")")
+ return b"(" + b'||'.join(rv) + b")"
def _getquoted_9(self):
"""Use the hstore(text[], text[]) function."""
if not self.wrapped:
- return b("''::hstore")
+ return b"''::hstore"
k = _ext.adapt(self.wrapped.keys())
k.prepare(self.conn)
v = _ext.adapt(self.wrapped.values())
v.prepare(self.conn)
- return b("hstore(") + k.getquoted() + b(", ") + v.getquoted() + b(")")
+ return b"hstore(" + k.getquoted() + b", " + v.getquoted() + b")"
getquoted = _getquoted_9