"""
__all__ = [ 'TypeEngine', 'TypeDecorator', 'AbstractType', 'UserDefinedType',
'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'NVARCHAR','TEXT', 'Text', 'FLOAT',
- 'NUMERIC', 'DECIMAL', 'TIMESTAMP', 'DATETIME', 'CLOB', 'NCLOB', 'BLOB',
- 'BOOLEAN', 'SMALLINT', 'INTEGER','DATE', 'TIME',
+ 'NUMERIC', 'DECIMAL', 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB',
+ 'BOOLEAN', 'SMALLINT', 'INTEGER', 'DATE', 'TIME',
'String', 'Integer', 'SmallInteger',
'Numeric', 'Float', 'DateTime', 'Date', 'Time', 'Binary',
'Boolean', 'Unicode', 'MutableType', 'Concatenable', 'UnicodeText', 'PickleType', 'Interval',
NoneType = type(None)
if util.jython:
import array
-
+
class AbstractType(Visitable):
def __init__(self, *args, **kwargs):
def compile(self, dialect):
return dialect.type_compiler.process(self)
-
+
def copy_value(self, value):
return value
@util.memoized_property
def _impl_dict(self):
return {}
-
+
def dialect_impl(self, dialect, **kwargs):
try:
return self._impl_dict[dialect.__class__]
class UserDefinedType(TypeEngine):
"""Base for user defined types.
-
+
This should be the base of new types. Note that
for most cases, :class:`TypeDecorator` is probably
more appropriate.
"""
__visit_name__ = "user_defined"
-
+
class TypeDecorator(AbstractType):
"""Allows the creation of types which add additional functionality
to an existing type.
"""
__visit_name__ = "type_decorator"
-
+
def __init__(self, *args, **kwargs):
if not hasattr(self.__class__, 'impl'):
raise AssertionError("TypeDecorator implementations require a class-level "
except KeyError:
pass
- # adapt the TypeDecorator first, in
+ # adapt the TypeDecorator first, in
# the case that the dialect maps the TD
# to one of its native types (i.e. PGInterval)
adapted = dialect.__class__.type_descriptor(self)
if adapted is not self:
self._impl_dict[dialect] = adapted
return adapted
-
+
# otherwise adapt the impl type, link
# to a copy of this TypeDecorator and return
# that.
by default calls dialect.type_descriptor(self.impl), but
can be overridden to provide different behavior.
-
+
"""
if isinstance(self.impl, TypeDecorator):
return self.impl.dialect_impl(dialect)
if typeobj is None:
return NULLTYPE
- try:
+ try:
return typeobj()
except TypeError:
return typeobj
"""
__visit_name__ = 'string'
-
+
def __init__(self, length=None, convert_unicode=False, assert_unicode=None):
"""
Create a string-holding type.
def adapt(self, impltype):
return impltype(
- length=self.length,
- convert_unicode=self.convert_unicode,
+ length=self.length,
+ convert_unicode=self.convert_unicode,
assert_unicode=self.assert_unicode)
def bind_processor(self, dialect):
assert_unicode = dialect.assert_unicode
else:
assert_unicode = self.assert_unicode
-
+
if dialect.supports_unicode_binds and assert_unicode:
def process(value):
if not isinstance(value, (unicode, NoneType)):
"""
__visit_name__ = 'unicode'
-
+
def __init__(self, length=None, **kwargs):
"""
Create a Unicode-converting String type.
class UnicodeText(Text):
"""An unbounded-length Unicode string.
-
+
See :class:`Unicode` for details on the unicode
behavior of this object.
-
+
"""
__visit_name__ = 'unicode_text'
class Integer(TypeEngine):
"""A type for ``int`` integers."""
-
+
__visit_name__ = 'integer'
-
+
def get_dbapi_type(self, dbapi):
return dbapi.NUMBER
"""
__visit_name__ = 'numeric'
-
+
def __init__(self, precision=None, scale=None, asdecimal=True):
"""
Construct a Numeric.
"""A type for ``float`` numbers."""
__visit_name__ = 'float'
-
+
def __init__(self, precision=None, asdecimal=False, **kwargs):
"""
Construct a Float.
converted back to datetime objects when rows are returned.
"""
-
+
__visit_name__ = 'datetime'
-
+
def __init__(self, timezone=False):
self.timezone = timezone
"""A type for ``datetime.date()`` objects."""
__visit_name__ = 'date'
-
+
def get_dbapi_type(self, dbapi):
return dbapi.DATETIME
:param mutable: defaults to True; implements
:meth:`AbstractType.is_mutable`. When ``True``, incoming
- objects *must* provide an ``__eq__()`` method which
- performs the desired deep comparison of members, or the
+ objects *must* provide an ``__eq__()`` method which
+ performs the desired deep comparison of members, or the
``comparator`` argument must be present. Otherwise,
comparisons are done by comparing pickle strings.
The pickle form of comparison is a deprecated usage and will
class TEXT(Text):
"""The SQL TEXT type."""
-
+
__visit_name__ = 'TEXT'
class CLOB(Text):
"""The CLOB type.
-
+
This type is found in Oracle and Informix.
"""