本文整理汇总了Python中shove.Shove.close方法的典型用法代码示例。如果您正苦于以下问题:Python Shove.close方法的具体用法?Python Shove.close怎么用?Python Shove.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shove.Shove
的用法示例。
在下文中一共展示了Shove.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCassandraStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestCassandraStore(Store, Spawn, unittest.TestCase):
cmd = ['cassandra', '-f']
@classmethod
def setUpClass(cls):
super(TestCassandraStore, cls).setUpClass()
import time
time.sleep(5.0)
def setUp(self):
from shove import Shove
from pycassa.system_manager import SystemManager # @UnresolvedImport @IgnorePep8
system_manager = SystemManager('localhost:9160')
try:
system_manager.create_column_family('Murk', 'shove')
except:
pass
self.store = Shove('cassandra://localhost:9160/Murk/shove')
def tearDown(self):
if self.store._store is not None:
self.store.clear()
self.store.close()
from pycassa.system_manager import SystemManager # @UnresolvedImport @IgnorePep8
system_manager = SystemManager('localhost:9160')
system_manager.drop_column_family('Murk', 'shove')
@classmethod
def tearDownClass(cls):
from fabric.api import local
local('killall java')
示例2: getRSSFeed
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
def getRSSFeed(self, url, post_data=None):
# create provider storaqe cache
storage = Shove('sqlite:///' + ek.ek(os.path.join, sickbeard.CACHE_DIR, self.provider.name) + '.db')
fc = cache.Cache(storage)
parsed = list(urlparse.urlparse(url))
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
if post_data:
url = url + 'api?' + urllib.urlencode(post_data)
f = fc.fetch(url)
if not f:
logger.log(u"Error loading " + self.providerID + " URL: " + url, logger.ERROR)
return None
elif 'error' in f.feed:
logger.log(u"Newznab ERROR:[%s] CODE:[%s]" % (f.feed['error']['description'], f.feed['error']['code']),
logger.DEBUG)
return None
elif not f.entries:
logger.log(u"No items found on " + self.providerID + " using URL: " + url, logger.WARNING)
return None
storage.close()
return f
示例3: _ShoveWrapper
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class _ShoveWrapper(object):
def __init__(self, loc):
self._loc = loc
self._shove = Shove(self._loc)
def __enter__(self):
return self._shove
def __exit__(self, type, value, traceback):
self._shove.close()
示例4: primary_file_name
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
def primary_file_name(self):
"""The file name for the 'primary' file in the bucket. It is this file from which data is loaded. Other files
within the bucket should be auxiliary to this file. (E.g. they should contain projection information.)
"""
shove = Shove(self._shove_url)
try:
return shove['primary_file_name']
except KeyError:
return None
finally:
shove.close()
示例5: TestFTPStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestFTPStore(Store, unittest.TestCase):
initstring = 'ftp://127.0.0.1/'
def setUp(self):
from shove import Shove
self.store = Shove(self.initstring, compress=True)
def tearDown(self):
self.store.clear()
self.store.close()
示例6: create_sequence_dbs_for_GAF
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
def create_sequence_dbs_for_GAF(gaf, transcripts_file, output_dir):
from Bio import SeqIO
from Bio import Seq
import os
print "Indexing GAF db by transcript id...\n"
gaf_transcript_idx = dict()
for i,g in enumerate(gaf):
for k in gaf[g].keys():
for ctr,t in enumerate(gaf[g][k]):
gaf_transcript_idx[t['transcript_id']] = (ctr,g,k)
fh_transcripts = SeqIO.parse(transcripts_file, 'fasta')
# transcripts_shlv = shelve.open(os.path.join(output_dir, 'GAF_transcript_seqs.fa.shlv'), 'c')
# proteins_shlv = shelve.open(os.path.join(output_dir, 'GAF_protein_seqs.fa.shlv'), 'c')
transcripts_shlv = Shove("file://" + os.path.join(output_dir, 'GAF_transcript_seqs.fa.shove'))
protein_seqs_url = "file://" + os.path.join(output_dir, 'GAF_protein_seqs.fa.shove')
proteins_shlv = Shove(protein_seqs_url)
print "Writing transcript and protein shove dbs..."
j = 0
transcripts_to_remove = list()
for transcript in fh_transcripts:
if j % 1000 == 0: print j
j += 1
if transcript.name not in gaf_transcript_idx:
continue
gaf_record = gaf[gaf_transcript_idx[transcript.name][1]][gaf_transcript_idx[transcript.name][2]][gaf_transcript_idx[transcript.name][0]]
raw_seq = str(transcript.seq)
transcripts_shlv[transcript.name] = raw_seq
if 'cds_start' not in gaf_record or not gaf_record['cds_start']: continue
prot_seq = Seq.translate(raw_seq[gaf_record['cds_start']-1:gaf_record['cds_stop']])
if prot_seq[-1] == '*':
prot_seq = prot_seq[:-1]
elif prot_seq.find('*') != -1:
# skip small number (n=12) transcripts with incorrect CDS coordinates
transcripts_to_remove.append(transcript.name)
continue
proteins_shlv[transcript.name] = prot_seq
for t in transcripts_to_remove:
del transcripts_shlv[t]
transcripts_shlv.close()
proteins_shlv.close()
return transcripts_to_remove,protein_seqs_url
示例7: TestHDF5Store
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestHDF5Store(Store, unittest.TestCase):
initstring = 'hdf5://test.hdf5/test'
def setUp(self):
from shove import Shove
self.store = Shove()
def tearDown(self):
import os
self.store.close()
try:
os.remove('test.hdf5')
except OSError:
pass
示例8: save_data
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
def save_data(self, data):
db = Shove(self.conf['data_file'])
modified = False
for item in data:
try:
db[item['guid']]
except KeyError:
db[item['guid']] = item
modified = True
else:
if db[item['guid']] != item:
db[item['guid']] = item
modified = True
db.close()
return modified
示例9: ShoveCache
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class ShoveCache(Cache):
"""Expects a url in the form that shove requires.
Maintains a cache of keys to speed performance."""
def __init__(self, url_db, url_cache):
self.db = Shove(url_db, url_cache, optimize=False, max_entries=2000)
def retrieve_from_cache(self, key):
try:
val = self.db[key]
return val
except KeyError:
return None
def store_into_cache(self, key, value):
self.db[key] = value
def close_cache(self):
self.db.close()
示例10: TestCassandraStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestCassandraStore(unittest.TestCase):
def setUp(self):
from shove import Shove
from pycassa.system_manager import SystemManager
system_manager = SystemManager('localhost:9160')
try:
system_manager.create_column_family('Foo', 'shove')
except:
pass
self.store = Shove('cassandra://localhost:9160/Foo/shove')
def tearDown(self):
self.store.clear()
self.store.close()
from pycassa.system_manager import SystemManager
system_manager = SystemManager('localhost:9160')
system_manager.drop_column_family('Foo', 'shove')
def test__getitem__(self):
self.store['max'] = 3
self.assertEqual(self.store['max'], 3)
def test__setitem__(self):
self.store['max'] = 3
self.assertEqual(self.store['max'], 3)
def test__delitem__(self):
self.store['max'] = 3
del self.store['max']
self.assertEqual('max' in self.store, False)
def test_get(self):
self.store['max'] = 3
self.assertEqual(self.store.get('min'), None)
def test__cmp__(self):
from shove import Shove
tstore = Shove()
self.store['max'] = 3
tstore['max'] = 3
self.assertEqual(self.store, tstore)
def test__len__(self):
self.store['max'] = 3
self.store['min'] = 6
self.assertEqual(len(self.store), 2)
# def test_clear(self):
# self.store['max'] = 3
# self.store['min'] = 6
# self.store['pow'] = 7
# self.store.clear()
# self.assertEqual(len(self.store), 0)
def test_items(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.items())
self.assertEqual(('min', 6) in slist, True)
def test_iteritems(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.iteritems())
self.assertEqual(('min', 6) in slist, True)
def test_iterkeys(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.iterkeys())
self.assertEqual('min' in slist, True)
def test_itervalues(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.itervalues())
self.assertEqual(6 in slist, True)
def test_pop(self):
self.store['max'] = 3
self.store['min'] = 6
item = self.store.pop('min')
self.assertEqual(item, 6)
# def test_popitem(self):
# self.store['max'] = 3
# self.store['min'] = 6
# self.store['pow'] = 7
# item = self.store.popitem()
# self.assertEqual(len(item) + len(self.store), 4)
def test_setdefault(self):
self.store['max'] = 3
self.store['min'] = 6
# self.store['pow'] = 7
#.........这里部分代码省略.........
示例11: TestFtpStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestFtpStore(unittest.TestCase):
ftpstring = "put ftp string here"
def setUp(self):
self.store = Shove(self.ftpstring, compress=True)
def tearDown(self):
self.store.clear()
self.store.close()
def test__getitem__(self):
self.store["max"] = 3
self.store.sync()
self.assertEqual(self.store["max"], 3)
def test__setitem__(self):
self.store["max"] = 3
self.store.sync()
self.assertEqual(self.store["max"], 3)
def test__delitem__(self):
self.store["max"] = 3
del self.store["max"]
self.assertEqual("max" in self.store, False)
def test_get(self):
self.store["max"] = 3
self.store.sync()
self.assertEqual(self.store.get("min"), None)
def test__cmp__(self):
tstore = Shove()
self.store["max"] = 3
tstore["max"] = 3
self.store.sync()
tstore.sync()
self.assertEqual(self.store, tstore)
def test__len__(self):
self.store["max"] = 3
self.store["min"] = 6
self.store.sync()
self.assertEqual(len(self.store), 2)
def test_clear(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.sync()
self.store.clear()
self.assertEqual(len(self.store), 0)
def test_items(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.sync()
slist = list(self.store.items())
self.assertEqual(("min", 6) in slist, True)
def test_iteritems(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.sync()
slist = list(self.store.iteritems())
self.assertEqual(("min", 6) in slist, True)
def test_iterkeys(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.sync()
slist = list(self.store.iterkeys())
self.assertEqual("min" in slist, True)
def test_itervalues(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.sync()
slist = list(self.store.itervalues())
self.assertEqual(6 in slist, True)
def test_pop(self):
self.store["max"] = 3
self.store["min"] = 6
self.store.sync()
item = self.store.pop("min")
self.assertEqual(item, 6)
def test_popitem(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.sync()
item = self.store.popitem()
self.store.sync()
self.assertEqual(len(item) + len(self.store), 4)
#.........这里部分代码省略.........
示例12: TestZodbStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestZodbStore(unittest.TestCase):
init = "zodb://test.db"
def setUp(self):
from shove import Shove
self.store = Shove(self.init, compress=True)
def tearDown(self):
self.store.close()
import os
os.remove("test.db")
os.remove("test.db.index")
os.remove("test.db.tmp")
os.remove("test.db.lock")
def test__getitem__(self):
self.store["max"] = 3
self.assertEqual(self.store["max"], 3)
def test__setitem__(self):
self.store["max"] = 3
self.assertEqual(self.store["max"], 3)
def test__delitem__(self):
self.store["max"] = 3
del self.store["max"]
self.assertEqual("max" in self.store, False)
def test_get(self):
self.store["max"] = 3
self.assertEqual(self.store.get("min"), None)
def test__cmp__(self):
from shove import Shove
tstore = Shove()
self.store["max"] = 3
tstore["max"] = 3
self.assertEqual(self.store, tstore)
def test__len__(self):
self.store["max"] = 3
self.store["min"] = 6
self.assertEqual(len(self.store), 2)
def test_close(self):
self.store.close()
self.assertEqual(self.store, None)
def test_clear(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
self.store.clear()
self.assertEqual(len(self.store), 0)
def test_items(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
slist = list(self.store.items())
self.assertEqual(("min", 6) in slist, True)
def test_iteritems(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
slist = list(self.store.iteritems())
self.assertEqual(("min", 6) in slist, True)
def test_iterkeys(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
slist = list(self.store.iterkeys())
self.assertEqual("min" in slist, True)
def test_itervalues(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
slist = list(self.store.itervalues())
self.assertEqual(6 in slist, True)
def test_pop(self):
self.store["max"] = 3
self.store["min"] = 6
item = self.store.pop("min")
self.assertEqual(item, 6)
def test_popitem(self):
self.store["max"] = 3
self.store["min"] = 6
self.store["pow"] = 7
item = self.store.popitem()
self.assertEqual(len(item) + len(self.store), 4)
#.........这里部分代码省略.........
示例13: DataManager
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class DataManager():
def __init__(self, filename, connection_details=VERTICA_CONNECTION):
self.filename = filename
self.store = Shove('file://'+self.filename, 'memory://', optimize=False)
self.connection_details = connection_details
@staticmethod
def get_attribute_name(data_set, attribute):
return '_' + data_set + '_' + attribute
def get_data_set_attribute(self, data_set, key):
attrib_name = self.get_attribute_name(data_set, key)
if self.has_attribute(data_set, key):
return self.store[attrib_name]
else:
return None
self.store.close()
gc.collect()
self.store = Shove('file://'+self.filename, 'memory://', optimize=False)
def set_data_set_attribute(self, data_set, key, value):
attrib_name = self.get_attribute_name(data_set, key)
self.store.update({attrib_name: value})
self.store.sync()
self.store.close()
gc.collect()
self.store = Shove('file://'+self.filename, 'memory://', optimize=False)
def has_attribute(self, data_set, key):
attrib_name = self.get_attribute_name(data_set, key)
if attrib_name in self.store.keys():
return True
else:
return False
def remove_attribute(self, data_set, key):
attrib_name = self.get_attribute_name(data_set, key)
if attrib_name in self.store:
del self.store[attrib_name]
self.store.sync()
def get_data_set_list(self):
data_sets = [key.split('_')[1] for key in self.store.keys() if '_query' in key]
return data_sets
def fetch_from_vertica_to_df(self, data_set, query):
data_set_query = self.get_data_set_attribute(data_set, 'query')
if data_set_query != query:
connection = connect(self.connection_details)
cursor = connection.cursor()
print 'Executing ', data_set, 'Query...'
print query
columns = get_column_names_from_sql_query(query)
cursor.execute(query)
data = []
while True:
rows = cursor.fetchmany(10000)
data.extend([[str(ele) for ele in row] for row in rows])
if len(rows) <= 1:
break
df = MetadataDataFrame(data=data, columns=columns, meta_info={'query': query, 'built_features': [], 'aggregate_values': {},
'columns': columns})
cursor.close()
if len(df) == 0:
raise(ValueError('SQL result in empty fetch!!'))
else:
self.set_data_set_attribute(data_set, 'data', df)
self.set_data_set_attribute(data_set, 'query', query)
self.set_data_set_attribute(data_set, 'columns', columns)
self.set_data_set_attribute(data_set, 'built_features', [])
示例14: __init__
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class Personis_server:
def __init__(self, modeldir=None, adminsfile=None, oauthconfig=None):
self.modeldir = modeldir
self.admins = yaml.load(file(adminsfile,'r'))
self.oauth_clients = Shove('sqlite:///oauth_clients.dat')
self.users = Shove('sqlite:///oauth_users.dat')
self.bearers = Shove('sqlite:///oauth_bearers.dat')
self.oauthconf = yaml.load(file(oauthconfig,'r'))
def stopper():
print 'saving persistant data'
self.oauth_clients.close()
self.users.close()
self.bearers.close()
cherrypy.engine.subscribe('stop', stopper)
@cherrypy.expose
def list_clients(self):
if cherrypy.session.get('user') == None:
cherrypy.session['target_url'] = '/list_clients'
raise cherrypy.HTTPRedirect('/login')
if not cherrypy.session.get('user')['id'] in self.admins.keys():
raise cherrypy.HTTPError()
base_path = os.path.dirname(os.path.abspath(__file__))
loader = TemplateLoader([base_path])
tmpl = loader.load('list_clients.html')
for k, v in self.oauth_clients.items():
print k, v.friendly_name
stream = tmpl.generate(clients=self.oauth_clients.values())
return stream.render('xhtml')
@cherrypy.expose
def list_clients_save(self, id, value, _method='get'):
if cherrypy.session.get('user') == None:
raise cherrypy.HTTPError()
if not cherrypy.session.get('user')['id'] in self.admins.keys():
raise cherrypy.HTTPError()
if id == "removeOneForMe":
del(self.oauth_clients[value])
self.oauth_clients.sync()
print "removed a client"
raise cherrypy.HTTPRedirect('/list_clients')
if id == "addOneForMe":
clid = ''
secret = ''
for i in range(10):
clid = clid + str(int(random.random()*100))
secret = secret + str(int(random.random()*100))
self.oauth_clients[clid] = oauth_client(
client_id = clid,
friendly_name= 'my client',
secret= secret,
redirect_uri='http://www.example.com/',
icon='/static/images/icon.svg')
self.oauth_clients.sync()
print "added a client"
raise cherrypy.HTTPRedirect('/list_clients')
clid, field = id.split('|')
print 'saving: ',clid, field, value
oldc = self.oauth_clients[clid]
oldc.__dict__[field] = value
self.oauth_clients[clid] = oldc
for k, v in self.oauth_clients.items():
print k, v.friendly_name
self.oauth_clients.sync()
return value
@cherrypy.expose
def authorize(self, client_id, redirect_uri, scope, access_type, response_type='code', approval_prompt='auto', state=None):
body = cherrypy.request.body.fp.read()
rurl = cherrypy.request.base+cherrypy.request.path_info
cherrypy.session['client_id'] = client_id
cli = self.oauth_clients[client_id]
if state <> None:
cherrypy.session['state'] = state
if cli.redirect_uri <> redirect_uri:
raise cherrypy.HTTPError()
raise cherrypy.HTTPRedirect('/login')
@cherrypy.expose
def login(self):
flow = OAuth2WebServerFlow(client_id=self.oauthconf['personis_client_id'],
client_secret=self.oauthconf['personis_client_secret'],
scope='https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
user_agent='personis-server/1.0')
callback = callback = cherrypy.request.base + '/logged_in'
authorize_url = flow.step1_get_authorize_url(callback)
cherrypy.session['flow'] = flow
raise cherrypy.HTTPRedirect(authorize_url)
@cherrypy.expose
def logged_in(self, code):
flow = cherrypy.session.get('flow')
if not flow:
raise IOError()
credentials = flow.step2_exchange(cherrypy.request.params)
#.........这里部分代码省略.........
示例15: TestFileStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import close [as 别名]
class TestFileStore(unittest.TestCase):
def setUp(self):
from shove import Shove
self.store = Shove('file://test', compress=True)
def tearDown(self):
import os
self.store.close()
for x in os.listdir('test'):
os.remove(os.path.join('test', x))
os.rmdir('test')
def test__getitem__(self):
self.store['max'] = 3
self.store.sync()
self.assertEqual(self.store['max'], 3)
def test__setitem__(self):
self.store['max'] = 3
self.store.sync()
self.assertEqual(self.store['max'], 3)
def test__delitem__(self):
self.store['max'] = 3
del self.store['max']
self.assertEqual('max' in self.store, False)
def test_get(self):
self.store['max'] = 3
self.store.sync()
self.assertEqual(self.store.get('min'), None)
def test__cmp__(self):
from shove import Shove
tstore = Shove()
self.store['max'] = 3
tstore['max'] = 3
self.store.sync()
tstore.sync()
self.assertEqual(self.store, tstore)
def test__len__(self):
self.store['max'] = 3
self.store['min'] = 6
self.assertEqual(len(self.store), 2)
def test_close(self):
self.store.close()
self.assertEqual(self.store, None)
def test_clear(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
self.store.clear()
self.assertEqual(len(self.store), 0)
def test_items(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.items())
self.assertEqual(('min', 6) in slist, True)
def test_iteritems(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.iteritems())
self.assertEqual(('min', 6) in slist, True)
def test_iterkeys(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.iterkeys())
self.assertEqual('min' in slist, True)
def test_itervalues(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
slist = list(self.store.itervalues())
self.assertEqual(6 in slist, True)
def test_pop(self):
self.store['max'] = 3
self.store['min'] = 6
item = self.store.pop('min')
self.assertEqual(item, 6)
def test_popitem(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
item = self.store.popitem()
self.assertEqual(len(item) + len(self.store), 4)
def test_setdefault(self):
#.........这里部分代码省略.........