def decode_url_encoding(input_string):
    """Returns a URL decoded byte-string
    """
    if type(input_string) == bytes:
        input_string = input_string.decode()
    if '%' not in input_string:
        return input_string.encode()
    return urlparse.unquote(input_string).encode()
Exemple #2
0
    def __init__(self):
        try:
            proxy = getproxies()['https']
        except KeyError:
            proxy = None
        if proxy is None:
            self._proxy = None
        else:
            # This assumes that the proxy is given in URL form.
            # A little simpler as _parse_proxy in urllib2.py
            self._proxy = urlparse(proxy)

        if proxy is None or not self._proxy.username:
            self._proxy_auth = None
        else:
            user_pass = "******" % (urlparse.unquote(self._proxy.username),
                                   urlparse.unquote(self._proxy.password))
            self._proxy_auth = {"Proxy-Authorization":
                                "Basic " + base64.b64encode(user_pass).strip()}
Exemple #3
0
    def __init__(self):
        try:
            proxy = getproxies()['https']
        except KeyError:
            proxy = None
        if proxy is None:
            self._proxy = None
        else:
            # This assumes that the proxy is given in URL form.
            # A little simpler as _parse_proxy in urllib2.py
            self._proxy = urlparse(proxy)

        if proxy is None or not self._proxy.username:
            self._proxy_auth = None
        else:
            user_pass = "******" % (urlparse.unquote(self._proxy.username),
                                   urlparse.unquote(self._proxy.password))
            self._proxy_auth = {"Proxy-Authorization":
                                "Basic " + base64.b64encode(user_pass).strip()}
def test():
    if not APP_DEBUG:
        return jsonify({"page": "test"})

    res = "<h2>Test Page (DEBUG):</h2>"
    import urllib
    for rule in app.url_map.iter_rules():
        options = {}
        for arg in rule.arguments:
            options[arg] = "[{0}]".format(arg)

        methods = ','.join(rule.methods)
        url = url_for(rule.endpoint, **options)
        res += urlparse.unquote(
            "{0:50s} {1:20s} <a href='{2}'>{2}</a><br/>".format(
                rule.endpoint, methods, url))

    return res
Exemple #5
0
 def buildGetParams(self, request):
     params = {}
     try:
         path = re.findall("^GET ([^\s]+)", request)
     except:
         path = re.findall("^GET ([^\s]+)", request.decode('utf-8'))
     if path:
         path = path[0]
         start = path.find("?")
         if start != -1:
             for param in path[start+1:].split("&"):
                 f = param.split("=")
                 if len(f) == 2:
                     var = f[0]
                     value = f[1]
                     value = value.replace("+", " ")
                     value = urlparse.unquote(value)
                     params[var] = value
     return params