def class_for_table(selectable, **mapper_kwargs):
selectable = expression._clause_element_as_expr(selectable)
mapname = 'Mapped' + _selectable_name(selectable)
+ # Py2K
if isinstance(mapname, unicode):
engine_encoding = selectable.metadata.bind.dialect.encoding
mapname = mapname.encode(engine_encoding)
+ # end Py2K
if isinstance(selectable, Table):
klass = TableClassType(mapname, (object,), {})
else:
if getattr(obj, '_sa_adapter', None) is not None:
return getattr(obj, '_sa_adapter')
elif setting_type == dict:
+ # Py3K
+ #return obj.values()
+ # Py2K
return getattr(obj, 'itervalues', getattr(obj, 'values'))()
+ # end Py2K
else:
return iter(obj)
def __iter__(self):
"""Iterate over entities in the collection."""
- return getattr(self._data(), '_sa_iterator')()
+
+ # Py3K requires iter() here
+ return iter(getattr(self._data(), '_sa_iterator')())
def __len__(self):
"""Count entities in the collection."""
class InstrumentedDict(dict):
"""An instrumented version of the built-in dict."""
+ # Py3K
+ #__instrumentation__ = {
+ # 'iterator': 'values', }
+ # Py2K
__instrumentation__ = {
'iterator': 'itervalues', }
-
+ # end Py2K
+
__canned_instrumentation = {
list: InstrumentedList,
set: InstrumentedSet,
'iterator': '__iter__',
'_decorators': _set_decorators(), },
# decorators are required for dicts and object collections.
+ # Py3K
+ #dict: {'iterator': 'values',
+ # '_decorators': _dict_decorators(), },
+ # Py2K
dict: {'iterator': 'itervalues',
'_decorators': _dict_decorators(), },
+ # end Py2K
# < 0.4 compatible naming, deprecated- use decorators instead.
None: {}
}
"""return a dictionary of bind parameter keys and values"""
if params:
- params = util.column_dict(params)
pd = {}
for bindparam, name in self.bind_names.iteritems():
for paramname in (bindparam.key, bindparam.shortname, name):
class DuckTypeCollectionTest(TestBase):
- # Py3K
- #pass
-
- # Py2K
def test_sets(self):
+ # Py2K
import sets
+ # end Py2K
class SetLike(object):
def add(self):
pass
class ForcedSet(list):
__emulates__ = set
-
+
for type_ in (set,
+ # Py2K
sets.Set,
+ # end Py2K
SetLike,
ForcedSet):
eq_(util.duck_type_collection(type_), set)
eq_(util.duck_type_collection(instance), set)
for type_ in (frozenset,
- sets.ImmutableSet):
+ # Py2K
+ sets.ImmutableSet
+ # end Py2K
+ ):
is_(util.duck_type_collection(type_), None)
instance = type_()
is_(util.duck_type_collection(instance), None)
- # end Py2K
class ArgInspectionTest(TestBase):
def test_get_cls_kwargs(self):
def cryptpw(password, salt=None):
if salt is None:
- salt = string.join([chr(random.randint(ord('a'), ord('z'))),
- chr(random.randint(ord('a'), ord('z')))],'')
- return sha(password + salt).hexdigest()
+ salt = "".join([chr(random.randint(ord('a'), ord('z'))),
+ chr(random.randint(ord('a'), ord('z')))])
+ return sha((password+ salt).encode('ascii')).hexdigest()
def checkpw(password, dbpw):
return cryptpw(password, dbpw[:2]) == dbpw