@classmethod
def dbapi(cls):
- import MySQLdb as mysql
- return mysql
+ return __import__('MySQLdb')
def create_connect_args(self, url):
opts = url.translate_connect_args(database='db', username='user',
client_flag = opts.get('client_flag', 0)
if self.dbapi is not None:
try:
- import MySQLdb.constants.CLIENT as CLIENT_FLAGS
+ CLIENT_FLAGS = __import__('MySQLdb.constants').constants.CLIENT
client_flag |= CLIENT_FLAGS.FOUND_ROWS
except:
pass
is otherwise internal to SQLAlchemy.
"""
-import string, re
+import re
from sqlalchemy import schema, engine, util, exc
from sqlalchemy.sql import operators, functions, util as sql_util, visitors
from sqlalchemy.sql import expression as sql
entry = self.stack and self.stack[-1] or {}
self.stack.append({'from':entry.get('from', None), 'iswrapper':True})
- text = string.join((self.process(c, asfrom=asfrom, parens=False, compound_index=i)
- for i, c in enumerate(cs.selects)),
- " " + cs.keyword + " ")
+ text = (" " + cs.keyword + " ").join((self.process(c, asfrom=asfrom, parens=False, compound_index=i)
+ for i, c in enumerate(cs.selects)))
group_by = self.process(cs._group_by_clause, asfrom=asfrom)
if group_by:
text += " GROUP BY " + group_by
return dialect.statement_compiler(dialect, self, **kw)
def __str__(self):
+ # Py3K
+ #return unicode(self.compile())
+ # Py2K
return unicode(self.compile()).encode('ascii', 'backslashreplace')
+ # end Py2K
def __and__(self, other):
return and_(self, other)
def __truediv__(self, other):
return self.operate(operators.truediv, other)
+ def __rtruediv__(self, other):
+ return self.reverse_operate(operators.truediv, other)
+
class _CompareMixin(ColumnOperators):
"""Defines comparison and math operations for ``ClauseElement`` instances."""
@property
def description(self):
+ # Py3K
+ #return self.name
+ # Py2K
return self.name.encode('ascii', 'backslashreplace')
+ # end Py2K
def is_derived_from(self, fromclause):
if fromclause in self._cloned_set:
@util.memoized_property
def description(self):
+ # Py3K
+ #return self.name
+ # Py2K
return self.name.encode('ascii', 'backslashreplace')
+ # end Py2K
@util.memoized_property
def _label(self):
@util.memoized_property
def description(self):
+ # Py3K
+ #return self.name
+ # Py2K
return self.name.encode('ascii', 'backslashreplace')
+ # end Py2K
def append_column(self, c):
self._columns[c.name] = c
_PRECEDENCE = {
from_: 15,
mul: 7,
+ truediv: 7,
# Py2K
div: 7,
# end Py2K
def clear(self):
self._data.clear()
-
class OrderedDict(dict):
"""A dict that returns keys/values/items in the order they were added."""
def __setitem__(self, key, object):
if key not in self:
- self._list.append(key)
+ try:
+ self._list.append(key)
+ except AttributeError:
+ # work around Python pickle loads() with
+ # dict subclass (seems to ignore __setstate__?)
+ self._list = [key]
dict.__setitem__(self, key, object)
def __delitem__(self, key):
for line in consume_py3k():
yield line
elif py2k_pattern.match(line):
- yield line
for line in consume_py2k():
yield line
else:
yield line
def consume_py3k():
+ yield "# start Py3K"
while lines:
line = lines.pop(0)
m = comment_pattern.match(line)
if m:
yield "%s%s" % m.group(1, 2)
else:
- m = py2k_pattern.match(line)
- if m:
- for line in consume_py2k():
- yield line
- else:
- yield line
+ # pushback
+ lines.insert(0, line)
break
+ yield "# end Py3K"
def consume_py2k():
+ yield "# start Py2K"
while lines:
line = lines.pop(0)
if not end_py2k_pattern.match(line):
yield "#%s" % line
else:
break
+ yield "# end Py2K"
return "\n".join(consume_normal())
def test_operators(self):
for (py_op, sql_op) in ((operator.add, '+'), (operator.mul, '*'),
- (operator.sub, '-'), (operator.div, '/'),
+ (operator.sub, '-'),
+ # Py3K
+ #(operator.truediv, '/'),
+ # Py2K
+ (operator.div, '/'),
+ # end Py2K
):
for (lhs, rhs, res) in (
(5, table1.c.myid, ':myid_1 %s mytable.myid'),
try:
if not verbose or quiet:
sys.stdout = DevNullWriter()
+ # Py3K
+ #else:
+ # # straight from the man:
+ # # http://mail.python.org/pipermail/python-3000/2008-February/012144.html
+ # sys.stdout._encoding = 'utf-8'
runner = unittest.TextTestRunner(verbosity = quiet and 1 or 2)
return runner.run(suite)
finally: