Пример #1
0
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
Пример #2
0
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'
Пример #3
0
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'
Пример #4
0
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"
Пример #5
0
def test_abspath(url, expected):
	uri = URI()
	uri.parse(url)
	uri.abspath()
	assert uri.tuple == expected
	uri.normalize()
	assert uri.tuple == expected
Пример #6
0
 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))
Пример #7
0
 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
Пример #8
0
	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
Пример #9
0
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)
Пример #10
0
def test_parse_scheme(url, expected):
	uri = URI(url)
	assert uri.tuple == expected
	assert bytes(uri) == bytes(URI(expected))
Пример #11
0
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'
    }
Пример #12
0
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'}
Пример #13
0
def test_parse_invalid_netloc(url):
    with pytest.raises(InvalidURI):
        URI(url)
Пример #14
0
def test_query_string_compose(query_string, query):
    uri = URI(b'http://example.com/')
    uri.query = query
    assert uri.query_string == query_string
Пример #15
0
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)
Пример #16
0
 def redirect_alias(self, domain, client):
     path = URI(client.request.uri)
     path.host = domain.fqdn
     raise MOVED_PERMANENTLY(path)
Пример #17
0
def test_ipvfuture(url, hostname, port):
    url = URI(url)
    assert url.hostname == hostname
Пример #18
0
def test_rfc2732(url, hostname, port):
    url = URI(url)
    assert url.hostname == hostname
    assert url.port == port
Пример #19
0
def test_unparse_parse(u):
    assert bytes(URI(u)) == u
Пример #20
0
	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
Пример #21
0
def test_query_string_parse(query_string, query):
    uri = URI(b'http://example.com/?%s' % (query_string, ))
    assert uri.query == query
Пример #22
0
def test_query_string_compose(query_string, query):
    uri = URI(b"http://example.com/")
    uri.query = query
    assert uri.query_string == query_string
Пример #23
0
def test_uri_join_very_strict(base, relative, expected):
	uri = URI(base).join(relative)
	assert bytes(uri) == bytes(expected)
Пример #24
0
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"}
Пример #25
0
	def redirect_alias(self, domain, client):
		path = URI(client.request.uri)
		path.host = domain.fqdn
		raise MOVED_PERMANENTLY(path)
Пример #26
0
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'
Пример #27
0
def test_parse_absolute_uri(url, expected):
    uri = URI()
    uri.parse(url)
    assert uri.tuple == expected
Пример #28
0
def test_parse_absolute_uri(url, expected):
	uri = URI()
	uri.parse(url)
	assert uri.tuple == expected
Пример #29
0
def test_uri_join(base, relative, expected):
	uri = URI(base).join(relative)
	assert uri == expected