Example #1
0
def urlform_decode(formencoded):
    "map URL encoded form data to UNICODE keys and values"
    query_strings = {}
    for param in formencoded.split('&'):
        if param.find('=') > -1:
            name, value = param.split('=', 1)
            query_strings[unicode(urldecode(name),
                                  'UTF-8')] = unicode(urldecode(value),
                                                      'UTF-8')
        elif param:
            query_strings[unicode(urldecode(param), 'UTF-8')] = None
    return query_strings
Example #2
0
def urlform_decode (formencoded):
        "map URL encoded form data to UNICODE keys and values"
        query_strings = {}
        for param in formencoded.split ('&'):
                if param.find ('=') > -1:
                        name, value = param.split ('=', 1)
                        query_strings[unicode (
                                urldecode (name), 'UTF-8'
                                )] = unicode (urldecode (value), 'UTF-8')
                elif param:
                        query_strings[unicode (
                                urldecode (param), 'UTF-8'
                                )] = None
        return query_strings
Example #3
0
    def request(self,endpoint, post = None, login = False, flood_wait = False, assoc = True):

        if not self.parent.isLoggedIn and not login:
            Exception("Not logged in\n")
            return

        headers = {
        'Connection': 'close',
        'Accept': '*/*',
        'X-IG-Capabilities ': Constants.X_IG_Capabilities,
             'X-IG-Connection-Type': 'WIFI',
        'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',

        'Accept-Language':' en-US',

        }
        ch =requests.Session()
        ret =requests.Request()
        req = ch.prepare_request(ret)
        req.url= Constants.API_URL+endpoint
        headers['User-agent']=self.userAgent
        req.headers=headers
        if self.parent.settingsAdopter['type'] == 'file':
            cook = load_cookies(self.parent.settings.cookiesPath)
            req.cookies =  cook
        else :
            cookieJar = self.parent.settings.get('cookies');
            cookieJarFile =  os.tempnam(( tempfile.gettempdir(), uuid.uuid1()))
            save_cookies(cookieJar,cookieJarFile)
            req.cookies = cookieJar


        if (post):
            req.method='POST'
            req.data= post

        if (self.parent.proxy) :
            resp = ch.send(req,

            verify=self.verifyHost,
            proxies=self.parent.proxy,
            cert=False,

                          )
        else:
            resp = ch.send(req,
            verify=self.verifyHost,
            cert=False)


        if (self.parent.debug):
            print "REQUEST: endpoint"
            if post:

                   print 'DATA: '+urllib.urldecode(post)


            print "RESPONSE: body\n\n";

        return [resp.response.headers, resp.json()];
Example #4
0
File: util.py Project: linex-cd/puf
def url_decode(string):
	if python_version < (3, 0):
		from urllib import quote as urldecode;
	else:
		from urllib.parse import unquote_plus as urldecode;
	#endif
	return urldecode(string);
Example #5
0
def urlDecode(what):
    res = None

    if type(what) == type(""):
        res = urllib.unquote(string.replace(what, "+", " "))

    elif type(what) == type({}):
        res = urllib.urldecode(what)
    else:
        raise "urlDecode doesn't know how to deal with this kind of data"

    return res
Example #6
0
def urlDecode(what):
    res = None

    if type(what) == type(""):
        res = urllib.unquote(string.replace(what, "+", " "))

    elif type(what) == type({}):
        res = urllib.urldecode(what)
    else:
        raise "urlDecode doesn't know how to deal with this kind of data"

    return res
Example #7
0
def arg(otherwise, query, name):
    """Extracts the value of a query argument."""
    nameLen = len(name)
    if name + "=" == query[:1 + nameLen]:
        first = 1 + nameLen
    else:
        first = query.find("&" + name + "=")
        if -1 == first:
            return otherwise
        first += 2 + nameLen
        last = query.find("&", first)

    return urldecode(query[first:last])
Example #8
0
def arg(otherwise, query, name):
    """Extracts the value of a query argument."""
    nameLen = len(name)
    if name+"=" == query[:1+nameLen]:
        first = 1 + nameLen
    else:
        first = query.find("&"+name+"=")
        if -1 == first:
            return otherwise
        first += 2 + nameLen
        last = query.find("&",first)
    
    return urldecode(query[first:last])
Example #9
0
        def http_continue (self, http):
                uri = http.request[1]
                try:
                        uri = list (HTTP_URI.match (uri).groups ())
                except:
                        uri = ['http://', http.collector_headers.get (
                                'host', self.presto_path
                                ), uri, '', '']
                else:
                        uri[0] = uri[0] or 'http://'
                        uri[1] = uri[1] or http.collector_headers.get (
                                'host', self.presto_path
                                )
                http.uri = uri
                about = uri[2].split ('/', 2)
                about[0] = uri[1]
                about = http.uri_about = tuple ((
                        unicode (urldecode (n), 'UTF-8') for n in about
                        ))
                try:
                        # context, subject and maybe predicate 
                        # || http://host/folder || http://host/folder/file
                        controller = self.presto_cached[about] 
                except:
                        if len (about) > 2:
                                about = (about[0], about[1])
                        else:
                                about = (about[0],)
                        try:
                                # context and subject || http://host/folder
                                controller = self.presto_cached[about] 
                        except:
                                controller = http_404_close

                try:
                        stalled = controller (http, about)
                except:
                        self.loginfo_traceback ()
                        http (500)
                        stalled = False
                try:
                        digest = http.irtd2[4]
                except:
                        digest = '%x' % id (http)
                loginfo.log (str (netstring.encode ((
                        ' '.join (http.request),
                        ''.join (uri[:3]),
                        digest
                        ))), '%d' % http.response)
                return stalled
Example #10
0
    def http_continue(self, http):
        uri = http.request[1]
        try:
            uri = list(HTTP_URI.match(uri).groups())
        except:
            uri = [
                'http://',
                http.collector_headers.get('host', self.presto_path), uri, '',
                ''
            ]
        else:
            uri[0] = uri[0] or 'http://'
            uri[1] = uri[1] or http.collector_headers.get(
                'host', self.presto_path)
        http.uri = uri
        about = uri[2].split('/', 2)
        about[0] = uri[1]
        about = http.uri_about = tuple(
            (unicode(urldecode(n), 'UTF-8') for n in about))
        try:
            # context, subject and maybe predicate
            # || http://host/folder || http://host/folder/file
            controller = self.presto_cached[about]
        except:
            if len(about) > 2:
                about = (about[0], about[1])
            else:
                about = (about[0], )
            try:
                # context and subject || http://host/folder
                controller = self.presto_cached[about]
            except:
                controller = http_404_close

        try:
            stalled = controller(http, about)
        except:
            self.loginfo_traceback()
            http(500)
            stalled = False
        try:
            digest = http.irtd2[4]
        except:
            digest = '%x' % id(http)
        loginfo.log(
            str(
                netstring.encode(
                    (' '.join(http.request), ''.join(uri[:3]), digest))),
            '%d' % http.response)
        return stalled
Example #11
0
    def prepare(self, record):
        """
        Prepares the record to be placed on the queue
        """
        if record.exc_info:
            record.exc_text = self.formatException(record.exc_info)
            record.exc_info = None

        # Apply string formatting to the message using args
        if hasattr(record, 'args'):
            record.msg = urldecode(record.msg) % record.args
            record.args = []

        serialized_record = json.dumps(record.__dict__)
        return serialized_record
Example #12
0
def decode_string(s):
    """
    >>> decode_string('foo')
    u'foo'
    >>> decode_string('foo%20bar')
    u'foo bar'
    >>> decode_string('föö%20bär')
    u'f\\xf6\\xf6 b\\xe4r'
    """
    try:
        s = s.decode('utf-8')
    except:
        if not type(s) in (str, unicode):
            s = unicode(s)
        s = unicode(non_ascii_pattern.sub('', s))
    return urldecode(s)
Example #13
0
def get_pingback_uri(url_to_ping):
   """
    Get Pingback url for RPC
   """
   pingback_uri = ''
   try:
       response = urlfetch.fetch(url_to_ping, method=urlfetch.GET, deadline = 10)
   except:
      pass  
   try:
       pingback_uri = response.headers['X-Pingback']
   except KeyError:
       _pingback_re = re.compile(r'<link rel="pingback" href="([^"]+)" ?/?>(?i)')
       match = _pingback_re.search(response.content)
       if match:
           pingback_uri =urldecode(match.group(1))
   return pingback_uri
