def run(self): # TODO: Make MessageReceiver receive and handle payloads parser = MessageParser() while True: package = self.connection.recv(4096) if package: parser.parse(package)
def handle(self): """ This method handles the connection between a client and the server. """ self.ip = self.client_address[0] self.port = self.client_address[1] self.connection = self.request # Init self.messageEncoder = MessageEncoder() self.messageParser = MessageParser() # Loop that listens for messages from the client while True: received_string = self.connection.recv(4096).decode() if received_string == "": self.connection.close() del connected_clients[self.connection] break else: payload = self.messageParser.parse(received_string) if 'login' in payload.keys(): if re.match("^[A-Za-z0-9_-]*$", payload['login']): self.connection.send( self.messageEncoder.encode_history( history).encode()) connected_clients[self.connection] = payload['login'] else: self.connection.send( self.messageEncoder.encode_error( "Invalid username").encode()) elif 'logout' in payload.keys(): self.connection.close() del connected_clients[self.connection] return elif 'message' in payload.keys(): message = self.messageEncoder.encode_message( connected_clients[self.connection], payload['message']) history.append(message) for conn in connected_clients.keys(): conn.send(message.encode()) elif 'names' in payload.keys(): self.connection.send( self.messageEncoder.encode_info(', '.join( connected_clients.values())).encode()) elif 'help' in payload.keys(): self.connection.send( self.messageEncoder.encode_info( "This is the help").encode())
def main(): try: print("Starting the SenseHat module...") global DISPLAY_MANAGER global MESSAGE_PARSER DISPLAY_MANAGER = DisplayManager() MESSAGE_PARSER = MessageParser() hubManager = HubManager() while True: time.sleep(1000) except IoTHubError as iothub_error: print("Unexpected error %s from IoTHub" % iothub_error) return except KeyboardInterrupt: print("IoTHubClient sample stopped")
def generate(requirements, fix_spec): requiredFieldsComponents = RequiredFieldsComponents.RequiredFieldsComponents( requirements) fix_specs = xml_parser.parse(fix_spec) component_parser = ComponentParser.ComponentParser( requiredFieldsComponents) message_parser = MessageParser.MessageParser(requiredFieldsComponents, component_parser) header_list_comp = [] header_messages = dict() required_header_fields = [] print("----- Processing Required Fields for QuickFIX Components -----") component_parser.parse_components(fix_specs) print("--------------------------------------------------------------\n") print("----- Processing Required Fields for QuickFIX Header -----") header_out = component_parser.parse_components_rec( 'Header', fix_specs.find('header'), header_messages, header_list_comp, required_header_fields, False) component_dependency_dictionary = component_parser.component_dep_dict # this list is required to populate dependecies for MPC to work print("--------------------------------------------------------------\n") print("----- Processing Required Fields for QuickFIX Message -----") message_parser.parse_messages(fix_specs, component_dependency_dictionary) print("--------------------------------------------------------------\n") component_parser.compenent_dict["Header"] = header_out component_parser.complete_dependency_list.append("Header") component_parser.component_dep_dict["Header"] = [] message_parser.store_message() component_parser.store_components()
import os import io import MessageParser from MessageParser import MessageParser # Imports for the REST API from flask import Flask, request # Imports for image procesing from PIL import Image # Imports for prediction from predict import initialize, predict_image, predict_url THRESHOLD = float(os.getenv('THRESHOLD', 0)) MESSAGE_PARSER = MessageParser() file = open('/tmp/predictions/p.txt', 'w') app = Flask(__name__) # 4MB Max image size limit app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024 # Default route just shows simple text @app.route('/') def index(): return 'CustomVision.ai model host harness' # Like the CustomVision.ai Prediction service /image route handles either # - octet-stream image file # - a multipart/form-data with files in the imageData parameter
def __init__(self, sock): self.sock = sock self.parser = MessageParser()