本文整理汇总了Python中connection.Connection.post方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.post方法的具体用法?Python Connection.post怎么用?Python Connection.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.post方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import post [as 别名]
#.........这里部分代码省略.........
def isDormFull(self):
return len(self.ships) >= self.maxShipNum
def addShip(self, ship):
self.ships[ship.id] = ship
def addResource(self, res):
pass # TODO
def removeShip(self, ship):
del self.ships[ship.id]
# Ship
def repair(self, ship, repairYard):
data = self.conn.get('/boat/repair/%d/%d/' % (ship.id, repairYard.id))
for ryData in data['repairDockVo']:
if int(ryData['id']) == repairYard.id:
return datetime.fromtimestamp(int(ryData['endTime']))
def repairComplete(self, repairYard):
self.conn.get('/boat/repairComplete/%d/%d/' % (repairYard.id, repairYard.ship.id))
def instantRepair(self, ship):
self.conn.get('/boat/instantRepairShips/[%d]/' % ship.id)
def dismantleShip(self, ship, keepEquipt = True):
self.conn.get('/dock/dismantleBoat/[%d]/%d/' % (ship.id, (0 if keepEquipt else 1)))
# Fleet
def changeShips(self, fleet, ships):
ships = [ ship.id for ship in ships ]
ships = str(ships).replace(' ', '')
self.conn.get('/boat/instantFleet/%d/%s/' % (fleet.id, ships))
def changeShip(self, fleet, pos, ship):
self.conn.get('/boat/changeBoat/%d/%d/%d/' % (fleet.id, ship.id, pos))
def fill(self, fleet):
ships = [ ship.id for ship in fleet.ships ]
ships = str(ships).replace(' ', '')
self.conn.get('/boat/supplyBoats/%s/' % ships)
# Expedition
def startExpedition(self, exp, fleet):
data = self.conn.post('/explore/start/%d/%d/' % (fleet.id, exp.id), 'pve_level=1')
for expData in data['pveExploreVo']['levels']:
if int(expData['exploreId']) == exp.id:
return datetime.fromtimestamp(int(expData['endTime']))
Log.e('startExpedition: unexpected response')
def getExpeditionResult(self, exp):
data = self.conn.get('/explore/getResult/%d/' % exp.id)
return (int(data['bigSuccess']) == 1), self.packer.makeResource(data['newAward'])
# Battle
def startStage(self, stageId, fleet):
self.conn.post('/pve/challenge/%d/%d/0/' % (stageId, fleet.id), 'pve_level=1')
def quitStage(self):
# faking official client
self.conn.get('/active/getUserData/')
self.conn.get('/pve/getUserData/')
self.conn.get('/campaign/getUserData/')
def nextSpot(self):
data = self.conn.get('/pve/next/')
return int(data['node'])
def searchEnemy(self, spot):
data = self.conn.get('/pve/spy/')
if int(data['enemyVO']['isFound']) == 0:
return [ ]
return [ int(ship['type']) for ship in data['enemyVO']['enemyShips'] ]
def startBattle(self, spot, fleet, formation):
data = self.conn.get('/pve/deal/%d/%d/%d/' % (spot, fleet.id, formation))
selfHp = data['warReport']['hpBeforeNightWarSelf']
enemyHp = data['warReport']['hpBeforeNightWarEnemy']
lastSpot = (int(data['pveLevelEnd']) == 1)
return selfHp, enemyHp, lastSpot
def getBattleResult(self, doNightBattle):
data = self.conn.get('/pve/getWarResult/%d/' % (1 if doNightBattle else 0))
newShip = None
if 'newShipVO' in data:
newShip = self.packer.makeShip(data['newShipVO'][0])
ships = None
if type(data['shipVO']) is list:
ships = [ self.packer.makeShip(shipData) for shipData in data['shipVO'] ]
else:
ships = [ self.packer.makeShip(data['shipVO']) ]
return newShip, ships
示例2: StateClient
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import post [as 别名]
class StateClient(threading.Thread):
def __init__(self, ownId, ownName=None, host=None, port=None):
self.api_version="v2"
print ownId, ownName, host, port
self.eventq = []
self.eventqc = threading.Condition()
self.ownid = ownId
if ownName == None:
self.devName = 'default'
else:
self.devname = ownName
if host == None:
host = 'kurre.soberit.hut.fi'
if port == None:
port = '80'
self.kurreClient = Connection(host, port)
self.prefix = '/api/v2/device/'
self.running=False
self.micThread = soundLvl.SoundLvl()
self.calThread = calSource.CalSource()
self.calThread.init(self)
self.micThread.init(self)
self.add_state_event( 'TalkingDevice', 'isWilling', 'True' )
threading.Thread.__init__(self)
self.setDaemon(True)
def set_printer(self, printer):
self.kurreClient.set_printer(printer)
self.printer = printer
def add_state_event(self, iface, method, value, arg_name=None, arg_val=None):
#print 'add state event called, params:', iface, method, value, arg_name, arg_val
self.eventqc.acquire()
#form the method path
method_path = self.ownid + '/interface/' + iface + '/method/' + method
if arg_name == None:
new_event = { "method": "PUT", "method_path": method_path, 'data': {'value':value} }
else:
new_event = { "method": "PUT", "method_path": method_path, 'data': {'value':value, 'arguments':{arg_name: arg_val}} }
if new_event in self.eventq:
pass
else:
self.eventq.append( new_event )
self.eventqc.notify()
self.eventqc.release()
def run(self):
self.running = True
self.calThread.start()
self.micThread.start()
while self.running:
#check for items in q
self.eventqc.acquire()
#print self.eventq
for event in self.eventq:
print 'processing event:', event
#post for update, put for create
if event['method'] == "PUT":
repl_status = self.kurreClient.put( self.prefix + event["method_path"] + '/', event["data"] )
elif event['method'] == "POST":
repl_status = self.kurreClient.post( self.prefix + event["method_path"] + '/', event["data"] )
#print 'repl status', repl_status
if isinstance(repl_status, Exception):
print repl_status
elif repl_status != 201 and repl_status != 204:
apip_struct = event['method_path'].split('/')
if len(apip_struct) == 5: # we were making a state value update
method_name = apip_struct.pop()
method_path = '/'.join(apip_struct)
event['data']['method_name'] = method_name
event['method'] = "POST"
event['method_path'] = method_path
#print 'put failed, modified event added', event
# no need to update again with put, since creation updates value as well
elif len(apip_struct) == 4: # state value creation failed
# create the interface
iface_name = apip_struct[2]
method_path = self.ownid + '/interface'
data = {"interface_name": iface_name}
#.........这里部分代码省略.........
示例3: UserOAuth
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import post [as 别名]
from useroauth import UserOAuth
from connection import Connection
oauth = UserOAuth("test")
conn = Connection(oauth)
res = conn.post("/1/statuses/update.json?include_entities=true", "status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21")