本文整理汇总了Python中dispatcher.Dispatcher.dispatch方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.dispatch方法的具体用法?Python Dispatcher.dispatch怎么用?Python Dispatcher.dispatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dispatcher.Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.dispatch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_read
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import dispatch [as 别名]
def handle_read(self):
data = self.recv(4096)
if data is None:
return
else:
self.message += data
while True:
index = self.message.find(MessageMark.END_MARK)
if index != -1:
handle_part = self.message[:index]
# Handle message
Dispatcher.dispatch(self, handle_part)
self.message = self.message[index+len(MessageMark.END_MARK):]
else:
break
示例2: start
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import dispatch [as 别名]
def start(self):
self.load_procedures()
proc = Procedure.procedures[self.procedure]
assert proc, "cannot find the specified procedure: %s" % self.procedure
# command line vm list overrides procedures.yaml
if self.vm_names==[''] and proc.command_list and proc.command_list[0].name.startswith("VM"):
vm_command = proc.command_list.pop(0)
self.vm_names = vm_command.execute('server', None, vm_command.args)[1]
logging.info("VM override: %s" % self.vm_names)
assert self.vm_names, "No VM specified"
mq = MQStar(self.args.redis, self.args.session)
if self.args.clean:
logging.warn("cleaning mq")
mq.clean()
logging.info("mq session: %s" % mq.session)
dispatcher = Dispatcher(mq, self.vm_names)
dispatcher.dispatch(proc, pool = self.pool)
示例3: get
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import dispatch [as 别名]
def get(self):
response = "XML Data Get"
try:
xml_data = self.request.get('xml')
except:
xml_data = None
self.response.out.write("No XML Found")
else:
try:
c = Dispatcher()
response = c.dispatch(xml_data)
except:
response = "Error in dispatcher"
#response = "hello process request"
self.response.out.write(response)
示例4: join
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import dispatch [as 别名]
import os
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib'))
import settings
import irc
import log
from dispatcher import Dispatcher
def join(c,m):
for chan in settings.default_channels:
c.write("JOIN " + chan)
if __name__=="__main__":
connection = irc.Connection(
address=(settings.SERVER, settings.PORT),
nick=settings.NICK,
ident=settings.IDENT,
realname=settings.REALNAME)
connection.connect()
dispatcher = Dispatcher(connection)
dispatcher.register('003', join)
while True:
msg = irc.Message(connection.read())
dispatcher.dispatch(msg)
示例5: ServerTest
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import dispatch [as 别名]
class ServerTest(unittest.TestCase):
def setUp(self):
self._head1 = MsgCSLogin('test', 0)
self._head2 = MsgCSMoveto(3, 5)
self._dispatcher = Dispatcher()
self._dispatcher.register(100, TestService())
self.count = 0
def tearDown(self):
self._head1 = None
self._head2 = None
self._dispatcher = None
self.count = 0
def addCount(self):
self.count += 1
def test_Parser(self):
# test header
data = self._head1.marshal()
print "hello", data
head = MsgCSLogin().unmarshal(data)
self.assertEqual(self._head1.name, head.name)
self.assertEqual(self._head1.icon, head.icon)
data = self._head2.marshal()
print "world", data
head = MsgCSMoveto().unmarshal(data)
self.assertEqual(self._head2.x, head.x)
self.assertEqual(self._head2.y, head.y)
# test dispatcher
msg = MsgService()
msg.sid = 100
msg.cid = 10
self.assertEqual(self._dispatcher.dispatch(msg, 'client1'), 'client1')
msg.cid = 20
self.assertEqual(self._dispatcher.dispatch(msg, 'client2'), 'client2')
# test network
host = SimpleHost()
host.startup(2000)
sock = NetStream()
last = time.time()
sock.connect('127.0.0.1', 2000)
stat = 0
last = time.time()
sock.nodelay(1)
while 1:
time.sleep(0.1)
host.process()
sock.process()
if stat == 0:
if sock.status() == conf.NET_STATE_ESTABLISHED:
stat = 1
data = cPickle.dumps((stat, 'Hello, world !!'), -1)
sock.send(data)
last = time.time()
elif stat == 1:
if time.time() - last >= 2.0:
stat = 2
data = cPickle.dumps((stat, 'exit'), -1)
sock.send(data)
event, wparam, data = host.read()
if event < 0:
continue
if event == conf.NET_CONNECTION_DATA:
client_stat, message = cPickle.loads(data)
host.sendClient(wparam, 'RE: ' + message)
if client_stat == 1:
self.assertEqual(message, 'Hello, world !!')
elif client_stat == 2:
self.assertEqual(message, 'exit')
host.closeClient(wparam)
host.shutdown()
break
# test timer
TimerManager.addRepeatTimer(0.15, self.addCount)
last = time.time()
while 1:
time.sleep(0.01)
TimerManager.scheduler()
if time.time() - last > 1.0:
break
self.assertEqual(self.count, 6)
return