Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python3 support #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from distutils.cmd import Command
from distutils.dir_util import remove_tree
from distutils import log
import os, os.path, re, hashlib, urllib2, cStringIO, zipfile
import os, os.path, re, hashlib, urllib.request, urllib.error, urllib.parse, io, zipfile


def get_version():
Expand Down Expand Up @@ -111,7 +111,7 @@ def run(self):
if os.path.exists(target):
continue
log.info("downloading vendor package '%s'" % url)
stream = urllib2.urlopen(url)
stream = urllib.request.urlopen(url)
data = stream.read()
stream.close()
assert hashlib.md5(data).hexdigest() == md5_hash
Expand All @@ -121,7 +121,7 @@ def run(self):
remove_tree(build_dir)
os.makedirs(build_dir)
if url.endswith('.zip'):
archive = zipfile.ZipFile(cStringIO.StringIO(data))
archive = zipfile.ZipFile(io.StringIO(data))
entries = archive.infolist()
assert entries
common = entries[0].filename
Expand Down
4 changes: 2 additions & 2 deletions src/htsql/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def validate(self):
raise ValueError("database address is not specified")
try:
connect().release()
except Error, exc:
except Error as exc:
raise ValueError("failed to establish database connection: %s"
% exc)
try:
introspect()
except Error, exc:
except Error as exc:
raise ValueError("failed to introspect the database: %s" % exc)


Expand Down
8 changes: 4 additions & 4 deletions src/htsql/core/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class __metaclass__(type):

def __new__(mcls, name, bases, content):
# Iterate over all values in the class namespace.
for value in content.values():
for value in list(content.values()):
# Ignore non-function attributes.
if not isinstance(value, types.FunctionType):
continue
# Update the code name and regenerate the code object.
code = value.func_code
code = value.__code__
code_name = code.co_name
if '.' in code_name:
continue
Expand All @@ -59,7 +59,7 @@ def __new__(mcls, name, bases, content):
code.co_firstlineno, code.co_lnotab,
code.co_freevars, code.co_cellvars)
# Patch the function object.
value.func_code = code
value.__code__ = code
# Create the class.
return type.__new__(mcls, name, bases, content)

Expand Down Expand Up @@ -161,7 +161,7 @@ def __realize__(interface, dispatch_key):
# Now we need to order the implementations unambiguously.
try:
implementations = toposort(implementations, order, is_total=True)
except RuntimeError, exc:
except RuntimeError as exc:
# We intercept exceptions to provide a nicer error message.
# `message` is an explanation we discard; `conflict` is a list
# of implementations which either form a domination loop or
Expand Down
4 changes: 2 additions & 2 deletions src/htsql/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(self, db, *extensions):
value = configuration[addon_name][parameter.attribute]
try:
value = parameter.validator(value)
except ValueError, exc:
except ValueError as exc:
raise ImportError("invalid parameter %r"
" of addon %r: %s"
% (parameter.attribute,
Expand All @@ -181,7 +181,7 @@ def __init__(self, db, *extensions):
for addon in self.addons:
try:
addon.validate()
except ValueError, exc:
except ValueError as exc:
raise ImportError("failed to initialize %r: %s"
% (addon.name, exc))

Expand Down
10 changes: 5 additions & 5 deletions src/htsql/core/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __call__(self):
table = self.arc.table
yield table.name, table.schema.priority
if table.schema.name:
name = u"%s %s" % (table.schema.name, table.name)
name = "%s %s" % (table.schema.name, table.name)
yield name, -1


Expand All @@ -213,7 +213,7 @@ class CallChain(Call):

adapt(ChainArc)

path_word = u"via"
path_word = "via"

def __call__(self):
is_primary = True
Expand All @@ -238,7 +238,7 @@ def __call__(self):
origin_name = foreign_key.origin_columns[-1].name
target_name = foreign_key.target_columns[-1].name
if origin_name.endswith(target_name):
prefix = origin_name[:-len(target_name)].rstrip(u' _-')
prefix = origin_name[:-len(target_name)].rstrip(' _-')
if not prefix:
prefix = target
column = origin_name
Expand All @@ -250,10 +250,10 @@ def __call__(self):
else:
yield target, 3
if not is_direct and prefix:
name = u"%s %s %s" % (target, self.path_word, prefix)
name = "%s %s %s" % (target, self.path_word, prefix)
yield name, 2
if not is_direct and column:
name = u"%s %s %s" % (target, self.path_word, column)
name = "%s %s %s" % (target, self.path_word, column)
yield name, 1


Expand Down
2 changes: 1 addition & 1 deletion src/htsql/core/cmd/act.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __call__(self):


def act(command, action):
assert isinstance(command, (Command, Syntax, unicode, str))
assert isinstance(command, (Command, Syntax, str))
assert isinstance(action, Action)
if not isinstance(command, Command):
command = recognize(command)
Expand Down
2 changes: 1 addition & 1 deletion src/htsql/core/cmd/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Command(object):
class UniversalCmd(Command):

def __init__(self, query):
assert isinstance(query, (str, unicode))
assert isinstance(query, str)
self.query = query


Expand Down
8 changes: 4 additions & 4 deletions src/htsql/core/cmd/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __call__(self):

class EmbedUntyped(Embed):

adapt_many(str, unicode)
adapt_many(str, str)

def __call__(self):
data = self.data
Expand All @@ -45,15 +45,15 @@ def __call__(self):
except UnicodeDecodeError:
raise TypeError("a string is expected to be encoded in UTF-8:"
" %s" % repr(data))
if u"\0" in data:
if "\0" in data:
raise TypeError("a string should not contain a NIL character:"
" %s" % repr(data))
return Value(UntypedDomain(), data)


class EmbedNull(Embed):

adapt(types.NoneType)
adapt(type(None))

def __call__(self):
return Value(UntypedDomain(), None)
Expand All @@ -69,7 +69,7 @@ def __call__(self):

class EmbedInteger(Embed):

adapt_many(int, long)
adapt_many(int, int)

def __call__(self):
return Value(IntegerDomain(), self.data)
Expand Down
2 changes: 1 addition & 1 deletion src/htsql/core/cmd/summon.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __call__(self):


def recognize(syntax):
assert isinstance(syntax, (Syntax, unicode, str))
assert isinstance(syntax, (Syntax, str))
if not isinstance(syntax, Syntax):
syntax = parse(syntax)
command = Recognize.__invoke__(syntax)
Expand Down
6 changes: 3 additions & 3 deletions src/htsql/core/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def execute(self, statement, *parameters):
try:
with self.guard:
return self.cursor.execute(statement, *parameters)
except Error, exc:
except Error as exc:
exc.wrap("While executing SQL", statement)
if parameters:
parameters = parameters[0]
Expand All @@ -194,7 +194,7 @@ def executemany(self, statement, parameters_set):
try:
with self.guard:
return self.cursor.executemany(statement, parameters_set)
except Error, exc:
except Error as exc:
exc.wrap("While executing SQL", statement)
if not parameters_set:
exc.wrap("With no parameters")
Expand Down Expand Up @@ -245,7 +245,7 @@ def __iter__(self):
while True:
with self.guard:
try:
row = iterator.next()
row = next(iterator)
except StopIteration:
row = None
if row is None:
Expand Down
Loading