def test_simple_uri_comparision(uri): u1 = URI(b'http://abc.com:80/~smith/home.html') u2 = URI(b'http://ABC.com/%7Esmith/home.html') u3 = URI(b'http://ABC.com:/%7esmith/home.html') u4 = URI(b'http://ABC.com:/%7esmith/./home.html') u5 = URI(b'http://ABC.com:/%7esmith/foo/../home.html') assert u1 == u2 assert u2 == u3 assert u1 == u3 assert u1 == u4 assert u1 == u5
def test_urlencode_object(): class Trivial(object): def __str__(self): return 'trivial' def __unicode__(self): return u'trivial' def __bytes__(self): return b'trivial' u = URI() u.query = {u'a': Trivial()} assert u.query_string == b'a=trivial'
def test_urlencode_object(): class Trivial(object): def __str__(self): return 'trivial' def __unicode__(self): return u'trivial' def __bytes__(self): return b'trivial' u = URI() u.query = {u'a': Trivial()} assert u.query_string == b'a=trivial'
def test_urlencode_object(): class Trivial(object): def __str__(self): return "trivial" def __unicode__(self): return u"trivial" def __bytes__(self): return b"trivial" u = URI() u.query = {u"a": Trivial()} assert u.query_string == b"a=trivial"
def test_abspath(url, expected): uri = URI() uri.parse(url) uri.abspath() assert uri.tuple == expected uri.normalize() assert uri.tuple == expected
def add_sockets(self): if not self.arguments.bind: if self.arguments.wsgi: return import warnings warnings.warn('No socket to bind to. Use --bind.', RuntimeWarning) for bind in self.arguments.bind: self.add_socket(URI(bind))
def url(self, client, *path): uri = URI(scheme=client.request.uri.scheme, host=self.fqdn, port=client.server.port) uri2 = URI() uri2.path_segments = path uri.join(uri2) return uri
def select_service_provider(self, client): """Select the URI of the requested assertion consumer service and the reply binding which should be used. If tries to preserve the current request scheme (HTTP / HTTPS) and picks the same netloc (host or IP). If nothing is found for this it falls back to the regular full qualified host name of the service provider. Returns (binding, service-provider-URI) """ acs = self.sp.config.getattr("endpoints", "sp")["assertion_consumer_service"] service_url, reply_binding = acs[0] netloc = False p2 = client.request.uri for _url, _binding in acs: p1 = URI(_url) if p1.scheme == p2.scheme and p1.netloc == p2.netloc: netloc = True service_url, reply_binding = _url, _binding if p1.path == p2.path: break elif not netloc and p1.netloc == p2.netloc: service_url, reply_binding = _url, _binding return reply_binding, service_url
def test_parse_encodings(query_string, encoding, query): u = URI() u.encoding = encoding u.parse(b'http://example.com/?%s' % (query_string, )) assert u.query == tuple(query)
def test_parse_scheme(url, expected): uri = URI(url) assert uri.tuple == expected assert bytes(uri) == bytes(URI(expected))
def test_urlencode_sequences(): u = URI() u.query = {'a': [1, 2], 'b': (3, 4, 5)} assert set(u.query_string.split(b'&')) == { b'a=1', b'a=2', b'b=3', b'b=4', b'b=5' }
def test_urlencode_sequences(): u = URI() u.query = {'a': [1, 2], 'b': (3, 4, 5)} assert set(u.query_string.split(b'&')) == {b'a=1', b'a=2', b'b=3', b'b=4', b'b=5'}
def test_parse_invalid_netloc(url): with pytest.raises(InvalidURI): URI(url)
def test_query_string_compose(query_string, query): uri = URI(b'http://example.com/') uri.query = query assert uri.query_string == query_string
def test_parse_encodings(query_string, encoding, query): u = URI() u.encoding = encoding u.parse(b"http://example.com/?%s" % (query_string,)) assert u.query == tuple(query)
def redirect_alias(self, domain, client): path = URI(client.request.uri) path.host = domain.fqdn raise MOVED_PERMANENTLY(path)
def test_ipvfuture(url, hostname, port): url = URI(url) assert url.hostname == hostname
def test_rfc2732(url, hostname, port): url = URI(url) assert url.hostname == hostname assert url.port == port
def test_unparse_parse(u): assert bytes(URI(u)) == u
def url(self, client, *path): uri = URI(scheme=client.request.uri.scheme, host=self.fqdn, port=client.server.port) uri2 = URI() uri2.path_segments = path uri.join(uri2) return uri
def test_query_string_parse(query_string, query): uri = URI(b'http://example.com/?%s' % (query_string, )) assert uri.query == query
def test_query_string_compose(query_string, query): uri = URI(b"http://example.com/") uri.query = query assert uri.query_string == query_string
def test_uri_join_very_strict(base, relative, expected): uri = URI(base).join(relative) assert bytes(uri) == bytes(expected)
def test_urlencode_sequences(): u = URI() u.query = {"a": [1, 2], "b": (3, 4, 5)} assert set(u.query_string.split(b"&")) == {b"a=1", b"a=2", b"b=3", b"b=4", b"b=5"}
def redirect_alias(self, domain, client): path = URI(client.request.uri) path.host = domain.fqdn raise MOVED_PERMANENTLY(path)
def test_scheme_difference(): assert URI(b'http://foo.example:1/') != URI(b'ftp://foo.example:1/') assert URI(b'http://foo.example:1/') != b'ftp://foo.example:1' assert URI(b'ftp://foo.example:1/') != b'http://foo.example:1'
def test_parse_absolute_uri(url, expected): uri = URI() uri.parse(url) assert uri.tuple == expected
def test_parse_absolute_uri(url, expected): uri = URI() uri.parse(url) assert uri.tuple == expected
def test_uri_join(base, relative, expected): uri = URI(base).join(relative) assert uri == expected