Example #14
0
 def get(self, value):
     value = urldecode(value)
     qr_key = QRKey.from_value(value)
     jsonp = self.request.get('callback')
     try:
         qr_image = QRStore.get(qr_key)
         if not qr_image:
             qr_image = QRStore(value)
         
         qr_image.put()  # saves the image if new, but otherwise just updates the access time
         if self.request.get('info'):
             if jsonp:
                 jsonify(self.response, {"success": True, "message": "QR code now stored in database."}, jsonp)
             else:
                 jsonify(self.response, {"success": True, "message": "QR code now stored in database."})
         else:
             self.response.headers['Content-Type'] = "image/png"
             self.response.out.write(qr_image.get_image())
             
     except QRValueError:
         if jsonp:
             jsonify(self.response, {"success": False, "message": "Value too short."}, jsonp)
         else:
             jsonify(self.response, {"success": False, "message": "Value too short."})
Example #15
0
    def changeProfilePicture(self,photo):

        if not photo:
            print  "Photo not valid\n\n";
            return;

        uData = json.loads({
        '_csrftoken' : self.parent.token,
        '_uuid'      : self.parent.uuid,
        '_uid'       : self.parent.username_id,
             });
        endpoint = Constants.API_URL+'accounts/change_profile_picture/';
        boundary = self.parent.uuid;
        with open(photo,'rb') as e:
              ph=  e.read()
        bodies = {
            {
          'type' : 'form-data',
          'name' : 'ig_sig_key_version',
          'data' : Constants.SIG_KEY_VERSION,
        },
            {
          'type' : 'form-data',
          'name' : 'signed_body',

          'data' :hmac.new( Constants.IG_SIG_KEY,uData,hashlib.sha256).digest()+uData,
            },
            {
          'type'     : 'form-data',
          'name'     : 'profile_pic',
          'data'     :ph ,
          'filename' : 'profile_pic',
          'headers'  : [
            'Content-type: application/octet-stream',
            'Content-Transfer-Encoding: binary',
            ],
            },
        };
        data = self.buildBody(bodies, boundary);
        headers = {
          'Proxy-Connection': 'keep-alive',
          'Connection': 'keep-alive',
          'Accept': '*/*',
          'Content-type': 'multipart/form-data; boundary='+boundary,
          'Accept-Language': 'en-en',
          'Accept-Encoding': 'gzip, deflate',
        };
        ch =requests.Session()
        ret =requests.Request()
        req = ch.prepare_request(ret)
        req.url= endpoint
        headers['User-agent']=self.userAgent
        req.headers=headers
        cook = load_cookies(self.parent.IGDataPath+self.parent.username+'-cookies.dat')
        #curl_setopt(ch, CURLOPT_COOKIEFILE, self.parent.IGDataPath+self.parent.username+'-cookies.dat');
        #curl_setopt(ch, CURLOPT_COOKIEJAR, self.parent.IGDataPath+self.parent.username+'-cookies.dat');
        req.cookies =  cook

        req.method='POST'
        req.data=post

        if (self.parent.proxy) :
            resp = s.send(req,

            verify=False,
            proxies=self.parent.proxy,
            cert=False,

                          )
        else:
            resp = s.send(req,
            verify=False,
            cert=False)


        if (self.parent.debug):
            print "REQUEST: endpoint"
            if post:

                   print 'DATA: '+urllib.urldecode(post)


            print "RESPONSE: body\n\n";
Example #16
0
 def urldecode_rfc3986(string):
     return urllib.urldecode(string)
Example #17
0
def url_decode(url):
    return urllib.urldecode(url)
Example #18
0
 def parse(self, elt, ps):
     val = String.parse(self, elt, ps)
     return urldecode(val)
Example #19
0
 def urldecode(self, st):
     return urllib.urldecode(st)
Example #20
0
 def decode(self, text=""):
     if(type(text) == str):
         return urllib.unquote(text)
     elif(type(text) == dict):
         return urllib.urldecode(text)
     return text