本文整理汇总了Python中bank.Bank.activate_cdkey方法的典型用法代码示例。如果您正苦于以下问题:Python Bank.activate_cdkey方法的具体用法?Python Bank.activate_cdkey怎么用?Python Bank.activate_cdkey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bank.Bank
的用法示例。
在下文中一共展示了Bank.activate_cdkey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BankNode
# 需要导入模块: from bank import Bank [as 别名]
# 或者: from bank.Bank import activate_cdkey [as 别名]
class BankNode(node.Node):
def __init__(self, nickname, port):
# over
super(BankNode, self).__init__(nickname,port,'bank')
thread.start_new_thread(self.node_main, ())
self.bank = Bank()
self.cl_list = []
self.addr_list = []
self.mylock = threading.RLock()
# method to activate the cdKey as the node requests
def onActivate(self, socket, addr, node, msg):
# activate the cdkey
self.mylock.acquire()
result = self.bank.activate_cdkey(msg['cdkey'])
# sleep for concurrent test
# time.sleep(5)
# if it is num
if not self.is_num(result):
socket.send(self.msg.answerActivate(balance=result))
# if it is not num, then error.
else:
socket.send(self.msg.answerActivate(info=result))
logging.info('%s'%result)
self.mylock.release()
# re-write the listen method maintaining queue for waiting
def listen(self):
while True:
logging.info('Listening...')
try:
logging.info(self)
client, addr = self._server.accept()
logging.info('connection from: %s:%d' % (addr[0], addr[1]))
self.cl_list.append(client)
self.addr_list.append(addr)
except KeyboardInterrupt:
break
# new method to handle the listener in queue by order
def node_main(self):
while True:
if self.cl_list and self.addr_list:
self.handle_client(self.cl_list[0], self.addr_list[0])
del(self.cl_list[0])
del (self.addr_list[0])
# Not Num : True; Num: False
def is_num(self, argv):
for i in range(len(argv)):
if not '0' <= argv[i] <= '9':
return True
return False