示例#1
0
    def handle_POST(self):

        d = {'foo': 'bar'}
        self.response.status = 200
        self.response.content_type = 'application/llsd+xml'
        self.response.body = llsd.format_xml(d)
        return self.response(self.environ, self.start)
示例#2
0
 def some_capability(self, data, content_type="application/llsd+xml"):
     """handle a dummy test capabilty"""
     d = {'something': 'else', 'some': 12345}
     d.update(data)
     data = llsd.format_xml(d)
     self.response.status = 200
     self.response.content_type = content_type
     self.response.body = data
     return self.response(self.environ, self.start)
示例#3
0
 def place_avatar(self, data):
     """place the avatar in a dummy way"""
     url = data.get("region_url", '')
     d = {
         'sim_ip': '127.0.0.1',
         'sim_port': 12345,
         'region_seed_capability': '/region_seed_cap'
     }
     data = llsd.format_xml(d)
     self.response.status = 200
     self.response.content_type = 'application/llsd+xml'
     self.response.body = data
     return self.response(self.environ, self.start)
示例#4
0
 def handle_seedcap(self, data, content_type="application/llsd+xml"):
     """return some other caps"""
     caps = data.get("capabilities", [])
     d = {'lastname': 'lastname', 'firstname': 'firstname'}
     return_caps = {}
     for cap in caps:
         # simple mapping from capname => host/cap/<capname> instead of UUIDs
         return_caps[cap] = "http://localhost:12345/cap/%s" % cap
     d['capabilities'] = return_caps
     data = llsd.format_xml(d)
     self.response.status = 200
     self.response.content_type = content_type
     self.response.body = data
     return self.response(self.environ, self.start)
示例#5
0
    def handle_legacy_login(self, data):
        """handle the login string"""

        # TODO: This is inadequate, need to handle the cases properly
        password = data.get('password')
        if password != PW:
            self.send_response(403)
            return

        data = {
            'seed_capability': "http://127.0.0.1:12345/seed_cap",
            'login': '******'
        }
        data = llsd.format_xml(data)

        self.response.status = 200
        self.response.content_type = 'application/llsd+xml'
        self.response.body = data
        return self.response(self.environ, self.start)
 def answer(self, data, withdata=True):
     global _storage
     debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data,
           self.path)
     if "fail" in self.path or "test/error" in self.path:  # fail requested
         status = data.get("status", 500)
         # self.responses maps an int status to a (short, long) pair of
         # strings. We want the longer string. That's why we pass a string
         # pair to get(): the [1] will select the second string, whether it
         # came from self.responses or from our default pair.
         reason = data.get(
             "reason",
             self.responses.get(status,
                                ("fail requested",
                                 "Your request specified failure status %s "
                                 "without providing a reason" % status))[1])
         debug("fail requested: %s: %r", status, reason)
         self.send_error(status, reason)
     else:
         if "web/echo" in self.path:
             pass
         elif "test/timeout" in self.path:
             time.sleep(5.0)
             return
         elif "test/storage" in self.path:
             if "GET" == self.command:
                 data = _storage
             else:
                 _storage = data
                 data = "ok"
         else:
             data = data.copy()  # we're going to modify
             # Ensure there's a "reply" key in data, even if there wasn't before
             data["reply"] = data.get("reply", llsd.LLSD("success"))
         response = llsd.format_xml(data)
         debug("success: %s", response)
         self.send_response(200)
         self.send_header("Content-type", "application/llsd+xml")
         self.send_header("Content-Length", str(len(response)))
         self.end_headers()
         if withdata:
             self.wfile.write(response)
示例#7
0
    def to_llsd(self):
        """ an llsd representation of a message """

        # broken!!! e.g.
        '''
        2010-01-09 01:47:16,482       client_proxy.lib.udpproxy     : INFO     Sending message:AgentUpdate to Host: '216.82.49.231:12035'. ID:86
        2010-01-09 01:47:16,482       client_proxy.lib.udpproxy     : ERROR    Problem handling viewer to sim proxy: invalid type.
        Traceback (most recent call last):
          File "/Users/enus/sandbox/lib/python2.6/site-packages/pyogp.apps-0.1dev-py2.6.egg/pyogp/apps/proxy/lib/udpproxy.py", line 111, in _send_viewer_to_sim
            logger.debug(recv_packet.as_llsd()) # ToDo: make this optionally llsd logging once that's in
          File "/Users/enus/sandbox/lib/python2.6/site-packages/pyogp.lib.base-0.1dev-py2.6.egg/pyogp/lib/base/message/message.py", line 158, in as_llsd
            return llsd.format_xml(self.as_dict())
          File "build/bdist.macosx-10.6-universal/egg/llbase/llsd.py", line 353, in format_xml
            return _g_xml_formatter.format(something)
          File "build/bdist.macosx-10.6-universal/egg/llbase/llsd.py", line 334, in format
            return cllsd.llsd_to_xml(something)
        TypeError: invalid type
        '''

        return llsd.format_xml(self.as_dict())
