本文整理汇总了Python中dispatcher.Dispatcher类的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher类的具体用法?Python Dispatcher怎么用?Python Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, clientManager, parent=None):
Dispatcher.__init__(self, clientManager, parent)
self.callbacks = {
Message.CMD_CLIENT_VALIDATED: self.loadResources,
Message.CMD_QUERY_VMS_OK: self.loadVms,
Message.CMD_UPDATE_VM_OK: self.handleUpdateVmOk,
Message.CMD_VM_START_OK: self.handleVmStartOk,
Message.CMD_VM_START_FAIL: self.handleVmStartFail,
Message.CMD_VM_UPDATED: self.updateVm,
Message.CMD_QUERY_GPS_OK: self.loadGps,
Message.CMD_ADD_GPS_OK: self.handleAddGpsOk,
Message.CMD_UPDATE_GPS_OK: self.handleUpdateGpsOk,
Message.CMD_GPS_UPDATED: self.updateGps,
Message.CMD_GPS_ADDED: self.loadGps,
Message.CMD_GPS_DELETED: self.deleteGps,
Message.CMD_DELETE_GPS_OK: self.handleDeleteGpsOk,
Message.CMD_ACCOUNT_ADDED: self.loadAccounts,
Message.CMD_QUERY_ACCOUNT: self.loadAccounts,
Message.CMD_QUERY_ACCOUNT_OK: self.loadAccounts,
Message.CMD_ADD_ACCOUNT_OK: self.handleAddAccountOk,
Message.CMD_DELETE_ACCOUNT_OK: self.handleDeleteAccountsOk,
Message.CMD_ACCOUNT_DELETED: self.deleteAccounts
}
示例2: __init__
def __init__(self, destaddr, output=None):
Dispatcher.__init__(self)
self.eventloop = EventLoop()
self.starttime = None
self.output = output
self.ready = True
self.max_ttl = 16
self.current_ttl = 16
self.min_ttl = 0
self.ident = -1
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
self.set_socket(sock)
except socket.error, err:
if _sockerror(err.args[0]) == 'EPERM':
logging.root.error('You need sudo privilages to use raw sockets')
else:
log_str = 'Socket Error: %s' % _sockerror(err.args[0])
logging.root.error(log_str)
sys.exit(-1)
示例3: __init__
def __init__(self):
self.width = 3
self.height = 3
Deferrer.__init__(self)
Dispatcher.__init__(self)
self.data = util.make2dArray(self.width, self.height, None)
self.curPlayer = 1
示例4: test_dispatches_correct_method
def test_dispatches_correct_method(self):
dispatcher = Dispatcher('func')
dispatcher.add_target(Pattern(lambda num: num % 2 == 0), lambda x: 'even')
dispatcher.add_target(Pattern(lambda num: num % 2 != 0), lambda x: 'odd')
self.assertEqual(dispatcher(2), 'even')
self.assertEqual(dispatcher(3), 'odd')
示例5: __init__
def __init__(self, server, parent=None):
Dispatcher.__init__(self, server, parent)
self.vm = VmManager()
self.vm.loadAllMachines()
#externalToVm --> {clientId: [(vmId, vmInfo),]}
self.externalToVm = {}
self.callbacks = {
Message.CMD_START_VM: self.startVM,
Message.CMD_CLOSE_VM: self.closeVM,
Message.CMD_RESET_VM: self.resetVM,
Message.CMD_QUERY_VMS: self.queryVms,
Message.CMD_QUERY_GPS: self.queryGPS,
Message.CMD_UPDATE_VM: self.updateVm,
Message.CMD_UPDATE_GPS: self.updateGps,
Message.CMD_ADD_GPS: self.addGps,
Message.CMD_DELETE_GPS: self.deleteGps,
Message.CMD_ADD_ACCOUNT: self.addAccount,
Message.CMD_QUERY_ACCOUNT: self.queryAccount,
Message.CMD_DELETE_ACCOUNT: self.deleteAccount,
}
self.server.clientDisconnected.connect(self.clearVmForClient)
EventManager.bind('DataCenter.gpsLoaded', self._sendGpsData)
EventManager.bind('DataCenter.gpsUpdated', self._updateGpsData)
EventManager.bind('DataCenter.gpsAdded', self._addGpsData)
EventManager.bind('DataCenter.gpsDeleted', self._deleteGpsData)
EventManager.bind('DataCenter.accountAdded', self._addAccountData)
EventManager.bind('DataCenter.accountLoaded', self._sendAccountData)
EventManager.bind('DataCenter.accountDeleted', self._deleteAccountData)
示例6: test_uses_default_if_no_match
def test_uses_default_if_no_match(self):
dispatcher = Dispatcher('func')
dispatcher.add_target(Pattern(5), lambda x: x*x)
dispatcher.add_default(lambda x: x*2)
self.assertEqual(dispatcher(5), 25)
self.assertEqual(dispatcher(3), 6)
示例7: lineReceived
def lineReceived(self, data):
"""Called to dispatch a fully-delimited CRLF command"""
try:
reqData = json.loads(data)
except:
return
if "request" in reqData:
Dispatcher.get().dispatchCommand(self, reqData)
示例8: __init__
def __init__(self, canvas, x, y, width, height, options={}):
Dispatcher.__init__(self)
self.obj_id = None
self.canvas = canvas
self.x = x
self.y = y
self.width = width
self.height = height
self.options = options
示例9: start
def start():
global dispatcher
if dispatcher.isAlive():
logging.warning("Cannot start dispatcher : Dispatcher is already running")
return "Cannot start dispatcher : Dispatcher is already running"
else:
dispatcher = Dispatcher(job_queue=job_queue)
dispatcher.start()
return "Dispatcher started... %s" % dispatcher
示例10: __init__
def __init__(self, connection):
Dispatcher.__init__(self, 3, SASL_FRAME)
self.connection = connection
self.mechanisms = None
self.mechanism = None
self.username = None
self.password = None
self.output_redirect = False
self.outcome = None
示例11: start_flask
def start_flask():
global job_queue
global dispatcher
# Create IN job queue & job dispatcher
job_queue = Queue()
#d = Dispatcher(job_queue=job_queue, log_queue=loggingqueue.queue) Process based logging
dispatcher = Dispatcher(job_queue=job_queue)
dispatcher.start()
app.run(debug=True, use_reloader=False)
示例12: run
def run(cityMap):
import copy
cityMap = copy.deepcopy(cityMap)
hospitalsOutput = cityMap.placeHospitals()
dispatcher = Dispatcher(cityMap)
ambulanceOutput = dispatcher.startDipatch()
output = hospitalsOutput + '\n' + ambulanceOutput
return output
示例13: __init__
def __init__(self, sockaddr=DEFAULT_ADDR):
asynchat.async_chat.__init__(self)
Dispatcher.__init__(self)
self._host, self._port = sockaddr
self._receiver_thread = None
self._receiver_thread_exiting = threading.Event()
self._receiver_thread_exited = False
self._ibuffer = ""
# IQfeed separates rows with newline
self.set_terminator("\r\n")
示例14: run
def run(self, driver=True, asynch=True):
disp = Dispatcher(self.eval_func, asynch)
while True:
if disp.run(): #jobs done
if driver:
if drive_optimization(population_size=self.population_size, dim=self.dim, lower_bounds=self.lower_bounds, upper_bounds=self.upper_bounds):
continue
# wait between 5 and 15 seconds to prevent several VMs from accessing GAE simultaneously
time.sleep(random.randrange(5, 15))
示例15: Client
class Client(NetStream, QtCore.QObject):
def __init__(self, headMode=8, serverIP="127.0.0.1", serverPort=4829, sleepInterval=0.1, parent=None):
NetStream.__init__(self, headMode)
QtCore.QObject.__init__(self)
print "Client Init ", serverIP, serverPort
self.initData(serverIP, serverPort, sleepInterval, parent)
self.setup()
self.parent.parent.connect(self, QtCore.SIGNAL("serverCrashedAlert()"), self.parent.parent.serverCrashedAlert)
def initData(self, serverIP, serverPort, sleepInterval, parent):
self.serverIP = serverIP
self.serverPort = serverPort
self.sleepInterval = sleepInterval
self.dispatcher = Dispatcher()
self.parent = parent
self.isAlive = True
self.hasBegan = False
def killClient(self):
self.isAlive = False
def setup(self):
self.setupDispatcher()
self.setupClient()
def setupDispatcher(self):
self.dispatcher.setParent(self)
services = {
1001: LoginService(self.dispatcher),
1002: HallService(self.dispatcher),
1003: RoomService(self.dispatcher),
}
self.dispatcher.registers(services)
def setupClient(self):
print self.serverPort, "\n", self.serverIP
self.connect(self.serverIP, self.serverPort)
self.nodelay(0)
self.nodelay(1)
def sendToServer(self, serviceID, commandID, data):
message = {}
message["create_time"] = time.time()
message["service_id"] = serviceID
message["command_id"] = commandID
message["data"] = data
try:
messageString = json.dumps(message)
except TypeError, e:
print "Error while dumping json"
print e
print message
print "Sending Messgae:", message
self.send(messageString)