本文整理匯總了Python中sqlite3.Binary方法的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.Binary方法的具體用法?Python sqlite3.Binary怎麽用?Python sqlite3.Binary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3
的用法示例。
在下文中一共展示了sqlite3.Binary方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cache_call_refresh
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def cache_call_refresh(self, method, *options):
"""
Call a remote method and update the local cache with the result
if it already existed.
:param str method: The name of the remote procedure to execute.
:return: The return value from the remote function.
"""
options_hash = self.encode(options)
if len(options_hash) > 20:
options_hash = hashlib.new('sha1', options).digest()
options_hash = sqlite3.Binary(options_hash)
with self.cache_lock:
cursor = self.cache_db.cursor()
cursor.execute('DELETE FROM cache WHERE method = ? AND options_hash = ?', (method, options_hash))
return_value = self.call(method, *options)
store_return_value = sqlite3.Binary(self.encode(return_value))
with self.cache_lock:
cursor = self.cache_db.cursor()
cursor.execute('INSERT INTO cache (method, options_hash, return_value) VALUES (?, ?, ?)', (method, options_hash, store_return_value))
self.cache_db.commit()
return return_value
示例2: store_full_hash
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def store_full_hash(self, threat_list, hash_value, cache_duration, malware_threat_type):
"""Store full hash found for the given hash prefix"""
log.info('Storing full hash %s to list %s with cache duration %s',
to_hex(hash_value), str(threat_list), cache_duration)
qi = '''INSERT OR IGNORE INTO full_hash
(value, threat_type, platform_type, threat_entry_type, malware_threat_type, downloaded_at)
VALUES
(?, ?, ?, ?, ?, current_timestamp)
'''
qu = "UPDATE full_hash SET expires_at=datetime(current_timestamp, '+{} SECONDS') \
WHERE value=? AND threat_type=? AND platform_type=? AND threat_entry_type=?"
i_parameters = [sqlite3.Binary(hash_value), threat_list.threat_type,
threat_list.platform_type, threat_list.threat_entry_type, malware_threat_type]
u_parameters = [sqlite3.Binary(hash_value), threat_list.threat_type,
threat_list.platform_type, threat_list.threat_entry_type]
with self.get_cursor() as dbc:
dbc.execute(qi, i_parameters)
dbc.execute(qu.format(int(cache_duration)), u_parameters)
示例3: _add_signature
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def _add_signature(
self, sampleID, calibrationID, instrument, environment, measurement,
xUnit, yUnit, minWavelength, maxWavelength, xData, yData):
import sqlite3
import array
sql = '''INSERT INTO Spectra (SampleID, SensorCalibrationID, Instrument,
Environment, Measurement, XUnit, YUnit, MinWavelength, MaxWavelength,
NumValues, XData, YData) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'''
xBlob = sqlite3.Binary(tobytes(array.array(arraytypecode, xData)))
yBlob = sqlite3.Binary(tobytes(array.array(arraytypecode, yData)))
numValues = len(xData)
self.cursor.execute(
sql, (
sampleID, calibrationID, instrument, environment, measurement,
xUnit, yUnit, minWavelength, maxWavelength, numValues, xBlob,
yBlob))
rowId = self.cursor.lastrowid
self.db.commit()
return rowId
示例4: adapt_obj
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def adapt_obj(obj):
"""Binarize objects to be stored in an SQLite database.
Parameters
----------
obj : object
Any picklable object.
Returns
-------
blob : memoryview
A buffer (Python 2) or memoryview (Python 3) of the pickled object
that can be stored as a BLOB in an SQLite database.
"""
blob = sqlite3.Binary(cPickle.dumps(obj))
if len(blob) > config.max_blob_size:
warnings.warn('large objects stored in SQLite' +
LARGE_BLOB_WARNING.format(type(obj), len(blob)))
# Prevent the warning with variable message from repeating
warnings.filterwarnings('ignore', 'large objects .*')
return blob
示例5: loopix_mixes
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def loopix_mixes():
sec_params = SphinxParams(header_len=1024)
dbManager.create_mixnodes_table('Mixnodes')
mixes = []
pubs_mixes = []
for i in range(3):
mix = LoopixMixNode(sec_params, 'Mix%d'%(i+1), 9999-i, '1.2.3.%d'%i, i)
mix.transport = proto_helpers.FakeDatagramTransport()
mix.config_params = mix.config_params._replace(DATABASE_NAME = 'test.db')
mixes.append(mix)
dbManager.insert_row_into_table('Mixnodes',
[None, mix.name, mix.port, mix.host,
sqlite3.Binary(petlib.pack.encode(mix.pubk)), mix.group])
pubs_mixes = [Mix(m.name, m.port, m.host, m.pubk, m.group) for m in mixes]
return mixes, pubs_mixes
示例6: loopix_providers
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def loopix_providers():
sec_params = SphinxParams(header_len=1024)
dbManager.create_providers_table('Providers')
providers = []
pubs_providers = []
for i in range(3):
p = LoopixProvider(sec_params, 'Provider%d'%(i+1), 9995-i, '1.2.%d.4'%i)
p.transport = proto_helpers.FakeDatagramTransport()
p.config_params = p.config_params._replace(DATABASE_NAME = 'test.db')
providers.append(p)
dbManager.insert_row_into_table('Providers',
[None, p.name, p.port, p.host,
sqlite3.Binary(petlib.pack.encode(p.pubk))])
pubs_providers = [Provider(p.name, p.port, p.host, p.pubk) for p in providers]
return providers, pubs_providers
示例7: loopix_clients
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def loopix_clients(pubs_providers, pubs_mixes):
sec_params = SphinxParams(header_len=1024)
dbManager.create_users_table('Users')
clients = []
pubs_clients = []
for i in range(3):
provider = pubs_providers[i]
c = LoopixClient(sec_params, 'Client%d'%(i+1), 9993 - i, '1.%d.3.4'%i, provider.name)
c.register_mixes(pubs_mixes)
c.transport = proto_helpers.FakeDatagramTransport()
c.config_params = c.config_params._replace(DATABASE_NAME = 'test.db')
c.provider = dbManager.select_provider_by_name(provider.name)
clients.append(c)
dbManager.insert_row_into_table('Users',
[None, c.name, c.port, c.host,
sqlite3.Binary(petlib.pack.encode(c.pubk)),
c.provider.name])
pubs_clients = [User(c.name, c.port, c.host, c.pubk, c.provider) for c in clients]
return clients, pubs_clients
示例8: set
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def set(self, audit, key, data, protocol="http", timestamp=None, lifespan=None):
protocol = self._sanitize_protocol(protocol)
data = self.encode(data)
data = sqlite3.Binary(data)
if lifespan is None:
lifespan = 0
if timestamp is None:
self.__cursor.execute("""
INSERT INTO cache (audit, key, protocol, data, lifespan)
VALUES ( ?, ?, ?, ?, ? );
""", (audit, key, protocol, data, lifespan))
else:
self.__cursor.execute("""
INSERT INTO cache (audit, key, protocol, data, timestamp, lifespan)
VALUES ( ?, ?, ?, ?, ?, ? );
""", (audit, key, protocol, data, timestamp, lifespan))
#--------------------------------------------------------------------------
示例9: database_thumbnail_update
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def database_thumbnail_update(self, fullpath, database, modified_date, orientation, temporary=False, force=False):
"""Check if a thumbnail is already in database, check if out of date, update if needed.
Arguments:
fullpath: String, the database-relative path to the photo.
database: String, database directory the photo is in.
modified_date: Integer, the modified date of the original photo.
orientation: Integer, EXIF orientation code.
temporary: Boolean, if True, uses the temporary thumbnails database.
force: Boolean, if True, will always update thumbnail, regardless of modified date.
Returns: Boolean, True if thumbnail updated, False if not.
"""
#check if thumbnail is already in database, check if out of date, update if needed
matches = self.database_thumbnail_get(fullpath, temporary=temporary)
if matches:
if modified_date <= matches[1] and not force:
return False
thumbnail = self.generate_thumbnail(local_path(fullpath), local_path(database))
thumbnail = sqlite3.Binary(thumbnail)
self.database_thumbnail_write(fullpath=fullpath, modified_date=modified_date, thumbnail=thumbnail, orientation=orientation, temporary=temporary)
return True
示例10: insert_contract
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def insert_contract(name: str, abi, bytecode: str, gas_estimates, method_identifiers, cwd):
'''insert_contract into the localdb, also converts the type
'''
assert name
assert abi
assert bytecode
assert gas_estimates
assert method_identifiers
gas = pickle.dumps(gas_estimates)
methods = pickle.dumps(method_identifiers)
result = cursor.execute(insert_contract_sql, (name,
str(abi),
bytecode,
sqlite3.Binary(gas),
sqlite3.Binary(methods)))
connection.commit()
return result
示例11: save
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def save(self, session):
"""Saves a requests.Session object for the next heartbeat process.
"""
if not HAS_SQL: # pragma: nocover
return
try:
conn, c = self.connect()
c.execute('DELETE FROM {0}'.format(self.table_name))
values = {
'value': sqlite3.Binary(pickle.dumps(session, protocol=2)),
}
c.execute('INSERT INTO {0} VALUES (:value)'.format(self.table_name), values)
conn.commit()
conn.close()
except: # pragma: nocover
log.traceback(logging.DEBUG)
示例12: _format_event
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def _format_event(self, event):
"""
Convert an event object triggered by the subscription into ordered lists for the SQL insert string
Args:
event: The event returned by the subscription
Returns: List of event fields (SQL column names), List of '?' placeholders, Tuple of variant binaries
"""
placeholders = []
ev_variant_binaries = []
ev_variant_dict = event.get_event_props_as_fields_dict()
names = list(ev_variant_dict.keys())
names.sort() # sort alphabetically since dict is not sorted
# split dict into two synchronized lists which will be converted to SQL strings
# note that the variants are converted to binary objects for storing in SQL BLOB format
for name in names:
variant = ev_variant_dict[name]
placeholders.append('?')
ev_variant_binaries.append(sqlite3.Binary(variant.to_binary()))
return self._list_to_sql_str(names), self._list_to_sql_str(placeholders, False), tuple(ev_variant_binaries)
示例13: _add_record
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def _add_record(self, sha1, subj, tset, data):
if not self.is_valid():
print " Invalid TrustStore.sqlite3"
return
conn = sqlite3.connect(self._path)
c = conn.cursor()
c.execute('SELECT COUNT(*) FROM tsettings WHERE subj=?', [sqlite3.Binary(subj)])
row = c.fetchone()
if row[0] == 0:
c.execute('INSERT INTO tsettings (sha1, subj, tset, data) VALUES (?, ?, ?, ?)', [sqlite3.Binary(sha1), sqlite3.Binary(subj), sqlite3.Binary(tset), sqlite3.Binary(data)])
print ' Certificate added'
else:
c.execute('UPDATE tsettings SET sha1=?, tset=?, data=? WHERE subj=?', [sqlite3.Binary(sha1), sqlite3.Binary(tset), sqlite3.Binary(data), sqlite3.Binary(subj)])
print ' Existing certificate replaced'
conn.commit()
conn.close()
示例14: create_http_object
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def create_http_object(self, remote_system, cli_parsed):
c = self.connection.cursor()
obj = HTTPTableObject()
obj.remote_system = remote_system
obj.set_paths(
cli_parsed.d, None)
obj.max_difference = cli_parsed.difference
c.execute("SELECT MAX(id) FROM http")
rowid = c.fetchone()[0]
if rowid is None:
rowid = 0
obj.id = rowid + 1
pobj = sqlite3.Binary(pickle.dumps(obj, protocol=2))
c.execute(("INSERT INTO http (object, complete)"
"VALUES (?,?)"),
(pobj, False))
self.connection.commit()
c.close()
return obj
示例15: create_ua_object
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Binary [as 別名]
def create_ua_object(self, http_object, browser, ua):
c = self.connection.cursor()
obj = UAObject(browser, ua)
obj.copy_data(http_object)
c.execute("SELECT MAX(id) FROM ua")
rowid = c.fetchone()[0]
if rowid is None:
rowid = 0
obj.id = rowid + 1
pobj = sqlite3.Binary(pickle.dumps(obj, protocol=2))
c.execute(("INSERT INTO ua (parent_id, object, complete, key)"
" VALUES (?,?,?,?)"),
(http_object.id, pobj, False, browser))
self.connection.commit()
c.close()
return obj