本文整理汇总了Python中sqlite3.PrepareProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python sqlite3.PrepareProtocol方法的具体用法?Python sqlite3.PrepareProtocol怎么用?Python sqlite3.PrepareProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlite3
的用法示例。
在下文中一共展示了sqlite3.PrepareProtocol方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __conform__
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PrepareProtocol [as 别名]
def __conform__(self, protocol):
if protocol is sqlite.PrepareProtocol:
return self.val
else:
return None
示例2: tearDown
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PrepareProtocol [as 别名]
def tearDown(self):
del sqlite.adapters[(int, sqlite.PrepareProtocol)]
self.cur.close()
self.con.close()
示例3: register_adapter
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PrepareProtocol [as 别名]
def register_adapter(type_, function):
adapters[(type_, sqlite3.PrepareProtocol)] = function
示例4: _adapt_from_python
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PrepareProtocol [as 别名]
def _adapt_from_python(value):
if not isinstance(value, basestring):
adapter_key = (type(value), sqlite3.PrepareProtocol)
adapter = adapters.get(adapter_key)
try:
if adapter is None:
# Fall back to _default_adapters, so that ObjectAdaptationTests
# teardown will correctly restore the default state.
adapter = _default_adapters[adapter_key]
except KeyError as e:
# No adapter registered. Let the object adapt itself via PEP-246.
# It has been rejected by the BDFL, but is still implemented
# on stdlib sqlite3 module even on Python 3 !!
if hasattr(value, '__adapt__'):
adapted = value.__adapt__(sqlite3.PrepareProtocol)
elif hasattr(value, '__conform__'):
adapted = value.__conform__(sqlite3.PrepareProtocol)
else:
raise InterfaceError(e)
else:
adapted = adapter(value)
else:
adapted = value
# The adapter could had returned a string
if isinstance(adapted, (bytes, unicode)):
adapted = _escape_string(adapted)
elif adapted is None:
adapted = 'NULL'
else:
adapted = str(adapted)
return adapted