summaryrefslogtreecommitdiff
path: root/Lib/sqlite3/dbapi2.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/sqlite3/dbapi2.py')
-rw-r--r--Lib/sqlite3/dbapi2.py68
1 files changed, 36 insertions, 32 deletions
diff --git a/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py
index e0c8a84289..665dbb276b 100644
--- a/Lib/sqlite3/dbapi2.py
+++ b/Lib/sqlite3/dbapi2.py
@@ -22,6 +22,9 @@
# 3. This notice may not be removed or altered from any source distribution.
import datetime
+import time
+
+from _sqlite3 import *
paramstyle = "qmark"
@@ -29,10 +32,6 @@ threadsafety = 1
apilevel = "2.0"
-from _sqlite3 import *
-
-import datetime, time
-
Date = datetime.date
Time = datetime.time
@@ -40,45 +39,50 @@ Time = datetime.time
Timestamp = datetime.datetime
def DateFromTicks(ticks):
- return apply(Date,time.localtime(ticks)[:3])
+ return apply(Date, time.localtime(ticks)[:3])
def TimeFromTicks(ticks):
- return apply(Time,time.localtime(ticks)[3:6])
+ return apply(Time, time.localtime(ticks)[3:6])
def TimestampFromTicks(ticks):
- return apply(Timestamp,time.localtime(ticks)[:6])
+ return apply(Timestamp, time.localtime(ticks)[:6])
-_major, _minor, _micro = version.split(".")
-version_info = (int(_major), int(_minor), _micro)
-_major, _minor, _micro = sqlite_version.split(".")
-sqlite_version_info = (int(_major), int(_minor), _micro)
+version_info = tuple([int(x) for x in version.split(".")])
+sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
Binary = buffer
-def adapt_date(val):
- return val.isoformat()
+def register_adapters_and_converters():
+ def adapt_date(val):
+ return val.isoformat()
+
+ def adapt_datetime(val):
+ return val.isoformat(" ")
+
+ def convert_date(val):
+ return datetime.date(*map(int, val.split("-")))
+
+ def convert_timestamp(val):
+ datepart, timepart = val.split(" ")
+ year, month, day = map(int, datepart.split("-"))
+ timepart_full = timepart.split(".")
+ hours, minutes, seconds = map(int, timepart_full[0].split(":"))
+ if len(timepart_full) == 2:
+ microseconds = int(float("0." + timepart_full[1]) * 1000000)
+ else:
+ microseconds = 0
-def adapt_datetime(val):
- return val.isoformat(" ")
+ val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
+ return val
-def convert_date(val):
- return datetime.date(*map(int, val.split("-")))
-def convert_timestamp(val):
- datepart, timepart = val.split(" ")
- year, month, day = map(int, datepart.split("-"))
- timepart_full = timepart.split(".")
- hours, minutes, seconds = map(int, timepart_full[0].split(":"))
- if len(timepart_full) == 2:
- microseconds = int(float("0." + timepart_full[1]) * 1000000)
- else:
- microseconds = 0
+ register_adapter(datetime.date, adapt_date)
+ register_adapter(datetime.datetime, adapt_datetime)
+ register_converter("date", convert_date)
+ register_converter("timestamp", convert_timestamp)
- val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
- return val
+register_adapters_and_converters()
+# Clean up namespace
-register_adapter(datetime.date, adapt_date)
-register_adapter(datetime.datetime, adapt_datetime)
-register_converter("date", convert_date)
-register_converter("timestamp", convert_timestamp)
+del(register_adapters_and_converters)