def __init__(self, message_handler=None, settings=None, message_template=None, message_xml=None): self.context = None self.unpacker = DataUnpacker() self.current_template = None self.current_block = None self.template_dict = TemplateDictionary( message_template=message_template) # allow the settings to be passed in # otherwise, grab the defaults if settings != None: self.settings = settings else: self.settings = Settings() if not message_xml: self.message_xml = MessageDotXML() else: self.message_xml = message_xml # we can skip parsing all the data in a packet if we know it's not being handled # allow the packet_handler to be passed in # otherwise, grab the defaults if message_handler != None: self.message_handler = message_handler elif self.settings.HANDLE_PACKETS: self.message_handler = MessageHandler()
def setUp(self): self.settings = Settings() self.settings.ENABLE_DEFERRED_PACKET_PARSING = False self.udp_connection = UDPDispatcher(MockupUDPClient(), settings=self.settings) self.host = Host((MockupUDPServer(), 80))
def __init__(self, udp_client = None, settings = None, message_handler = None, message_template = None, message_xml = None): #holds the details of the message, or how the messages should be sent, #built, and read self.packets_in = 0 self.packets_out = 0 self.circuit_manager = CircuitManager() self.data_unpacker = DataUnpacker() #the ID of the packet we most recently received self.receive_packet_id = -1 if udp_client == None: self.udp_client = NetUDPClient() else: self.udp_client = udp_client self.udp_client.start_udp_connection() # allow the settings to be passed in # otherwise, grab the defaults if settings != None: self.settings = settings else: self.settings = Settings() # allow the passing in of message_template.xml as a file handle if not message_template: self.message_template = None else: if isinstance(message_template, file): self.message_template = message_template else: log.warning("%s parameter is expected to be a filehandle, it is a %s. \ Using the embedded message_template.msg" % (message_template, type(message_template))) self.message_template = None if not message_xml: self.message_xml = MessageDotXML() else: self.message_xml = message_xml self.helpers = Helpers() # allow the packet_handler to be passed in # otherwise, grab the defaults if message_handler != None: self.message_handler = message_handler elif self.settings.HANDLE_PACKETS: from pyogp.lib.base.message.message_handler import MessageHandler self.message_handler = MessageHandler() # set up our parsers self.udp_deserializer = UDPMessageDeserializer(self.message_handler, self.settings, message_template = self.message_template) self.udp_serializer = UDPMessageSerializer(message_template = self.message_template)
def __init__(self, agent, settings): # allow the settings to be passed in # otherwise, grab the defaults if settings != None: self.settings = settings else: from pyogp.lib.base.settings import Settings self.settings = Settings() self.agent = agent
def process_stream(data, source=None, stats = None): msg_buff = gen_message_buffer(data) settings = Settings() settings.ENABLE_DEFERRED_PACKET_PARSING = False if msg_buff != None: try: deserializer = UDPMessageDeserializer(settings = settings) packet = deserializer.deserialize(msg_buff) display_packet(packet, data, source) if stats != None: stats.addSuccess(packet.name) except Exception, e: print 'Unable to parse data "%s" due to: %s' % (data, e) traceback.print_exc() if stats != None: stats.addFail(data)
def __init__(self, settings=None): """ i do nothing """ # allow the settings to be passed in # otherwise, grab the defaults if settings != None: self.settings = settings else: from pyogp.lib.base.settings import Settings self.settings = Settings() self.handlers = {}
def test_quiet_settings(self): settings = Settings(True) self.assertEquals(settings.quiet_logging, True) self.assertEquals(settings.HANDLE_PACKETS, True) self.assertEquals(settings.LOG_VERBOSE, False) self.assertEquals(settings.ENABLE_BYTES_TO_HEX_LOGGING, False) self.assertEquals(settings.ENABLE_CAPS_LOGGING, False) self.assertEquals(settings.ENABLE_CAPS_LLSD_LOGGING, False) self.assertEquals(settings.ENABLE_EQ_LOGGING, False) self.assertEquals(settings.ENABLE_UDP_LOGGING, False) self.assertEquals(settings.ENABLE_OBJECT_LOGGING, False) self.assertEquals(settings.LOG_SKIPPED_PACKETS, False) self.assertEquals(settings.ENABLE_HOST_LOGGING, False) self.assertEquals(settings.LOG_COROUTINE_SPAWNS, False)
def test_cap_constructor(self): from pyogp.lib.base.settings import Settings name = 'foo' url = 'http://127.0.0.1' settings = Settings() cap = Capability(name, url, restclient=self.restclient, settings=settings) self.assertEquals(name, cap.name) self.assertEquals(url, cap.public_url) self.assertEquals(self.restclient, cap.restclient) self.assertEquals(settings, cap.settings)
def __init__(self, name, public_url, restclient = None, settings = None): """ initialize the capability """ # allow the settings to be passed in # otherwise, grab the defaults if settings != None: self.settings = settings else: from pyogp.lib.base.settings import Settings self.settings = Settings() if restclient == None: self.restclient = StdLibClient() else: self.restclient = restclient self.name = name self.public_url = public_url
def test_base_settings(self): settings = Settings() self.assertEquals(settings.quiet_logging, False) self.assertEquals(settings.HANDLE_PACKETS, True) self.assertEquals(settings.LOG_VERBOSE, True) self.assertEquals(settings.ENABLE_BYTES_TO_HEX_LOGGING, False) self.assertEquals(settings.ENABLE_CAPS_LOGGING, True) self.assertEquals(settings.ENABLE_CAPS_LLSD_LOGGING, False) self.assertEquals(settings.ENABLE_EQ_LOGGING, True) self.assertEquals(settings.ENABLE_UDP_LOGGING, True) self.assertEquals(settings.ENABLE_OBJECT_LOGGING, True) self.assertEquals(settings.LOG_SKIPPED_PACKETS, True) self.assertEquals(settings.ENABLE_HOST_LOGGING, True) self.assertEquals(settings.LOG_COROUTINE_SPAWNS, True) self.assertEquals(settings.DISABLE_SPAMMERS, True) self.assertEquals(settings.UDP_SPAMMERS, ['PacketAck', 'AgentUpdate'])
def __init__(self, capability = None, settings = None, \ message_handler = None, host = None): """ set up the event queue attributes """ # allow the settings to be passed in # otherwise, grab the defaults if settings != None: self.settings = settings else: from pyogp.lib.base.settings import Settings self.settings = Settings() # allow the packet_handler to be passed in # otherwise, grab the defaults # otherwise, let's just use our own if message_handler != None: self.message_handler = message_handler else: self.message_handler = MessageHandler() self.host = host self.cap = capability #self.type = eq_type # specify 'agentdomain' or 'region' self.type = 'typeNotSpecified' self._running = False # this class controls this value self.stopped = False # client can pause the event queue self.last_id = -1 # if applicable, initialize data to post to the event queue self.data = {} # stores the result of the post to the event queue capability self.result = None # enables proper packet parsing in event queue responses self.template_dict = TemplateDictionary() self.current_template = None
def setUp(self): self.settings = Settings() self.settings.ENABLE_DEFERRED_PACKET_PARSING = False
Licensed under the Apache License, Version 2.0. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 or in http://svn.secondlife.com/svn/linden/projects/2008/pyogp/lib/base/LICENSE.txt $/LicenseInfo$ """ # std lib import logging #pyogp from pyogp.lib.base.settings import Settings settings = Settings() debug = settings.ENABLE_LOGGING_IN_TESTS #setup logging if debug: console = logging.StreamHandler() console.setLevel( logging.DEBUG) # seems to be a no op, set it for the logger formatter = logging.Formatter( '%(asctime)-30s%(name)-15s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) # setting the level for the handler above seems to be a no-op