当前位置: 首页>>代码示例>>Python>>正文


Python sqlite3.Binary方法代码示例

本文整理汇总了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 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:25,代码来源:advancedhttpserver.py

示例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) 
开发者ID:afilipovich,项目名称:gglsbl,代码行数:22,代码来源:storage.py

示例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 
开发者ID:spectralpython,项目名称:spectral,代码行数:21,代码来源:aster.py

示例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 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:24,代码来源:sqlite.py

示例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 
开发者ID:UCL-InfoSec,项目名称:loopix,代码行数:18,代码来源:test_all.py

示例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 
开发者ID:UCL-InfoSec,项目名称:loopix,代码行数:18,代码来源:test_all.py

示例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 
开发者ID:UCL-InfoSec,项目名称:loopix,代码行数:23,代码来源:test_all.py

示例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))


    #-------------------------------------------------------------------------- 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:cachedb.py

示例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 
开发者ID:snuq,项目名称:Snu-Photo-Manager,代码行数:23,代码来源:main.py

示例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 
开发者ID:Lamden,项目名称:saffron,代码行数:19,代码来源:database.py

示例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) 
开发者ID:wakatime,项目名称:komodo-wakatime,代码行数:19,代码来源:session_cache.py

示例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) 
开发者ID:beeond,项目名称:opcua-modeling-tool,代码行数:27,代码来源:history_sql.py

示例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() 
开发者ID:alibaba,项目名称:iOSSecAudit,代码行数:18,代码来源:iosCertTrustManager.py

示例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 
开发者ID:FortyNorthSecurity,项目名称:EyeWitness,代码行数:21,代码来源:db_manager.py

示例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 
开发者ID:FortyNorthSecurity,项目名称:EyeWitness,代码行数:18,代码来源:db_manager.py


注:本文中的sqlite3.Binary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。