summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/processors.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/processors.py')
-rw-r--r--lib/sqlalchemy/processors.py56
1 files changed, 39 insertions, 17 deletions
diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py
index 860a55b8f..46d5dcbc6 100644
--- a/lib/sqlalchemy/processors.py
+++ b/lib/sqlalchemy/processors.py
@@ -32,20 +32,30 @@ def str_to_datetime_processor_factory(regexp, type_):
try:
m = rmatch(value)
except TypeError:
- raise ValueError("Couldn't parse %s string '%r' "
- "- value is not a string." %
- (type_.__name__, value))
+ raise ValueError(
+ "Couldn't parse %s string '%r' "
+ "- value is not a string." % (type_.__name__, value)
+ )
if m is None:
- raise ValueError("Couldn't parse %s string: "
- "'%s'" % (type_.__name__, value))
+ raise ValueError(
+ "Couldn't parse %s string: "
+ "'%s'" % (type_.__name__, value)
+ )
if has_named_groups:
groups = m.groupdict(0)
- return type_(**dict(list(zip(
- iter(groups.keys()),
- list(map(int, iter(groups.values())))
- ))))
+ return type_(
+ **dict(
+ list(
+ zip(
+ iter(groups.keys()),
+ list(map(int, iter(groups.values()))),
+ )
+ )
+ )
+ )
else:
return type_(*list(map(int, m.groups(0))))
+
return process
@@ -61,6 +71,7 @@ def py_fallback():
# len part is safe: it is done that way in the normal
# 'xx'.decode(encoding) code path.
return decoder(value, errors)[0]
+
return process
def to_conditional_unicode_processor_factory(encoding, errors=None):
@@ -76,6 +87,7 @@ def py_fallback():
# len part is safe: it is done that way in the normal
# 'xx'.decode(encoding) code path.
return decoder(value, errors)[0]
+
return process
def to_decimal_processor_factory(target_class, scale):
@@ -86,6 +98,7 @@ def py_fallback():
return None
else:
return target_class(fstring % value)
+
return process
def to_float(value):
@@ -107,22 +120,30 @@ def py_fallback():
return bool(value)
DATETIME_RE = re.compile(
- r"(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?")
+ r"(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?"
+ )
TIME_RE = re.compile(r"(\d+):(\d+):(\d+)(?:\.(\d+))?")
DATE_RE = re.compile(r"(\d+)-(\d+)-(\d+)")
- str_to_datetime = str_to_datetime_processor_factory(DATETIME_RE,
- datetime.datetime)
+ str_to_datetime = str_to_datetime_processor_factory(
+ DATETIME_RE, datetime.datetime
+ )
str_to_time = str_to_datetime_processor_factory(TIME_RE, datetime.time)
str_to_date = str_to_datetime_processor_factory(DATE_RE, datetime.date)
return locals()
+
try:
- from sqlalchemy.cprocessors import UnicodeResultProcessor, \
- DecimalResultProcessor, \
- to_float, to_str, int_to_boolean, \
- str_to_datetime, str_to_time, \
- str_to_date
+ from sqlalchemy.cprocessors import (
+ UnicodeResultProcessor,
+ DecimalResultProcessor,
+ to_float,
+ to_str,
+ int_to_boolean,
+ str_to_datetime,
+ str_to_time,
+ str_to_date,
+ )
def to_unicode_processor_factory(encoding, errors=None):
if errors is not None:
@@ -144,5 +165,6 @@ try:
# return Decimal('5'). These are equivalent of course.
return DecimalResultProcessor(target_class, "%%.%df" % scale).process
+
except ImportError:
globals().update(py_fallback())