本文整理匯總了Python中sqlite3.html方法的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.html方法的具體用法?Python sqlite3.html怎麽用?Python sqlite3.html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3
的用法示例。
在下文中一共展示了sqlite3.html方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _instrument
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def _instrument(self, **kwargs):
"""Integrate with SQLite3 Python library.
https://docs.python.org/3/library/sqlite3.html
"""
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, __version__, tracer_provider)
dbapi.wrap_connect(
tracer,
sqlite3,
"connect",
self._DATABASE_COMPONENT,
self._DATABASE_TYPE,
self._CONNECTION_ATTRIBUTES,
)
示例2: adapt_datetime
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def adapt_datetime(ts):
# http://docs.python.org/2/library/sqlite3.html#registering-an-adapter-callable
return time.mktime(ts.timetuple())
示例3: adapt_datetime
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def adapt_datetime(ts):
# http://docs.python.org/2/library/sqlite3.html#registering-an-adapter-callable
return time.mktime(ts.timetuple())
示例4: get_url
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def get_url(self,url):
#headers = {'user-agent': 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+'}
headers = {'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'}
try:
r = requests.get(url,headers=headers)
html = HTMLParser.HTMLParser().unescape(r.content.decode('utf-8'))
return html
except:
return ''
示例5: generate_insert_sqlstr_multivalue_tuple
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def generate_insert_sqlstr_multivalue_tuple(table_name, column_name_list, column_value_lists):
# Formulate the sql string and value tuple for batch sql insert queries
# The key point is to use executemany function
# https://docs.python.org/2/library/sqlite3.html
sqlstr = 'INSERT INTO %s( %s ) VALUES ( %s )' % (table_name, ','.join(column_name_list),
','.join(['?'] * len(column_name_list)))
return (sqlstr, column_value_lists)
示例6: GetValues
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def GetValues(self, table_names, column_names, condition):
"""Retrieves values from a table.
Args:
table_names (list[str]): table names.
column_names (list[str]): column names.
condition (str): query condition such as
"log_source == 'Application Error'".
Yields:
sqlite3.row: row.
Raises:
RuntimeError: if the database is not opened.
"""
if not self._connection:
raise RuntimeError('Cannot retrieve values database not opened.')
if condition:
condition = ' WHERE {0:s}'.format(condition)
sql_query = 'SELECT {1:s} FROM {0:s}{2:s}'.format(
', '.join(table_names), ', '.join(column_names), condition)
self._cursor.execute(sql_query)
# TODO: have a look at https://docs.python.org/2/library/
# sqlite3.html#sqlite3.Row.
for row in self._cursor:
yield {
column_name: row[column_index]
for column_index, column_name in enumerate(column_names)}
示例7: __init__
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def __init__(self, *args, **kwargs):
# by default [py]sqlite3 checks that object methods are run in the same
# thread as the one that created the Connection or Cursor. If it finds
# they are not then an exception is raised.
# <https://docs.python.org/2/library/sqlite3.html#multithreading>
# Luckily for us we can switch this check off.
kwargs['check_same_thread'] = False
super(Connection, self).__init__(*args, **kwargs)
示例8: __init__
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import html [as 別名]
def __init__(self, databaseFilePath):
print("Intializing database at {}".format(databaseFilePath))
self.dbConnection = sqlite3.connect(databaseFilePath)
# This gives us the ability to access results by column name
# See https://docs.python.org/3/library/sqlite3.html#row-objects
self.dbConnection.row_factory = sqlite3.Row
self.initializeDatabaseTables()