summaryrefslogtreecommitdiff
path: root/lib/sql.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-12-10 18:35:41 -0800
committerJon Dufresne <jon.dufresne@gmail.com>2017-12-11 20:26:58 -0800
commit8ad2098b74ee90f341e69937a1503e29decf4594 (patch)
treeca6bb581c11fcb1a4cbe56b24aa9b83662293f3a /lib/sql.py
parentf35465231f76039fae8677d48beacbdd2479095a (diff)
downloadpsycopg2-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/sql.py')
-rw-r--r--lib/sql.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/sql.py b/lib/sql.py
index 849b25f..7ba9295 100644
--- a/lib/sql.py
+++ b/lib/sql.py
@@ -27,6 +27,7 @@ import sys
import string
from psycopg2 import extensions as ext
+from psycopg2.compat import string_types
_formatter = string.Formatter()
@@ -147,7 +148,7 @@ class Composed(Composable):
"foo", "bar"
"""
- if isinstance(joiner, basestring):
+ if isinstance(joiner, string_types):
joiner = SQL(joiner)
elif not isinstance(joiner, SQL):
raise TypeError(
@@ -179,7 +180,7 @@ class SQL(Composable):
select "foo", "bar" from "table"
"""
def __init__(self, string):
- if not isinstance(string, basestring):
+ if not isinstance(string, string_types):
raise TypeError("SQL values must be strings")
super(SQL, self).__init__(string)
@@ -308,7 +309,7 @@ class Identifier(Composable):
"""
def __init__(self, string):
- if not isinstance(string, basestring):
+ if not isinstance(string, string_types):
raise TypeError("SQL identifiers must be strings")
super(Identifier, self).__init__(string)
@@ -395,7 +396,7 @@ class Placeholder(Composable):
"""
def __init__(self, name=None):
- if isinstance(name, basestring):
+ if isinstance(name, string_types):
if ')' in name:
raise ValueError("invalid name: %r" % name)