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)
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()