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)
def load(indra_xml_file=None): global _g_config_dict if _g_config_dict == None: if indra_xml_file is None: ## going from: ## "/opt/linden/indra/lib/python/indra/base/config.py" ## to: ## "/opt/linden/etc/indra.xml" indra_xml_file = realpath( dirname(realpath(__file__)) + "../../../../../../etc/indra.xml") config_file = file(indra_xml_file) _g_config_dict = llsd.LLSD().parse(config_file.read()) config_file.close()
def update(new_conf): """Load an XML file and apply its map as overrides or additions to the existing config. The dataserver does this with indra.xml and dataserver.xml.""" global _g_config_dict if _g_config_dict == None: _g_config_dict = {} if isinstance(new_conf, dict): overrides = new_conf else: config_file = file(new_conf) overrides = llsd.LLSD().parse(config_file.read()) config_file.close() _g_config_dict.update(overrides)
def answer(self, data): if "fail" not in self.path: response = llsd.format_xml(data.get("reply", llsd.LLSD("success"))) 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) reason = data.get("reason", self.responses.get(status, ("fail requested", "Your request specified failure status %s " "without providing a reason" % status))[1]) self.send_error(status, reason)
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)
from indra.base import llsd, lluuid from datetime import datetime import cllsd import time, sys class myint(int): pass values = ( '&<>', u'\u81acj', llsd.uri('http://foo<'), lluuid.UUID(), llsd.LLSD(['thing']), 1, myint(31337), sys.maxint + 10, llsd.binary('foo'), [], {}, { u'f&\u1212': 3 }, 3.1, True, None, datetime.fromtimestamp(time.time()), )
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()