Ejemplo n.º 1
0
    def __init__(self):
        """
        Initialize the Request. All parameters are set as public attributes
        with the same name.

        :param str method: (or bytes) the method to use
        :param str url: (or bytes) the URL to fetch. This can have non-ASCII
            characters, and they will be interpreted as an IRI.
        :param dict headers: the headers to send with the request.
            keys and values must be bytes.
        :param bytes data: the request body to send
        :param int timeout: time to way before giving up. None means
            no timeout
        """
        self.url = URLObject.from_iri(self.url)
        if self.headers is not None:
            for k,v in self.headers.items():
                if type(k) is not bytes:
                    raise TypeError("headers key {key!r} is not bytes".format(key=k))
                elif type(v) is not bytes:
                    raise TypeError("headers value {value!r} is not bytes".format(value=v))
Ejemplo n.º 2
0
 def test_path_params(self):
     assert (URLObject.from_iri(u('https://example.com/foo;p\xe5rameter')) ==
             'https://example.com/foo;p%C3%A5rameter')
Ejemplo n.º 3
0
 def test_encode_fragment(self):
     assert (URLObject.from_iri(u('https://example.com/#fr\xe5gment')) ==
             'https://example.com/#fr%C3%A5gment')
Ejemplo n.º 4
0
 def test_encode_query(self):
     assert (URLObject.from_iri(u('https://example.com/?k\xe9y=v\xe5l&key2=val2')) ==
             'https://example.com/?k%C3%A9y=v%C3%A5l&key2=val2')
Ejemplo n.º 5
0
 def test_encode_path(self):
     assert (URLObject.from_iri(u('https://example.com/p\xe5th/path2')) ==
             'https://example.com/p%C3%A5th/path2')
Ejemplo n.º 6
0
 def test_port_maintained(self):
     assert (URLObject.from_iri(u('https://\xe9xample.com:80/')) ==
             'https://xn--xample-9ua.com:80/')
Ejemplo n.º 7
0
 def test_encode_hostname_idna(self):
     assert (URLObject.from_iri(u('https://\xe9xample.com/')) ==
             'https://xn--xample-9ua.com/')
Ejemplo n.º 8
0
 def test_port_maintained(self):
     assert (URLObject.from_iri(u('https://\xe9xample.com:80/')) ==
             'https://xn--xample-9ua.com:80/')
Ejemplo n.º 9
0
 def test_quote_other_special_characters(self):
     assert (URLObject.from_iri(u('https://example.com/foo bar/')) ==
             'https://example.com/foo%20bar/')
Ejemplo n.º 10
0
 def test_path_params(self):
     assert (URLObject.from_iri(u('https://example.com/foo;p\xe5rameter'))
             == 'https://example.com/foo;p%C3%A5rameter')
Ejemplo n.º 11
0
 def test_quoted_iri(self):
     """
     If an IRI already has some quoted characters, they will be maintained as is.
     """
     assert (URLObject.from_iri(u('https://example.com/foo%20b\xe5r/')) ==
             'https://example.com/foo%20b%C3%A5r/')
Ejemplo n.º 12
0
 def test_encode_fragment(self):
     assert (URLObject.from_iri(u('https://example.com/#fr\xe5gment')) ==
             'https://example.com/#fr%C3%A5gment')
Ejemplo n.º 13
0
 def test_encode_query(self):
     assert (URLObject.from_iri(
         u('https://example.com/?k\xe9y=v\xe5l&key2=val2')) ==
             'https://example.com/?k%C3%A9y=v%C3%A5l&key2=val2')
Ejemplo n.º 14
0
 def test_encode_path(self):
     assert (URLObject.from_iri(u('https://example.com/p\xe5th/path2')) ==
             'https://example.com/p%C3%A5th/path2')
Ejemplo n.º 15
0
 def test_quoted_iri(self):
     """
     If an IRI already has some quoted characters, they will be maintained as is.
     """
     assert (URLObject.from_iri(u('https://example.com/foo%20b\xe5r/')) ==
         'https://example.com/foo%20b%C3%A5r/')
Ejemplo n.º 16
0
def request_intent(method, url, headers=None, **kwargs):
    url = URLObject.from_iri(url)
    return Request(method, url, headers=headers, **kwargs)
Ejemplo n.º 17
0
 def test_quote_other_special_characters(self):
     assert (URLObject.from_iri(u('https://example.com/foo bar/')) ==
         'https://example.com/foo%20bar/')
Ejemplo n.º 18
0
 def test_encode_hostname_idna(self):
     assert (URLObject.from_iri(
         u('https://\xe9xample.com/')) == 'https://xn--xample-9ua.com/')