本文整理匯總了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