本文整理汇总了Python中shove.Shove.values方法的典型用法代码示例。如果您正苦于以下问题:Python Shove.values方法的具体用法?Python Shove.values怎么用?Python Shove.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shove.Shove
的用法示例。
在下文中一共展示了Shove.values方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSvnStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import values [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 values [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 values [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 values [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 values [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 values [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: TestLevelDBStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import values [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
#.........这里部分代码省略.........
示例8: TestRedisStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import values [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
#.........这里部分代码省略.........
示例9: TestFileStore
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import values [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):
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import values [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)
#.........这里部分代码省略.........
示例11: EntryManager
# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import values [as 别名]
class EntryManager(object):
def __init__(self, location, **kwargs):
self.store = Shove(location, **kwargs)
def create_entry(self, entry):
"""
Create an entry in the entry manager::
>>> entry = {}
>>> entry['content'] = {'content': "<p>This is an entry.</p>"}
>>> entry['author'] = {'name': "Roberto De Almeida",
... 'email': "[email protected]"}
>>> em.create_entry(entry)
If empty, 'id' and 'updated' will be automatically set.
"""
# Required elements.
entry.setdefault('id', self._next_id())
entry.setdefault('updated', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()))
# Store entry.
self.store[str(entry["id"])] = entry
return entry
def get_entry(self, key):
"""
Retrieve an entry by its id::
>>> entry = em.get_entry("1")
Will return a dict describing the entry.
"""
entry = self.store[str(key)]
return entry
def get_entries(self, size=None, offset=0):
"""
Retrieve last n entries, sorted by the 'updated' attribute and in
descending order::
>>> entries = em.get_entries(10)
If you omit the number, all entries will be retrieved.
You can also specify an offset::
>>> entries = em.get_entries(10, 5)
This will skip the first 5 entries.
"""
entries = self.store.values()
# Sort by time.
entries.sort(key=operator.itemgetter('updated'), reverse=True)
if size is not None: size += offset
entries = entries[offset:size]
return entries
def delete_entry(self, key):
"""
Delete an entry identified by its key::
>>> em.delete_entry("1")
"""
del self.store[str(key)]
def update_entry(self, new_entry):
"""
Update an entry.
>>> entry = {'title': "This is an entry"}
>>> entry = em.create_entry(entry)
>>> print entry['id']
0
>>> entry['title'] = "A different title"
>>> em.update_entry(entry)
"""
# Retrieve old entry and update id.
entry = self.store[str(new_entry["id"])]
entry.update(new_entry)
# Update 'updated'.
entry['updated'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
# Store it back.
self.store[str(entry["id"])] = entry
return entry
def search(self, filters, flags=0, size=None, offset=0):
"""
Search all entries.
A simple, case-sensitive search for the word "Python" in the title::
>>> entries = em.search({"title": "Python"})
#.........这里部分代码省略.........