requests.compat.quote

Here are the examples of the python api requests.compat.quote taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: djangopackages
Source File: utils.py
View license
def quote_plus(s, safe=''):
    """Quote the query fragment of a URL; replacing ' ' with '+'"""
    if ' ' in s:
        s = quote(s, safe + ' ')
        return s.replace(' ', '+')
    return quote(s, safe)

Example 2

Project: YCM_WIN_X86
Source File: test_requests.py
View license
    def test_get_auth_from_url(self):
        """ Ensures that username and password in well-encoded URI as per RFC 3986 are correclty extracted """
        from requests.utils import get_auth_from_url
        from requests.compat import quote
        percent_encoding_test_chars = "%!*'();:@&=+$,/?#[] "
        url_address = "request.com/url.html#test"
        url = "http://" + quote(percent_encoding_test_chars, '') + ':' + quote(percent_encoding_test_chars, '') + '@' + url_address
        (username, password) = get_auth_from_url(url)
        assert username == percent_encoding_test_chars
        assert password == percent_encoding_test_chars

Example 3

Project: pc-bot
Source File: api.py
View license
    def request(self, method, endpoint, body='', **kwargs):
        """Make a request to the PyCon website, and return the result."""
        # The PyCon website runs using HTTPS, but localhost doesn't.
        # Determine the right thing.
        protocol = 'https'
        if 'localhost' in self.host:
            protocol = 'http'

        # Construct the base URI.
        uri = '/2015/pycon_api/%s/' % endpoint.strip('/')

        # If keyword arguments are provided, append them to
        # the URI.
        if kwargs:
            uri += '?' + '&'.join(
                ['%s=%s' % (k, quote(str(v))) for k, v in kwargs.items()],
            )

        # Construct the full URL.
        url = '{protocol}://{host}{uri}'.format(
            host=self.host,
            protocol=protocol,
            uri=uri,
        )

        # Generate the appropriate request signature to certify
        # that this is a valid request.
        signature = self._sign_request(uri, method, body)

        # Add the appropriate content-type header.
        if method == 'POST':
            signature['Content-Type'] = 'application/json'

        # Make the actual request to the PyCon website.
        r = requests.request(method, url, data=body, headers=signature,
                                          verify=False)

        # Sanity check: Did we get a bad request of some kind?
        if r.status_code >= 400:
            # If we got a 500 response, we can't really know what to do
            if r.status_code >= 500:
                raise InternalServerError(r)

            # What exception class shall I use?
            exc_class = APIError
            if r.status_code == 403:
                exc_class = AuthenticationError
            if r.status_code == 404:
                exc_class = NotFound

            # Create and raise the exception
            try:
                ex = exc_class(r.json()['error'])
            except ValueError:
                raise InternalServerError(r)
            ex.request = r
            raise ex

        # OK, all is well; return the response.
        return r.json()

Example 4

Project: pytvmaze
Source File: tvmaze.py
View license
def _url_quote(show):
    return requests.compat.quote(show.encode('UTF-8'))

Example 5

Project: libgreader
Source File: items.py
View license
    @staticmethod
    def urlQuote(string):
        """ Quote a string for being used in a HTTP URL """
        return quote(string.encode("utf-8"))