本文整理汇总了Python中connection.Connection.get方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get方法的具体用法?Python Connection.get怎么用?Python Connection.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConnectionTest
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get [as 别名]
class ConnectionTest(AsyncTestCase):
def setUp(self):
super(ConnectionTest, self).setUp()
self.conn = Connection(['127.0.0.1:11211'], debug=True)
def test_get_host(self):
host = self.conn.get_host('key')
assert isinstance(host, TCPConnection)
@gen_test
def test_set_get(self):
res = yield self.conn.set('key', 'test', 10)
assert res is True
res = yield self.conn.get('key')
assert res == 'test'
@gen_test
def test_delete(self):
yield self.conn.set('del', 'del', 10)
res = yield self.conn.get('del')
assert res == 'del'
res = yield self.conn.delete('del')
assert res is True
res = yield self.conn.get('del')
assert res is None
@gen_test
def test_set_get_multi(self):
res = yield self.conn.set_multi({'key1': 'test1', 'key2': 'test2', 'key3': 'test3', 1: '3', 2: 2}, 10, key_prefix="multi_")
assert res == []
res = yield self.conn.get_multi(['key1', 'key2', 'key3', 1, 2], key_prefix='multi_')
print res
assert res == {'key1': 'test1', 'key2': 'test2', 'key3': 'test3', 1: '3', 2: 2}
res = yield self.conn.get_multi(['key', 'key2', 'key3'], key_prefix='multi_')
print res
assert res == {'key2': 'test2', 'key3': 'test3'}
@gen_test
def test_incr(self):
yield self.conn.set('incr', 0, 10)
res = yield self.conn.incr('incr')
print 'incr0:', res
res = yield self.conn.incr('incr')
print 'incr1:', res
@gen_test
def test_close(self):
self.conn.disconnect_all()
示例2: TestBinaryProtocol
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get [as 别名]
class TestBinaryProtocol(unittest.TestCase):
def setUp(self):
servers = [("127.0.0.1",11211)]
self.connection = Connection()
self.connection.add_servers(servers)
def test_delete_exception(self):
self.assertRaises(ProtocolException, self.connection.delete, key="Hello")
def test_add(self):
self.assertTrue(self.connection.add("Hello", "World"))
def test_get(self):
self.assertTrue(self.connection.get("Hello"))
def test_add_exception(self):
self.assertRaises(ProtocolException, self.connection.add, key="Hello", value="World")
def testAddUnicode(self):
self.connection.add("Hello", u"łóść")
def test_delete(self):
self.assertTrue(self.connection.delete(key="Hello"))
示例3: __init__
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get [as 别名]
class Game:
def __init__(self, account):
self.username = account['username']
self.password = account['password']
self.server = account['server']
self.shipClasses = { }
self.ships = { }
self.fleets = [ None, None, None, None ]
self.expeditions = { }
self.repairYards = [ None, None, None, None ]
self.maxShipNum = 0
self.errorCodes = { }
self.packer = Packer(self)
Log.i('Initializing game...')
self.conn = Connection()
self.gameData = self.conn.get('/index/getInitConfigs/')
for shipClassData in self.gameData['shipCard']:
if int(shipClassData['npc']) == 0 and int(shipClassData['release']) == 1:
shipClass = self.packer.makeShipClass(shipClassData)
self.shipClasses[shipClass.id] = shipClass
for expeditionData in self.gameData['pveExplore']:
expedition = self.packer.makeExpedition(expeditionData)
self.expeditions[expedition.id] = expedition
Log.errorCodes = { int(k) : v for k, v in self.gameData['errorCode'].items() }
Log.i('Logging in...')
loginData = self.conn.httpsGet('/index/passportLogin/%s/%s/' % (self.username, self.password))
self.conn.setServer(self.server)
time.sleep(1)
self.conn.get('//index/login/' + loginData['userId'])
Log.i('Initializing user data...')
self.userData = self.conn.get('/api/initGame/')
self.conn.get('/pevent/getPveData/')
self.conn.get('/pve/getPveData/')
time.sleep(5)
self.conn.get('/active/getUserData/')
self.conn.get('/campaign/getUserData/')
self.conn.get('/pve/getUserData/')
for shipData in self.userData['userShipVO']:
ship = self.packer.makeShip(shipData)
self.ships[ship.id] = ship
for fleetData in self.userData['fleetVo']:
fleet = self.packer.makeFleet(fleetData)
self.fleets[fleet.id - 1] = fleet
for expStatusData in self.userData['pveExploreVo']['levels']:
exp = self.expeditions[int(expStatusData['exploreId'])]
fleet = self.fleets[int(expStatusData['fleetId']) - 1]
endTime = datetime.fromtimestamp(int(expStatusData['endTime']))
exp.setStatus(fleet, endTime)
for repairYardData in self.userData['repairDockVo']:
ry = self.packer.makeRepairYard(repairYardData)
self.repairYards[ry.id - 1] = ry
self.maxShipNum = int(self.userData['userVo']['detailInfo']['shipNumTop'])
Log.i('Done')
def restart(self):
self.conn = Connection()
self.conn.get('/index/getInitConfigs/')
loginData = self.conn.get('/index/passportLogin/%s/%s/' % (self.username, self.password))
self.conn.setServer(self.server)
self.conn.get('//index/login/' + loginData['userId'])
self.conn.get('/api/initGame/')
Log.i('Game restarted')
def getShipClass(self, id_):
return self.shipClasses[id_]
def getShip(self, id_):
return self.ships[id_]
def findShip(self, name, lv = None):
ret = None
for ship in self.ships.values():
if ship.getName() == name:
if lv is not None and ship.lv == lv:
Log.i('Found ship %s of level %d, id: %d' % (name, ship.lv, ship.id))
return ship
if ret is None or ret.lv < ship.lv:
ret = ship
return ret
def getFleet(self, id_):
return self.fleets[id_ - 1]
def isDormFull(self):
return len(self.ships) >= self.maxShipNum
#.........这里部分代码省略.........
示例4: UserOAuth
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get [as 别名]
from useroauth import UserOAuth
from connection import Connection
oauth = UserOAuth("adaythere")
conn = Connection(oauth)
res = conn.get("/1.1/geo/search.json?query=Victoria")
print res.status
print res.read()
示例5: _TahoeFS
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get [as 别名]
class _TahoeFS(FS):
def __init__(self, dircap, autorun, largefilesize, webapi):
self.dircap = dircap if not dircap.endswith('/') else dircap[:-1]
self.autorun = autorun
self.largefilesize = largefilesize
self.connection = Connection(webapi)
self.tahoeutil = TahoeUtil(webapi)
self.readonly = dircap.startswith('URI:DIR2-RO')
super(_TahoeFS, self).__init__(thread_synchronize=_thread_synchronize_default)
def _log(self, level, message):
if not logger.isEnabledFor(level): return
logger.log(level, u'(%d) %s' % (id(self),
unicode(message).encode('ASCII', 'replace')))
def _fixpath(self, path):
return abspath(normpath(path))
def _get_file_handler(self, path):
if not self.autorun:
if path.lower().startswith('/autorun.'):
self._log(DEBUG, 'Access to file %s denied' % path)
return NullFile()
return self.getrange(path, 0)
@_fix_path
def getpathurl(self, path, allow_none=False, webapi=None):
'''
Retrieve URL where the file/directory is stored
'''
if webapi == None:
webapi = self.connection.webapi
self._log(DEBUG, "Retrieving URL for %s over %s" % (path, webapi))
path = self.tahoeutil.fixwinpath(path, False)
return u"%s/uri/%s%s" % (webapi, self.dircap, path)
@_fix_path
def getrange(self, path, offset, length=None):
path = self.tahoeutil.fixwinpath(path, False)
return self.connection.get(u'/uri/%s%s' % (self.dircap, path),
offset=offset, length=length)
@_fix_path
def setcontents(self, path, file, chunk_size=64*1024):
self._log(INFO, 'Uploading file %s' % path)
path = self.tahoeutil.fixwinpath(path, False)
size=None
if self.readonly:
raise errors.UnsupportedError('read only filesystem')
# Workaround for large files:
# First create zero file placeholder, then
# upload final content.
if self.largefilesize != None and getattr(file, 'read', None):
# As 'file' can be also a string, need to check,
# if 'file' looks like duck. Sorry, file.
file.seek(0, SEEK_END)
size = file.tell()
file.seek(0)
if size > self.largefilesize:
self.connection.put(u'/uri/%s%s' % (self.dircap, path),
"PyFilesystem.TahoeFS: Upload started, final size %d" % size)
self.connection.put(u'/uri/%s%s' % (self.dircap, path), file, size=size)
@_fix_path
def getinfo(self, path):
self._log(INFO, 'Reading meta for %s' % path)
info = self.tahoeutil.info(self.dircap, path)
#import datetime
#info['created_time'] = datetime.datetime.now()
#info['modified_time'] = datetime.datetime.now()
#info['accessed_time'] = datetime.datetime.now()
return info