def dump(indra_xml_file, indra_cfg = None, update_in_mem=False): ''' Dump config contents into a file Kindof reverse of load. Optionally takes a new config to dump. Does NOT update global config unless requested. ''' global _g_config if not indra_cfg: if _g_config is None: return indra_cfg = _g_config.as_dict() if not indra_cfg: return config_file = open(indra_xml_file, 'w') _config_xml = llsd.format_xml(indra_cfg) config_file.write(_config_xml) config_file.close() if update_in_mem: update(indra_cfg)
def dump(indra_xml_file, indra_cfg=None, update_in_mem=False): ''' Dump config contents into a file Kindof reverse of load. Optionally takes a new config to dump. Does NOT update global config unless requested. ''' global _g_config if not indra_cfg: if _g_config is None: return indra_cfg = _g_config.as_dict() if not indra_cfg: return config_file = open(indra_xml_file, 'w') _config_xml = llsd.format_xml(indra_cfg) config_file.write(_config_xml) config_file.close() if update_in_mem: update(indra_cfg)
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)
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 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)
def rez(self, agent): """rez an IAgent on that region""" session_id = str(uuid.uuid1()) secure_session_id = session_id circuit_code = random.randint(0, 9999999) data = { 'agent_id': agent.agent_id, 'first_name': agent.first_name, 'last_name': agent.last_name, 'age_verified': agent.age_verified, 'agent_access': agent.agent_access, 'allow_redirect': agent.allow_redirect, 'god_level': agent.god_level, 'identified': agent.identified, 'transacted': agent.transacted, 'limited_to_estate': agent.limited_to_estate, 'sim_access': agent.sim_access } xml = llsd.format_xml(data) url = urljoin(self.url, 'agent/%s/request' % agent.agent_id) headers = { 'Content-Type': 'application/llsd+xml', 'Content-Length': len(xml) } request = urllib2.Request(url, xml, headers) result = urllib2.urlopen(request).read() result = llsd.parse(result) # TODO: Error handling! What are the possible error conditions? # step two: rez_avatar url = result['rez_avatar/rez'] # create the rez_avatar payload: data = { 'first_name': agent.first_name, 'last_name': agent.last_name, 'secure_session_id': session_id, 'age_verified': False, 'region_id': '00000000-0000-0000-0000-000000000000', 'transacted': False, 'agent_access': False, 'circuit_code': circuit_code, 'identified': False, 'session_id': session_id, 'god_level': 0, 'god_override': False, 'inventory_host': 'inv4.mysql.agni.lindenlab.com', 'limited_to_estate': '1', 'position': self.position, 'start': 'safe' } xml = llsd.format_xml(data) headers = { 'Content-Type': 'application/llsd+xml', 'Content-Length': len(xml) } request = urllib2.Request(url, xml, headers) result = urllib2.urlopen(request).read() data = llsd.parse(result) self.region_y = data.get('region_y', None) self.region_x = data.get('region_x', None) self.seed_capability = data.get('seed_capability', None) self.region_id = data.get('region_id', None) self.sim_access = data.get('sim_access', None) self.connect = data.get('connect', None) self.sim_port = data.get('sim_port', None) self.sim_ip = data.get('sim_ip', None) self.session_id = session_id self.secure_session_id = secure_session_id self.circuit_code = circuit_code self.agent_id = agent.agent_id
def test_basic_get(self): req = siesta.Request.blank('/') self.assertEquals( req.get_response(self.server).body, llsd.format_xml(None))
def test_basic_get(self): req = siesta.Request.blank('/') self.assertEquals(req.get_response(self.server).body, llsd.format_xml(None))
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()