本文整理匯總了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