def _build_rpc_info_urls(self): """Patch-in for `ClusterClientService._build_rpc_info_urls`. Returns a dummy value. """ return [ ([ascii_url(self.maas_url)], self.maas_url), ]
def fetch_api_description(url, insecure=False): """Obtain the description of remote API given its base URL.""" url_describe = urljoin(url, "describe/") response, content = http_request( ascii_url(url_describe), "GET", insecure=insecure) if response.status != httplib.OK: raise CommandError( "{0.status} {0.reason}:\n{1}".format(response, content)) if response["content-type"] != "application/json": raise CommandError( "Expected application/json, got: %(content-type)s" % response) return json.loads(content)
def make_ws_uri(self, csrftoken=None): """Make a websocket URI. In practice, the URI usually looks like: '/MAAS/ws?csrftoken=<csrftoken>' but in practice the code only cares about the presence of the CSRF token in the query string. """ url = "/%s/%s" % (maas_factory.make_name("path"), maas_factory.make_name("path")) if csrftoken is not None: url += "?csrftoken=%s" % csrftoken return ascii_url(url)
def toString(self, inObject): """Encode a URL-like object into an ASCII URL. :raise TypeError: If `inObject` is not a URL-like object (meaning it doesn't have a `geturl` method). """ try: geturl = inObject.geturl except AttributeError: raise TypeError("Not a URL-like object: %r" % (inObject, )) else: return ascii_url(geturl())
def fetch_api_description(url, insecure=False): """Obtain the description of remote API given its base URL.""" url_describe = urljoin(url, "describe/") response, content = http_request(ascii_url(url_describe), "GET", insecure=insecure) if response.status != httplib.OK: raise CommandError("{0.status} {0.reason}:\n{1}".format( response, content)) if response["content-type"] != "application/json": raise CommandError("Expected application/json, got: %(content-type)s" % response) return json.loads(content)
def fetch_api_description(url, insecure=False): """Obtain the description of remote API given its base URL.""" url_describe = urljoin(url, "describe/") response, content = http_request( ascii_url(url_describe), "GET", insecure=insecure) if response.status != http.client.OK: raise CommandError( "{0.status} {0.reason}:\n{1}".format(response, content)) if response["content-type"] != "application/json": raise CommandError( "Expected application/json, got: %(content-type)s" % response) # XXX mpontillo 2015-12-15: We don't actually know that this is UTF-8, but # I'm keeping it here, because if it happens to be non-ASCII, chances are # good that it'll be UTF-8. return json.loads(content.decode('utf-8'))
def test_ascii_url_asciifies_unicode(self): self.assertEqual(b'http://example.com/', ascii_url('http://example.com/')) self.assertIsInstance(ascii_url('http://example.com'), bytes)
def test_ascii_url_leaves_ascii_bytes_unchanged(self): self.assertEqual(b'http://example.com/', ascii_url(b'http://example.com/')) self.assertIsInstance(ascii_url(b'http://example.com'), bytes)
def test_ascii_url_asciifies_unicode(self): self.assertEqual( b'http://example.com/', ascii_url('http://example.com/')) self.assertIsInstance(ascii_url('http://example.com'), bytes)
def test_ascii_url_leaves_ascii_bytes_unchanged(self): self.assertEqual( b'http://example.com/', ascii_url(b'http://example.com/')) self.assertIsInstance(ascii_url(b'http://example.com'), bytes)
def test_ascii_url_asciifies_unicode(self): self.assertEqual( b"http://example.com/", ascii_url("http://example.com/") ) self.assertIsInstance(ascii_url("http://example.com"), bytes)
def _get_rpc_info_url(self): """Patch-in for `ClusterClientService._get_rpc_info_url`. Returns a dummy value. """ return ascii_url("http://localhost/MAAS")