class BurpExtender(IBurpExtender): """ hiccupy """ def registerExtenderCallbacks(self, callbacks): self.mCallBacks = callbacks self.config = Config(callbacks) self.loader = Loader(self.config) self.dispatcher = Dispatcher(self.config, self.loader.getPlugins()) def processProxyMessage(self, messageReference, messageIsRequest, remoteHost, remotePort, serviceIsHttps, httpMethod, path, resourceType, statusCode, responseContentType, message, interceptAction): self.loader.reloadIfChanged() url = URL("HTTPS" if serviceIsHttps else "HTTP", remoteHost, remotePort, path) if self.mCallBacks.isInScope(url): if messageIsRequest: self.dispatcher.processProxyRequest( messageReference, messageIsRequest, remoteHost, remotePort, serviceIsHttps, httpMethod, path, resourceType, statusCode, responseContentType, message, interceptAction) else: self.dispatcher.processProxyResponse( messageReference, messageIsRequest, remoteHost, remotePort, serviceIsHttps, httpMethod, path, resourceType, statusCode, responseContentType, message, interceptAction) return message def processHttpMessage(self, toolName, messageIsRequest, message): if toolName == "intruder" and messageIsRequest: print "[%s] %s" % (toolName, message.getRequest())
class BurpExtender(IBurpExtender): """ hiccupy """ def registerExtenderCallbacks(self, callbacks): self.mCallBacks = callbacks self.config = Config(callbacks) self.loader = Loader(self.config) self.dispatcher = Dispatcher(self.config, self.loader.getPlugins()) def processProxyMessage(self, messageReference, messageIsRequest, remoteHost, remotePort, serviceIsHttps, httpMethod, path, resourceType, statusCode, responseContentType, message, interceptAction): self.loader.reloadIfChanged() url = URL("HTTPS" if serviceIsHttps else "HTTP", remoteHost, remotePort, path) if self.mCallBacks.isInScope(url): if messageIsRequest: self.dispatcher.processProxyRequest(messageReference, messageIsRequest, remoteHost, remotePort, serviceIsHttps, httpMethod, path, resourceType, statusCode, responseContentType, message, interceptAction) else: self.dispatcher.processProxyResponse(messageReference, messageIsRequest, remoteHost, remotePort, serviceIsHttps, httpMethod, path, resourceType, statusCode, responseContentType, message, interceptAction) return message def processHttpMessage(self, toolName, messageIsRequest, message): if toolName == "intruder" and messageIsRequest: print "[%s] %s" % (toolName, message.getRequest())
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 simulate_partial(self, rho, i, output: list, overheads: list, jbt, custom, seed): dispatcher = Dispatcher(self.number_of_tasks, self.number_of_servers, rho, self.d, seed, jbt=jbt, custom=custom) mean_sys_delay, overhead = dispatcher.execute_simulation() output.append((i, mean_sys_delay)) overheads.append((i, overhead))
def handle_connect(self): Dispatcher.handle_connect(self) try: fd = socket.socket(self.sock_family, self.sock_type) fd.connect(self.remote_address) self.fd = fd except socket.error as e: print("ERROR could not open socket %s, %s" % (e, self), file=sys.stderr)
class Client(netstream,QtCore.QObject): def __init__(self,headMode = 8,serverIP = '127.0.0.1',serverPort = 12345,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)
def __init__(self, pipelines=4): Dispatcher.__init__(self) self.Queue = Queue.PriorityQueue(-1) self.WaitingToQuit = False self.Workers = [] self.Lock = threading.Lock() self.Count = pipelines # indicates the number of available workers, used in IsFull() self.Log = open("dispatcher.log", "w") for i in range(pipelines): worker = threading.Thread(target=Worker, args=(self, i + 1)) worker.start() self.Workers.append(worker)
def __init__(self, logger, hardware, scheduler): # Logger self._logger = logger # Inicio el Hardware que me llega por parametros self._hardware = hardware # Software self._dispatcher = Dispatcher(self._hardware.cpu, self._hardware.mmu, self._hardware.timer) #para continuo # self._dispatcher = DispatcherPages(self._hardware.cpu, self._hardware.mmu, self._hardware.timer) #para paginacion self._scheduler = scheduler self._pcbTable = PCBTable() self._interruptVector = hardware.interruptVector self._interruptVector.setKernel(self) # IRQ # self._newIRQ = IRQ("NEW") self._killIRQ = IRQ("KILL") # self._ioInIRQ = IRQ("IO_IN") # self._ioOutIRQ = IRQ("IO_OUT") # self._timeOut = IRQ("TIME_OUT") # Por ahora interruptVector es un hibrido (Hard/Soft) #self._interruptVector.sekernel = self # Interrupt Handlers config self._interruptVector.register(self._killIRQ.type, KillHandler(self))
async def process_file(self, file_path): print('processing {}'.format(file_path)) listener_output = Listener.read_wav_file(file_path) print('Listening completed') dispatcher_output = Dispatcher.offline(listener_output, self.config) print('Dispatching completed') return dispatcher_output
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 __init__(self, sock_family, sock_type, bind_address, factory): Dispatcher.__init__(self) self.sock_family = sock_family self.sock_type = sock_type self.sock_type = sock_type self.bind_address = bind_address self.factory = factory if sock_family == socket.AF_UNIX: try: os.unlink(bind_address) except OSError: pass fd = socket.socket(self.sock_family, self.sock_type) fd.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) fd.bind(self.bind_address) fd.listen(5) self.fd = fd
def __init__(self): super(NodeGraphScene, self).__init__() #Keep a dictionary of nodes. self.nodeDict = {} #Register a dispatcher object to talk with other widgets. self.dispatcher = Dispatcher(self) self.signalMapperParam = QtCore.QSignalMapper(self) self.signalMapperView = QtCore.QSignalMapper(self) self.signalMapperView.mapped[str].connect(self.dispatcher.initViewer) self.signalMapperParam.mapped[str].connect(self.dispatcher.swapParams)
def __init__(self, sock_family, sock_type, remote_address, fd=None): Dispatcher.__init__(self, fd) self.sock_family = sock_family self.sock_type = sock_type self.remote_address = remote_address self.read_buffer = Buffer(4096) self.write_buffer = Buffer(4096) self.uid = None self.gids = set() # For AF_UNIX sockets find out the uid/gids of the caller. if self.fd is not None and self.sock_family == socket.AF_UNIX: self.uid = utils.get_peer_uid(fd) self.gids = utils.uid_gids.get(self.uid, []) # Connect if this is client side. if self.client: self.handle_connect() print("uid:", self.uid, self.gids)
def main(): #interface on which capture packets interface = input('interface: ') if len(interface) == 0: print('Not valid interface.') sys.exit() #own ip ipaddress = ni.ifaddresses(interface)[ni.AF_INET][0]['addr'] #-------------------------------------------------------------------------------------------# #two data structure used to analyze packets and store the flows global buff buff = Buffer() pkt_str = PacketsStr() #threads used to analyze the flows and their content dispatcher = Dispatcher(buff, pkt_str, ipaddress) scanner = PortScanner(pkt_str) visual = Visual(pkt_str) dispatcher.start() scanner.start() visual.start() #starting to sniff packets capture = sniff(filter='ip', session=IPSession, prn=traffic_handler, count=0, iface=interface) #at the and of the sniff, when Ctrl+C key is pressed, termination variable is set to notify threads dispatcher.term.set() scanner.term.set() visual.term.set() #to wake the threads which are waiting for new packets time.sleep(1) with buff._mutex: buff._mutex.notify() with pkt_str._lockPkts: pkt_str._lockPkts.notify() dispatcher.join() scanner.join() visual.join() #print some information about the number of unknown and known packets print("\nUnknown packets: %d" % len(pkt_str.unknown)) print("Packets of unknown process: %d" % len(pkt_str.unanalizedPkt)) print("Total packets: %d" % len(capture))
def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None: global announce, dispatcher, group, httpServer, notification, validator global registration, remote, security, statistics, storage, event global rootDirectory global aeStatistics rootDirectory = os.getcwd() # get the root directory os.environ[ "FLASK_ENV"] = "development" # get rid if the warning message from flask. # Hopefully it is clear at this point that this is not a production CSE # Handle command line arguments and load the configuration if args is None: args = argparse.Namespace( ) # In case args is None create a new args object and populate it args.configfile = None args.resetdb = False args.loglevel = None for key, value in kwargs.items(): args.__setattr__(key, value) if not Configuration.init(args): return # init Logging Logging.init() Logging.log('============') Logging.log('Starting CSE') Logging.log('CSE-Type: %s' % C.cseTypes[Configuration.get('cse.type')]) Logging.log(Configuration.print()) # Initiatlize the resource storage storage = Storage() # Initialize the event manager event = EventManager() # Initialize the statistics system statistics = Statistics() # Initialize the registration manager registration = RegistrationManager() # Initialize the resource validator validator = Validator() # Initialize the resource dispatcher dispatcher = Dispatcher() # Initialize the security manager security = SecurityManager() # Initialize the HTTP server httpServer = HttpServer() # Initialize the notification manager notification = NotificationManager() # Initialize the announcement manager announce = AnnouncementManager() # Initialize the group manager group = GroupManager() # Import a default set of resources, e.g. the CSE, first ACP or resource structure importer = Importer() if not importer.importResources(): return # Initialize the remote CSE manager remote = RemoteCSEManager() remote.start() # Start AEs startAppsDelayed( ) # the Apps are actually started after the CSE finished the startup # Start the HTTP server event.cseStartup() # type: ignore Logging.log('CSE started') httpServer.run() # This does NOT return
relaisPinClose = 27 ledPinRed = 23 ledPinGreen = 24 d11 = DHTSensor(dht11Pin, 'DHT11', True) d22 = DHTSensor(dht22Pin, 'DHT22', True) windowOpen = Relais(relaisPinOpen, 5) windowClose = Relais(relaisPinClose, 5) lcd = LCD() ledRed = LED(ledPinRed) ledGreen = LED(ledPinGreen) dispatcher = Dispatcher(d11, d22, ledRed, ledGreen, lcd, windowOpen, windowClose, True) #button = Button() #button.run() try: while True: dispatcher.main() time.sleep(delay) except KeyboardInterrupt: print "done" finally: lcd.lcd_byte(0x01, lcd.LCD_CMD) GPIO.cleanup()
def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None: global announce, dispatcher, group, httpServer, notification, validator global registration, remote, request, security, statistics, storage, event global rootDirectory global aeStatistics global supportedReleaseVersions, cseType, defaultSerialization, cseCsi, cseRi, cseRn global cseOriginator global isHeadless rootDirectory = os.getcwd() # get the root directory os.environ[ "FLASK_ENV"] = "development" # get rid if the warning message from flask. # Hopefully it is clear at this point that this is not a production CSE # Handle command line arguments and load the configuration if args is None: args = argparse.Namespace( ) # In case args is None create a new args object and populate it args.configfile = None args.resetdb = False args.loglevel = None args.headless = False for key, value in kwargs.items(): args.__setattr__(key, value) isHeadless = args.headless if not Configuration.init(args): return # Initialize configurable constants supportedReleaseVersions = Configuration.get( 'cse.supportedReleaseVersions') cseType = Configuration.get('cse.type') cseCsi = Configuration.get('cse.csi') cseRi = Configuration.get('cse.ri') cseRn = Configuration.get('cse.rn') cseOriginator = Configuration.get('cse.originator') defaultSerialization = Configuration.get('cse.defaultSerialization') # init Logging Logging.init() if not args.headless: Logging.console('Press ? for help') Logging.log('============') Logging.log('Starting CSE') Logging.log(f'CSE-Type: {cseType.name}') Logging.log('Configuration:') Logging.log(Configuration.print()) # Initiatlize the resource storage storage = Storage() # Initialize the event manager event = EventManager() # Initialize the statistics system statistics = Statistics() # Initialize the registration manager registration = RegistrationManager() # Initialize the resource validator validator = Validator() # Initialize the resource dispatcher dispatcher = Dispatcher() # Initialize the request manager request = RequestManager() # Initialize the security manager security = SecurityManager() # Initialize the HTTP server httpServer = HttpServer() # Initialize the notification manager notification = NotificationManager() # Initialize the group manager group = GroupManager() # Import a default set of resources, e.g. the CSE, first ACP or resource structure # Import extra attribute policies for specializations first importer = Importer() if not importer.importAttributePolicies() or not importer.importResources( ): return # Initialize the remote CSE manager remote = RemoteCSEManager() # Initialize the announcement manager announce = AnnouncementManager() # Start AEs startAppsDelayed( ) # the Apps are actually started after the CSE finished the startup # Start the HTTP server event.cseStartup() # type: ignore httpServer.run() # This does return (!) Logging.log('CSE started') if isHeadless: # when in headless mode give the CSE a moment (2s) to experience fatal errors before printing the start message BackgroundWorkerPool.newActor( delay=2, workerCallback=lambda: Logging.console('CSE started') if not shuttingDown else None).start() # # Enter an endless loop. # Execute keyboard commands in the keyboardHandler's loop() function. # commands = { '?': _keyHelp, 'h': _keyHelp, '\n': lambda c: print(), # 1 empty line '\x03': _keyShutdownCSE, # See handler below 'c': _keyConfiguration, 'C': _keyClearScreen, 'D': _keyDeleteResource, 'i': _keyInspectResource, 'l': _keyToggleLogging, 'Q': _keyShutdownCSE, # See handler below 'r': _keyCSERegistrations, 's': _keyStatistics, 't': _keyResourceTree, 'T': _keyChildResourceTree, 'w': _keyWorkers, } # Endless runtime loop. This handles key input & commands # The CSE's shutdown happens in one of the key handlers below loop(commands, catchKeyboardInterrupt=True, headless=args.headless) shutdown()
def main(mode, interface): if interface == 'net': comm = iinic.NetComm() else: comm = iinic.USBComm(interface) #comm = iinic.USBComm() if Config.ON_DEVICE else iinic.NetComm() nic = iinic.NIC(comm) frameLayer = FrameLayer(nic) myId = frameLayer.getMyId() print >> sys.stderr, 'NIC initialized. My id is', frameLayer.getMyId() dispatcher = Dispatcher(frameLayer) if mode == 'k': keepalive = KeepAlive() dispatcher.registerProto(keepalive, 'keepalive') dispatcher.loop() if mode == 'n': neighbourhood = Neighbourhood() dispatcher.registerProto(neighbourhood, 'neighbourhood') dispatcher.loop() if mode == 'd': sample = SampleProto() dispatcher.registerProto(sample, 'sample') pp = PingPongProto() dispatcher.registerProto(pp, 'ping-pong') try: dispatcher.registerProto(sample, 'sample') except: pass # yes, we expected you, Mr. Exception dispatcher.scheduleCallback(sample.sampleCallback, time.time()+1) dispatcher.scheduleCallback(sampleCallback, time.time()+2) dispatcher.scheduleRepeatingCallback(sampleCallback, time.time()+3, 10) dispatcher.loop() if mode == 'r': monitor = MonitorProto() dispatcher.registerProto(monitor, 'monitor') dispatcher.loop() if mode == 's': frameLayer.sendFrame('s', myId, 0, 'blah') approx = frameLayer.nic.get_approx_timing() # TODO: expose this method frameLayer.sendFrame('x', myId, 0, 'blah blah', approx + 2000000)
def __init__(self, main): self.main = main Dispatcher.__init__(self, udpfilter, PacketFilterBase)
# __BEGIN_LICENSE__ # Copyright (C) 2008-2010 United States Government as represented by # the Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # __END_LICENSE__ from Dispatcher import Dispatcher from SharedScheduler import scheduler import exampleConfig def publishMessage(): com.publish('%s:foo' % exampleConfig.PROTOCOL, 'bar') print 'published message' com = Dispatcher(moduleName='examplePublisher') com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT) scheduler.enterPeriodic(period=1.0, action=publishMessage) scheduler.runForever()
def main(): program = Program() cs_id = 0 random.seed() while True: try: filename = input("Program name: ") file = open(filename, 'r') break except FileNotFoundError: print("File not found!") program.number_of_processes = int(input("Number of processes: ")) tables.memory = int(input("Memory Size: ")) instructions = [] for line in file: if line == 'EXE': break elif 'Name: ' in line: program.name = line.split(' ', 1)[1].splitlines()[0] elif 'Total runtime: ' in line: program.runtime = int(line.split(': ')[1]) elif 'Memory: ' in line: program.memory = int(line.split(': ')[1]) elif line != '\n': current_line = line.split() if "CRITICAL BEGIN" in line: begin_idx = len(instructions) cs = CriticalSection(cs_id, begin_idx) program.critical_sections.append(cs) tables.critical_sections[cs.id] = cs instructions.append(Instruction("CRITICAL BEGIN", cs_id)) cs_id += 1 elif "CRITICAL END" in line: end_idx = len(instructions) for cs in program.critical_sections: if cs.id == cs_id - 1: cs.end_idx = end_idx instructions.append(Instruction("CRITICAL END", cs.id)) tables.critical_sections[cs.id].end_idx = end_idx break elif len(current_line) == 1: instructions.append(Instruction(current_line[0], 0)) else: instructions.append( Instruction(current_line[0], int(current_line[1]))) program.instructions = instructions missing_end_tags = 0 for cs in program.critical_sections: if cs.end_idx == -1: missing_end_tags += 1 if missing_end_tags > 0: print( f'{missing_end_tags} critical section(s) are missing \'CRITICAL END\' commands' ) exit() print(f'Program loaded: {program.name}({program.number_of_processes})') processes = [ Process(copy.deepcopy(program), pid) for pid in range(program.number_of_processes) ] print('Randomizing...') for process in processes: # random.shuffle(process.program.instructions) for instruction in\ (instruction for instruction in process.program.instructions if instruction.command == 'CALCULATE'): instruction.value = random.randint( math.floor(instruction.value / 2), instruction.value * 2) pcbs = [PCB(process) for process in processes] for pcb in pcbs: pcb.process.pcb = pcb for pcb in pcbs: print(f'------Process {pcb.process.pid}------') for instruction in pcb.process.program.instructions: print(f'{instruction.command}: {instruction.value}') print(f'---------------------') input('Press enter/return to start execution...') dispatcher = Dispatcher() scheduler = Scheduler(dispatcher) dispatcher.connect_scheduler(scheduler) scheduler.start() tables.PCBs = pcbs scheduler.pcb_lock.set() gui = ProcessGUI() gui.start() scheduler.run_thread.join()
def handleLine(sock, line): print 'got:', line def handleService(finder, serviceName, serviceEvent): print 'handling notification of service %s at event %s' % (serviceName, serviceEvent) if serviceName == exampleConfig.SERVER_ENDPOINT: com.connect(serviceEvent, connectHandler=handleConnect, lineHandler=handleLine) def handleStdin(sock, line): print 'you said:', line com = Dispatcher(moduleName='exampleClient') if exampleConfig.NOTIFY_ENDPOINT: com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT) if exampleConfig.USE_SERVICE_DISCOVERY: com.findServices(protoName=exampleConfig.PROTOCOL, serviceHandler=handleService) else: handleService(None, exampleConfig.SERVER_ENDPOINT, exampleConfig.SERVER_ENDPOINT) com.connect('console:', lineHandler=handleStdin) com.runForever()
from Dispatcher import Dispatcher from CalculationUnit import CalculationUnit from MyProcess import MyProcess from Table import Table dispatcher = Dispatcher() unite1 = CalculationUnit("127.0.0.1", 4898) #unite2 = CalculationUnit("127.0.0.1", 4899) processMultiplyArray = MyProcess() unite1.attach_process(processMultiplyArray) #unite2.attach_process(processMultiplyArray) # unite2 = CalculationUnit("192.168.1.12", 4898) # unite1.attach_process(processMultiplyArray) dispatcher.add_calculation_unit(unite1) #dispatcher.add_calculation_unit(unite2) def endTask(resultat): print(resultat.to_string()) t1 = Table(1, 64) for i in range(0, 64): t1.append(i) if dispatcher.prepare(): print("YES") dispatcher.distribute_data(t1)
class NodeGraphScene(QtGui.QGraphicsScene): ''' ''' def __init__(self): super(NodeGraphScene, self).__init__() #Keep a dictionary of nodes. self.nodeDict = {} #Register a dispatcher object to talk with other widgets. self.dispatcher = Dispatcher(self) self.signalMapperParam = QtCore.QSignalMapper(self) self.signalMapperView = QtCore.QSignalMapper(self) self.signalMapperView.mapped[str].connect(self.dispatcher.initViewer) self.signalMapperParam.mapped[str].connect(self.dispatcher.swapParams) def adjustSceneRect(self): itemsRect = self.itemsBoundingRect() itemsRect.adjust(20, 20, 20, 20) return itemsRect #self.setSceneRect(itemsRect) @QtCore.Slot(str) def sendUpdate(self, changedNode): self.dispatcher.updateQ(changedNode) def addNode(self, pos=(50, 50), name=NODE_DEFAULT_NAME): #Create node obj newNode = Node(name=name) newNode.setPos(pos[0], pos[1]) newNode.update() #Add to scene self.addItem(newNode) self.nodeDict[name] = weakref.ref(newNode) #Reigster params with dispatcher self.dispatcher.registerParams(name, newNode.params) #Connect switches with signalmapper self.signalMapperParam.setMapping(newNode.editSwitch.switchObj, unicode(name)) self.signalMapperView.setMapping(newNode.viewSwitch.switchObj, unicode(name)) newNode.editSwitch.switchObj.toggleSignal.connect(self.signalMapperParam.map) newNode.viewSwitch.switchObj.toggleSignal.connect(self.signalMapperView.map) #Connect paramchanged with DAG update newNode.nodeObj.paramChSignal.connect(self.sendUpdate) #self.adjustSceneRect() return newNode def addEdge(self, outPort, inPort): '''Connect two nodes with an edge.''' #TODO - make this not stupid if outPort in self.items() \ and inPort in self.items(): newEdge = Edge() self.addItem(newEdge) newEdge.outPort = weakref.ref(outPort) newEdge.inPort = weakref.ref(inPort) outPort.connectedEdges.append(weakref.ref(newEdge)) inPort.connectedEdges.append(weakref.ref(newEdge)) newEdge.adjust() return newEdge else: raise ValueError("Port not found.") def deleteNodes(self, nodeList=[]): print nodeList self.detachNodes(nodeList) for node in nodeList: print node if node in self.nodeDict.keys(): self.removeItem(self.nodeDict[node]()) del self.nodeDict[node] def detachNodes(self, nodeList=[]): for node in nodeList: if node in self.nodeDict.keys(): for port in self.nodeDict[node]().portIter(): if len(port.connectedEdges): for edge in port.connectedEdges: self.removeItem(edge()) port.connectedEdges = [] else: raise ValueError("Node not found: " + node.name) def clearScene(self): self.deleteNodes(self.nodeDict.keys()) def loadFromJSON(self, jsonStr): #pp(json.loads(jsonStr)) loadedNodes = [] for name, node in json.loads(jsonStr).iteritems(): newNode = self.addNode(name=name, pos=node["pos"]) for port in node["ports"]: for edge in port["connected"]: try: outNode = self.nodeDict[edge["out"]["node"]] inNode = self.nodeDict[edge["in"]["node"]] outPort = outNode().port(edge["out"]["port"]) inPort = inNode().port(edge["in"]["port"]) except KeyError: print "Node not found, no edge created." continue self.addEdge(outPort, inPort) loadedNodes.append(newNode) return loadedNodes def asJSON(self, nodes=[]): if not nodes: nodes = self.nodeDict.keys() nodesDict = {} for node in nodes: nodesDict[node] = self.nodeDict[node]().asDict() return json.dumps(nodesDict, sort_keys=True, indent=4, separators=(',', ': ')) @QtCore.Slot() def editSelNodes(self): for node in self.selectedItems(): node.editSwitch.toggle() @QtCore.Slot() def viewSelNodes(self): for node in self.selectedItems(): node.viewSwitch.toggle() @QtCore.Slot() def extractNode(self): self.detachNodes(self.selectedItems()) @QtCore.Slot() def ignoreNode(self): for node in self.selectedItems(): node.toggleIgnored()
def registerExtenderCallbacks(self, callbacks): self.mCallBacks = callbacks self.config = Config(callbacks) self.loader = Loader(self.config) self.dispatcher = Dispatcher(self.config, self.loader.getPlugins())
def __init__(self): Dispatcher.__init__(self)
class NodeGraphScene(QtGui.QGraphicsScene): ''' ''' def __init__(self): super(NodeGraphScene, self).__init__() #Keep a dictionary of nodes. self.nodeDict = {} #Register a dispatcher object to talk with other widgets. self.dispatcher = Dispatcher(self) self.signalMapperParam = QtCore.QSignalMapper(self) self.signalMapperView = QtCore.QSignalMapper(self) self.signalMapperView.mapped[str].connect(self.dispatcher.initViewer) self.signalMapperParam.mapped[str].connect(self.dispatcher.swapParams) #SR = self.sceneRect() #SR.adjust(500, 500, 500, 500) #self.setSceneRect(SR) @QtCore.Slot(str) def sendUpdate(self, changedNode): self.dispatcher.updateQ(changedNode) def addNode(self, pos=(50, 50), name=NODE_DEFAULT_NAME): #Create node obj newNode = Node(name=name) newNode.setPos(pos[0], pos[1]) newNode.update() #Add to scene self.addItem(newNode) self.nodeDict[name] = weakref.ref(newNode) #Reigster params with dispatcher self.dispatcher.registerParams(name, newNode.params) #Connect switches with signalmapper self.signalMapperParam.setMapping(newNode.editSwitch.switchObj, unicode(name)) self.signalMapperView.setMapping(newNode.viewSwitch.switchObj, unicode(name)) newNode.editSwitch.switchObj.toggleSignal.connect(self.signalMapperParam.map) newNode.viewSwitch.switchObj.toggleSignal.connect(self.signalMapperView.map) #Connect paramchanged with DAG update newNode.nodeObj.paramChSignal.connect(self.sendUpdate) return newNode def addEdge(self, outPort, inPort): '''Connect two nodes with an edge.''' #TODO - make this not stupid if outPort in self.items() \ and inPort in self.items(): newEdge = Edge() self.addItem(newEdge) newEdge.outPort = weakref.ref(outPort) newEdge.inPort = weakref.ref(inPort) outPort.connectedEdges.append(weakref.ref(newEdge)) inPort.connectedEdges.append(weakref.ref(newEdge)) newEdge.adjust() return newEdge else: raise ValueError("Port not found.") def deleteNodes(self, nodeList=[]): self.detachNodes(nodeList) for node in nodeList: if node in self.items(): self.removeItem(node) del self.nodeDict[node.name] def detachNodes(self, nodeList=[]): for node in nodeList: if node in self.items(): for port in node.portIter(): if len(port.connectedEdges): for edge in port.connectedEdges: self.removeItem(edge()) port.connectedEdges = [] else: raise ValueError("Node not found: " + node) def clearScene(self): self.deleteNodes(self.nodeDict.items()) @QtCore.Slot() def editSelNodes(self): for node in self.selectedItems(): node.editSwitch.toggle() @QtCore.Slot() def viewSelNodes(self): for node in self.selectedItems(): node.viewSwitch.toggle() @QtCore.Slot() def extractNode(self): self.detachNodes(self.selectedItems()) @QtCore.Slot() def ignoreNode(self): for node in self.selectedItems(): node.toggleIgnored()
class Client(netstream, QtCore.QObject): def __init__(self, headMode=8, serverIP='127.0.0.1', serverPort=12345, 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)
socket.setdefaulttimeout(5) web_addr = urlopen('http://automation.whatismyip.com/n09230945.asp').read() socket.setdefaulttimeout(timeout) _root.console_write(web_addr) except: web_addr = local_addr _root.console_write('not online') _root.console_write() _root.local_ip = local_addr _root.online_ip = web_addr _root.console_write('Listening for clients on port %i'%port) _root.console_write('Using %i client handling thread(s).'%_root.max_threads) dispatcher = Dispatcher(_root, server) _root.dispatcher = dispatcher chanserv = True if chanserv: address = ((web_addr or local_addr), 0) chanserv = ChanServ.ChanServClient(_root, address, _root.session_id) dispatcher.addClient(chanserv) _root.chanserv = chanserv try: dispatcher.pump() except KeyboardInterrupt: _root.console_write() _root.console_write('Server killed by keyboard interrupt.') except:
# __BEGIN_LICENSE__ # Copyright (C) 2008-2010 United States Government as represented by # the Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # __END_LICENSE__ from Dispatcher import Dispatcher import exampleConfig def handleConnect(sock): print 'got connection' def handleLine(sock, line): print 'got:', line sock.write('ciao\n') com = Dispatcher(moduleName='exampleServer') if exampleConfig.NOTIFY_ENDPOINT: com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT) com.listen(exampleConfig.SERVER_ENDPOINT, connectHandler=handleConnect, lineHandler=handleLine) if exampleConfig.USE_SERVICE_DISCOVERY: com.findServices(protoName=exampleConfig.PROTOCOL, announceServices=[exampleConfig.SERVER_ENDPOINT]) com.runForever()
def Listner(Host, Port, SSL, QueueName, ExchangeName, ConfigPaths): #Choosing between normal connection to secure connection if SSL: connection = pika.BlockingConnection( pika.ConnectionParameters(Host, Port, ssl=True, ssl_options=SSL)) else: connection = pika.BlockingConnection( pika.ConnectionParameters(Host, Port)) channel = connection.channel() disp = Dispatcher(ConfigPaths) #Loading Algorithms configurations disp.loadAlgorithms(ConfigPaths['prefix'] + ConfigPaths['ConfigAlgorithms'] + '/Algorithms.yml') #Loading Commands configurations disp.loadCommands(ConfigPaths['prefix'] + ConfigPaths['ConfigAlgorithms'] + '/Commands.json') channel.exchange_declare(exchange=ExchangeName, durable=True) channel.queue_declare(queue=QueueName) channel.queue_bind(exchange=ExchangeName, queue=QueueName) channel.exchange_declare(exchange='rpc_queue') channel.queue_declare(queue='rpc_queue') channel.queue_bind(exchange='rpc_queue', queue='rpc_queue') print(' [*] Waiting for messages. To exit press CTRL+C') #Method for NO-RPC call def callback(ch, method, properties, body): text = body.decode(encoding="utf-8", errors="strict") print(text) if (text == 'Hello World!') or (text == 'hello'): ch.basic_ack(delivery_tag=method.delivery_tag) return Stringio = StringIO(body) data = json.load(Stringio) if data['Command'] == disp.getCommand('Add Participant'): print('Add-Participant') print(disp.addParticipant(data['Participant'])) print('Everything OK') if data['Command'] == disp.getCommand('Insert Event'): print('Add-Compute') global ids data['Event']['ID'] = str(ids) ids = ids + 1 eve = disp.insertEvent(data['Participant'], data['Event']) if not eve: print("Somenthing wrong!!") else: print("EventID:" + str(eve[0])) disp.compute(data['Participant'], eve) print(" [x] Done!") ch.basic_ack(delivery_tag=method.delivery_tag) #Method for RPC CALL def on_request(ch, method, props, body): try: text = body.decode(encoding="utf-8", errors="strict") #parsing data Stringio = StringIO(text) data = json.load(Stringio) #print(data) if data['Command'] == disp.getCommand('Add Participant'): print('Add Participant') ret = disp.addParticipant(data['Participant']) if ret: response = 'ACK From Add Participant' else: response = 'NACK From Add Participant' if data['Command'] == disp.getCommand('Insert Event'): print('Insert Event') global ids data['Event']['ID'] = str( ids) + '_' + data['TimeStamp'] + '_' + data['Participant'] ids = ids + 1 eve = disp.insertEvent(data['Participant'], data['Event']) if not eve: response = 'NACK From Insert Event' else: print("EventID:" + str(eve[0])) response = 'ID:' + str(eve[0]) disp.compute(data['Participant'], eve) if data['Command'] == disp.getCommand('List Event'): response = '' for event in disp.getAllEventFromParticipant( data['Participant']): #print(event) printevent = event.getPrintEvent() response = response + str(printevent) + '\n' if response == '': response = 'Nothing to show From List Event' if data['Command'] == disp.getCommand('Delete Event'): ret = disp.deleteEvent(data['Participant'], data['ID']) if ret: response = 'ACK From List Event' else: response = 'NACK From List Event' if data['Command'] == disp.getCommand('Delete Password'): ret = disp.deletePassword(data['Participant'], data['Event']['HashPassword']) if ret: response = 'ACK From Delete Password' else: response = 'NACK Frome Delete Password' if data['Command'] == disp.getCommand('Delete WebSite'): disp.deleteWebsite(data['Participant'], data['Event']['Website']) if data['Command'] == disp.getCommand('Delete All Event'): ret = True for event in disp.getAllEventFromParticipant( data['Participant']): #print(event) ret = ret and disp.deleteEvent(data['Participant'], event.data['ID']) if ret: response = 'ACK From All Event' else: response = 'NACK From All Event' if data['Command'] == disp.getCommand('Delete Participant'): ret = disp.deleteParticipant(data['Participant']) if ret: response = 'ACK From Delete Participant' else: response = 'NACK From Delete Participant' #sending response ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties( correlation_id=props.correlation_id), body=response) ch.basic_ack(delivery_tag=method.delivery_tag) print(response) except: traceback.print_exc(file=sys.stdout) ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties( correlation_id=props.correlation_id), body='ERROR SOMETHING GOES WRONG!') ch.basic_ack(delivery_tag=method.delivery_tag) channel.basic_qos(prefetch_count=1) channel.basic_consume(on_request, queue='rpc_queue') channel.start_consuming()
Logger() parser = optparse.OptionParser() parser.add_option('-C', '--city', action='store', dest='city', help='set city') parser.add_option('-c', '--community_spider', action='store_true', dest='community_spider', help='enable spider of all community') parser.add_option('-d', '--deal_spider', action='store_true', dest='deal_spider', help='enable spider of deal') parser.add_option('-H', '--house_spider', action='store_true', dest='house_spider', help='enable spider of house') parser.add_option('-a', '--analyze_deal', action='store_true', dest='analyze_deal', help='enable analyze deal') parser.add_option('-m', '--music', action='store', dest='music', help='play music when end') parser.add_option('-P', '--post_handle', action='store_true', dest='post_handle', help='enable post handle') parser.add_option('-t', '--test', action='store_true', dest='test', help='enable test') parser.add_option('-b', '--book', action='store_true', dest='book', help='enable book') parser.add_option('-n', '--new_community', action='store_true', dest='new_community', help='enable new_community') parser.add_option('-T', '--tag', action='store', dest='tag', help='tag') options, args = parser.parse_args() dispatcher = Dispatcher(options.tag or '') dispatcher.set_network_service(NetworkService()) if options.city: cities = options.city.split() else: cities = ('cd', ) if options.community_spider: logging.info('using community spider') for city in cities: community(dispatcher, city) if options.house_spider: logging.info('using house spider') for city in cities: house(dispatcher, city) if options.deal_spider:
from Dispatcher import Dispatcher import datetime as dt from Exchanges.Coinbase import Coinbase from config import Users, ExchangeConfig from config import NotificationConfig as ntfc import time, sys dispatcher = Dispatcher() coinbase = Coinbase('cb', ExchangeConfig.coinbase['currency']) exchanges = [coinbase] default_countdown = int(sys.argv[1]) if len(sys.argv) > 1 else 60 trigger_reset = 15 highest_triggered = None lowest_triggered = None sec_cd = 60 def main_loop(sec_cd): sec_cd -= 1 global default_countdown if sec_cd <= 0: sec_cd = 60 hour_now = dt.datetime.now().hour if hour_now >= ntfc.default_sleep[ 'end'] and hour_now <= ntfc.default_sleep['begin']: default_countdown -= 1 else: default_countdown = 1 update() sys.stdout.write("\r{scd}|Next default msg in {cd} min ".format(
def handleConnect(sock): writeText(sock) scheduler.enterPeriodic(period=2.0, action=lambda: writeText(sock)) def handleLine(sock, line): print 'got:', line def handleService(finder, serviceName, serviceEvent): print 'handling notification of service %s at event %s' % (serviceName, serviceEvent) if serviceName == exampleConfig.SERVER_ENDPOINT: com.connect(serviceEvent, connectHandler=handleConnect, lineHandler=handleLine) def handleStdin(sock, line): print 'you said:', line com = Dispatcher(moduleName='exampleClient') if exampleConfig.NOTIFY_ENDPOINT: com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT) if exampleConfig.USE_SERVICE_DISCOVERY: com.findServices(protoName=exampleConfig.PROTOCOL, serviceHandler=handleService) else: handleService(None, exampleConfig.SERVER_ENDPOINT, exampleConfig.SERVER_ENDPOINT) com.connect('console:', lineHandler=handleStdin) com.runForever()
def __init__(self, id): Dispatcher.__init__(self) self.id = id
# __BEGIN_LICENSE__ # Copyright (C) 2008-2010 United States Government as represented by # the Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # __END_LICENSE__ from Dispatcher import Dispatcher from SharedScheduler import scheduler import exampleConfig def fooHandler(name, data): print 'got "%s" "%s"' % (name, data) com = Dispatcher(moduleName='exampleSubscriber') com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT) com.subscribe('%s:foo' % exampleConfig.PROTOCOL, fooHandler) scheduler.runForever()