MCPcopy Index your code
hub / github.com/python/cpython / register_adapters_and_converters

Function register_adapters_and_converters

Lib/sqlite3/dbapi2.py:54–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52collections.abc.Sequence.register(Row)
53
54def register_adapters_and_converters():
55 from warnings import warn
56
57 msg = ("The default {what} is deprecated as of Python 3.12; "
58 "see the sqlite3 documentation for suggested replacement recipes")
59
60 def adapt_date(val):
61 warn(msg.format(what="date adapter"), DeprecationWarning, stacklevel=2)
62 return val.isoformat()
63
64 def adapt_datetime(val):
65 warn(msg.format(what="datetime adapter"), DeprecationWarning, stacklevel=2)
66 return val.isoformat(" ")
67
68 def convert_date(val):
69 warn(msg.format(what="date converter"), DeprecationWarning, stacklevel=2)
70 return datetime.date(*map(int, val.split(b"-")))
71
72 def convert_timestamp(val):
73 warn(msg.format(what="timestamp converter"), DeprecationWarning, stacklevel=2)
74 datepart, timepart = val.split(b" ")
75 year, month, day = map(int, datepart.split(b"-"))
76 timepart_full = timepart.split(b".")
77 hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
78 if len(timepart_full) == 2:
79 microseconds = int('{:0<6.6}'.format(timepart_full[1].decode()))
80 else:
81 microseconds = 0
82
83 val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
84 return val
85
86
87 register_adapter(datetime.date, adapt_date)
88 register_adapter(datetime.datetime, adapt_datetime)
89 register_converter("date", convert_date)
90 register_converter("timestamp", convert_timestamp)
91
92register_adapters_and_converters()
93

Callers 1

dbapi2.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…