示例#8
0
    def test_builder(self):
        builder = LLSDMessageBuilder()
        builder.new_message('TestMessage')

        builder.next_block('TestBlock1')
        builder.add_data('Test1', 0x00000001, MsgType.MVT_U32)

        builder.next_block('TestBlock1')
        builder.add_data('Test2', 0x00000001, MsgType.MVT_U32)

        builder.next_block('NeighborBlock')
        builder.add_data('Test0', 0x00000001, MsgType.MVT_U32)
        builder.add_data('Test1', 0x00000001, MsgType.MVT_U32)
        builder.add_data('Test2', 0x00000001, MsgType.MVT_U32)

        builder.next_block('NeighborBlock')
        builder.add_data('Test1', 0x00000001, MsgType.MVT_U32)
        builder.add_data('Test1', 0x00000001, MsgType.MVT_U32)
        builder.add_data('Test1', 0x00000001, MsgType.MVT_U32)

        builder.next_block('NeighborBlock')
        builder.add_data('Test2', 0x00000001, MsgType.MVT_U32)
        builder.add_data('Test2', 0x00000001, MsgType.MVT_U32)
        builder.add_data('Test2', 0x00000001, MsgType.MVT_U32)

        builder.next_block('TestBlock2')
        builder.add_data('Test1', 0x00000001, MsgType.MVT_U32)

        msg, size = builder.build_message()

        try:
            assert len(msg['NeighborBlock']) == 3, "Multiple blocks not" + \
                   " correct"
        except:
            assert False, "Message not set up properly"

        try:
            msg = llsd.format_xml(msg)
        except:
            assert False, "Message not built correctly so it can be formatted"
示例#9
0
 def serialize(self):
     """convert the payload to LLSD"""
     return llsd.format_xml(self.context)
    def answer(self, data, withdata=True):
        debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data,
              self.path)
        if "/sleep/" in self.path:
            time.sleep(30)

        if "/503/" in self.path:
            # Tests for various kinds of 'Retry-After' header parsing
            body = None
            if "/503/0/" in self.path:
                self.send_response(503)
                self.send_header("retry-after", "2")
            elif "/503/1/" in self.path:
                self.send_response(503)
                self.send_header("retry-after",
                                 "Thu, 31 Dec 2043 23:59:59 GMT")
            elif "/503/2/" in self.path:
                self.send_response(503)
                self.send_header("retry-after",
                                 "Fri, 31 Dec 1999 23:59:59 GMT")
            elif "/503/3/" in self.path:
                self.send_response(503)
                self.send_header("retry-after", "")
            elif "/503/4/" in self.path:
                self.send_response(503)
                self.send_header("retry-after", "(*#*(@*(@(")
            elif "/503/5/" in self.path:
                self.send_response(503)
                self.send_header(
                    "retry-after",
                    "aklsjflajfaklsfaklfasfklasdfklasdgahsdhgasdiogaioshdgo")
            elif "/503/6/" in self.path:
                self.send_response(503)
                self.send_header("retry-after", "1 2 3 4 5 6 7 8 9 10")
            else:
                # Unknown request
                self.send_response(400)
                body = "Unknown /503/ path in server"
            if "/reflect/" in self.path:
                self.reflect_headers()
            self.send_header("Content-type", "text/plain")
            self.end_headers()
            if body:
                self.wfile.write(body)
        elif "/bug2295/" in self.path:
            # Test for https://jira.secondlife.com/browse/BUG-2295
            #
            # Client can receive a header indicating data should
            # appear in the body without actually getting the body.
            # Library needs to defend against this case.
            #
            body = None
            if "/bug2295/0/" in self.path:
                self.send_response(206)
                self.send_header("Content-Range", "bytes 0-75/2983")
            elif "/bug2295/1/" in self.path:
                self.send_response(206)
                self.send_header("Content-Range", "bytes 0-75/*")
            elif "/bug2295/2/" in self.path:
                self.send_response(206)
                self.send_header("Content-Range", "bytes 0-75/2983")
                self.send_header("Content-Length", "0")
            elif "/bug2295/00000012/0/" in self.path:
                self.send_response(206)
                self.send_header("Content-Range", "bytes 0-75/2983")
                self.send_header("Content-Length", "76")
            elif "/bug2295/inv_cont_range/0/" in self.path:
                self.send_response(206)
                self.send_header("Content-Range", "bytes 0-75/2983")
                body = "Some text, but not enough."
            else:
                # Unknown request
                self.send_response(400)
            if "/reflect/" in self.path:
                self.reflect_headers()
            self.send_header("Content-type", "text/plain")
            self.end_headers()
            if body:
                self.wfile.write(body)
        elif "fail" not in self.path:
            data = data.copy()  # we're going to modify
            # Ensure there's a "reply" key in data, even if there wasn't before
            data["reply"] = data.get("reply", llsd.LLSD("success"))
            response = llsd.format_xml(data)
            debug("success: %s", response)
            self.send_response(200)
            if "/reflect/" in self.path:
                self.reflect_headers()
            self.send_header("Content-type", "application/llsd+xml")
            self.send_header("Content-Length", str(len(response)))
            self.send_header("X-LL-Special", "Mememememe")
            self.end_headers()
            if withdata:
                self.wfile.write(response)
        else:  # fail requested
            status = data.get("status", 500)
            # self.responses maps an int status to a (short, long) pair of
            # strings. We want the longer string. That's why we pass a string
            # pair to get(): the [1] will select the second string, whether it
            # came from self.responses or from our default pair.
            reason = data.get(
                "reason",
                self.responses.get(status,
                                   ("fail requested",
                                    "Your request specified failure status %s "
                                    "without providing a reason" % status))[1])
            debug("fail requested: %s: %r", status, reason)
            self.send_error(status, reason)
            if "/reflect/" in self.path:
                self.reflect_headers()
            self.end_headers()