本文整理汇总了Python中shove.Shove.items方法的典型用法代码示例。如果您正苦于以下问题:Python Shove.items方法的具体用法?Python Shove.items怎么用?Python Shove.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shove.Shove
的用法示例。
在下文中一共展示了Shove.items方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSvnStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [as 别名]
class TestSvnStore(unittest.TestCase):
svnstring = 'SVN test string here'
def setUp(self):
from shove import Shove
self.store = Shove(self.svnstring, 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):
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.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()
#.........这里部分代码省略.........
示例2: TestDbmStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [as 别名]
class TestDbmStore(unittest.TestCase):
def setUp(self):
self.store = Shove('dbm://test.dbm', compress=True)
def tearDown(self):
self.store.close()
os.remove('test.dbm')
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):
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)
def test_setdefault(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['powl'] = 7
self.store.setdefault('pow', 8)
self.assertEqual(self.store['pow'], 8)
def test_update(self):
tstore = Shove()
tstore['max'] = 3
tstore['min'] = 6
#.........这里部分代码省略.........
示例3: TestCassandraStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [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
#.........这里部分代码省略.........
示例4: TestHDF5Store
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [as 别名]
class TestHDF5Store(unittest2.TestCase):
def setUp(self):
from shove import Shove
self.store = Shove('hdf5://test.hdf5/test')
def tearDown(self):
import os
self.store.close()
try:
os.remove('test.hdf5')
except OSError:
pass
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)
def test_setdefault(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
self.store.setdefault('bow', 8)
#.........这里部分代码省略.........
示例5: TestZodbStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [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)
#.........这里部分代码省略.........
示例6: TestFtpStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [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)
#.........这里部分代码省略.........
示例7: ngs_muscle_align
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [as 别名]
def ngs_muscle_align(libdict, seqdict, output_prefix, **kwargs):
#if this designed library member has any unique sequences that match to it
#then perform a pairwise alignment for each and update the relevant info
#for that unique sequence.
#Also update the count for the unique member.
lib_mems = Shove('file://'+output_prefix + '.shove.libmems')
#seqdict = Shove('file://'+output_prefix + '.shove.seqdict')
#====do alignment of clusters====
#create parallel process pool with all threads
pool = Pool()
muscle_jobs = {}
completed_jobs = 0
align_kwargs ={'ref_idx': 0, 'local': False, 'is_coding': 0}
print >> sys.stderr, 'Using MUSCLE to align clustered sequences...'
sys.stderr.flush()
pairwise_aligns = Shove('file://'+output_prefix+'.shove.pwa')
faalign_file = open(output_prefix+'.aligns.fa', 'w')
def use_muscle_output(muscle_tuple):
pwa, align_fa = muscle_tuple
print >> faalign_file, align_fa
pairwise_aligns.update(pwa)
for lm, uniques in lib_mems.items():
libdict[lm].annotations['count'] = len(uniques)
#perform parallel multiple alignment with clustered seqs using MUSCLE
if len(uniques) == 0: continue
muscle_jobs[lm] = pool.apply_async(align_recordlist, (
[(lm,libdict[lm].seq.tostring(),)]
+ [(uniq, seqdict[uniq][0],) for uniq in uniques],),
{'ref_idx': 0, 'local': False, 'is_coding': 0})
# out_tuple = (align_recordlist(
# [(lm,libdict[lm].seqdict(),)]
# + [(uniq, seqdict[uniq],) for uniq in uniques], **align_kwargs))
# pairwise_aligns.update(out_tuple[0])
# print >> faalign_file, out_tuple[1]
#
# completed_jobs += 1
# if completed_jobs % 100 == 0:
# print >> sys.stderr, '\t%d / %d clusters completed.' % (
# completed_jobs, len(lib_mems.items()))
# sys.stderr.flush()
submitted_jobs = len(muscle_jobs.keys())
print >> sys.stderr, '\t%d jobs submitted.' % (submitted_jobs)
#wait for all jobs to finish
while True:
for it in filter(lambda it: it[1].ready(), muscle_jobs.items()):
lm, mj = it
completed_jobs += 1
if not mj.successful():
import pdb
pdb.set_trace()
else:
use_muscle_output(mj.get())
del muscle_jobs[lm]
if completed_jobs % 250 == 0:
print >> sys.stderr, '\t%d / %d clusters completed.' % (
completed_jobs, submitted_jobs)
sys.stderr.flush()
if len(muscle_jobs) == 0:
break
pool.close()
pool.join()
print >> sys.stderr, '\tMUSCLE alignments complete.\b'
sys.stderr.flush()
示例8: TestLevelDBStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [as 别名]
class TestLevelDBStore(unittest2.TestCase):
def setUp(self):
from shove import Shove
self.store = Shove('leveldb://test', compress=True)
def tearDown(self):
import shutil
shutil.rmtree('test')
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)
def test_setdefault(self):
self.store['max'] = 3
self.store['min'] = 6
self.store['pow'] = 7
self.store.setdefault('bow', 8)
self.assertEqual(self.store['bow'], 8)
def test_update(self):
from shove import Shove
#.........这里部分代码省略.........
示例9: TestRedisStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [as 别名]
class TestRedisStore(unittest.TestCase):
def setUp(self):
from shove import Shove
self.store = Shove('redis://localhost:6379/0')
def tearDown(self):
self.store.clear()
self.store.close()
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['powl'] = 7
self.store.setdefault('pow', 8)
self.assertEqual(self.store.setdefault('pow', 8), 8)
self.assertEqual(self.store['pow'], 8)
def test_update(self):
from shove import Shove
tstore = Shove()
tstore['max'] = 3
tstore['min'] = 6
#.........这里部分代码省略.........
示例10: TestFileStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [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):
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import items [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)
#.........这里部分代码省略.........