コード例 #1
0
 def answer(self, data):
     debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data,
           self.path)
     if "fail" not in self.path:
         response = llsd.format_xml(data.get("reply", llsd.LLSD("success")))
         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()
         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)
コード例 #2
0
 def answer(self, data, withdata=True):
     debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data, self.path)
     if "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)
         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)
     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)
コード例 #3
0
 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)
コード例 #4
0
 def run(self):
     httpd = HTTPServer(("127.0.0.1", 8000), TestHTTPRequestHandler)
     debug("Starting HTTP server...\n")
     httpd.serve_forever()
コード例 #5
0
        def log_request(self, code, size=None):
            # For present purposes, we don't want the request splattered onto
            # stderr, as it would upset devs watching the test run
            pass

        def log_error(self, format, *args):
            # Suppress error output as well
            pass

class Server(HTTPServer):
    # This pernicious flag is on by default in HTTPServer. But proper
    # operation of freeport() absolutely depends on it being off.
    allow_reuse_address = False

if __name__ == "__main__":
    # Instantiate a Server(TestHTTPRequestHandler) on the first free port
    # in the specified port range. Doing this inline is better than in a
    # daemon thread: if it blows up here, we'll get a traceback. If it blew up
    # in some other thread, the traceback would get eaten and we'd run the
    # subject test program anyway.
    httpd, port = freeport(xrange(8000, 8020),
                           lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler))
    # Pass the selected port number to the subject test program via the
    # environment. We don't want to impose requirements on the test program's
    # command-line parsing -- and anyway, for C++ integration tests, that's
    # performed in TUT code rather than our own.
    os.environ["PORT"] = str(port)
    debug("$PORT = %s", port)
    sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), *sys.argv[1:]))
コード例 #6
0
 def run(self):
     server = TestServer(('127.0.0.1', 8000))
     debug("Starting XMLRPC server...\n")
     server.serve_forever()
コード例 #7
0
        def log_request(self, code, size=None):
            # For present purposes, we don't want the request splattered onto
            # stderr, as it would upset devs watching the test run
            pass

        def log_error(self, format, *args):
            # Suppress error output as well
            pass

class Server(HTTPServer):
    # This pernicious flag is on by default in HTTPServer. But proper
    # operation of freeport() absolutely depends on it being off.
    allow_reuse_address = False

if __name__ == "__main__":
    # Instantiate a Server(TestHTTPRequestHandler) on the first free port
    # in the specified port range. Doing this inline is better than in a
    # daemon thread: if it blows up here, we'll get a traceback. If it blew up
    # in some other thread, the traceback would get eaten and we'd run the
    # subject test program anyway.
    httpd, port = freeport(xrange(8000, 8020),
                           lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler))
    # Pass the selected port number to the subject test program via the
    # environment. We don't want to impose requirements on the test program's
    # command-line parsing -- and anyway, for C++ integration tests, that's
    # performed in TUT code rather than our own.
    os.environ["PORT"] = str(port)
    debug("$PORT = %s", port)
    sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), *sys.argv[1:]))
コード例 #8
0
ファイル: test_llxmlrpc_peer.py プロジェクト: gurucoyote/c20
 def run(self):
     server = TestServer(('127.0.0.1', 8000))
     debug("Starting XMLRPC server...\n")
     server.serve_forever()
コード例 #9
0
    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()
コード例 #10
0
    path_search = False
    options, args = getopt.getopt(sys.argv[1:], "V", ["valgrind"])
    for option, value in options:
        if option == "-V" or option == "--valgrind":
            do_valgrind = True

    # function to make a server with specified port
    make_server = lambda port: Server(
        ('127.0.0.1', port), TestHTTPRequestHandler)

    if not sys.platform.startswith("win"):
        # Instantiate a Server(TestHTTPRequestHandler) on a port chosen by the
        # runtime.
        httpd = make_server(0)
    else:
        # "Then there's Windows"
        # Instantiate a Server(TestHTTPRequestHandler) on the first free port
        # in the specified port range.
        httpd, port = freeport(xrange(8000, 8020), make_server)

    # Pass the selected port number to the subject test program via the
    # environment. We don't want to impose requirements on the test program's
    # command-line parsing -- and anyway, for C++ integration tests, that's
    # performed in TUT code rather than our own.
    os.environ["LL_TEST_PORT"] = str(httpd.server_port)
    debug("$LL_TEST_PORT = %s", httpd.server_port)
    if do_valgrind:
        args = ["valgrind", "--log-file=./valgrind.log"] + args
        path_search = True
    sys.exit(run(server_inst=httpd, use_path=path_search, *args))
コード例 #11
0

class Server(HTTPServer):
    # This pernicious flag is on by default in HTTPServer. But proper
    # operation of freeport() absolutely depends on it being off.
    allow_reuse_address = False


if __name__ == "__main__":
    # function to make a server with specified port
    make_server = lambda port: Server(
        ('127.0.0.1', port), TestHTTPRequestHandler)

    if not sys.platform.startswith("win"):
        # Instantiate a Server(TestHTTPRequestHandler) on a port chosen by the
        # runtime.
        httpd = make_server(0)
    else:
        # "Then there's Windows"
        # Instantiate a Server(TestHTTPRequestHandler) on the first free port
        # in the specified port range.
        httpd, port = freeport(xrange(8000, 8020), make_server)

    # Pass the selected port number to the subject test program via the
    # environment. We don't want to impose requirements on the test program's
    # command-line parsing -- and anyway, for C++ integration tests, that's
    # performed in TUT code rather than our own.
    os.environ["PORT"] = str(httpd.server_port)
    debug("$PORT = %s", httpd.server_port)
    sys.exit(run(server_inst=httpd, *sys.argv[1:]))
コード例 #12
0
    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()
コード例 #13
0
        print client_address
        print '-'*40

if __name__ == "__main__":
    do_valgrind = False
    path_search = False
    options, args = getopt.getopt(sys.argv[1:], "V", ["valgrind"])
    for option, value in options:
        if option == "-V" or option == "--valgrind":
            do_valgrind = True

    # Instantiate a Server(TestHTTPRequestHandler) on the first free port
    # in the specified port range. Doing this inline is better than in a
    # daemon thread: if it blows up here, we'll get a traceback. If it blew up
    # in some other thread, the traceback would get eaten and we'd run the
    # subject test program anyway.
    httpd, port = freeport(xrange(8000, 8020),
                           lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler))

    # Pass the selected port number to the subject test program via the
    # environment. We don't want to impose requirements on the test program's
    # command-line parsing -- and anyway, for C++ integration tests, that's
    # performed in TUT code rather than our own.
    os.environ["LL_TEST_PORT"] = str(port)
    debug("$LL_TEST_PORT = %s", port)
    if do_valgrind:
        args = ["valgrind", "--log-file=./valgrind.log"] + args
        path_search = True
    sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), use_path=path_search, *args))

コード例 #14
0
 def run(self):
     httpd = HTTPServer(('127.0.0.1', 8000), TestHTTPRequestHandler)
     debug("Starting HTTP server...\n")
     httpd.serve_forever()