Python cgi.parse_qs() Examples

The following are 30 code examples of cgi.parse_qs(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cgi , or try the search function .
Example #1
Source File: escape.py    From honeything with GNU General Public License v3.0 6 votes vote down vote up
def parse_qs_bytes(qs, keep_blank_values=False, strict_parsing=False):
        """Parses a query string like urlparse.parse_qs, but returns the
        values as byte strings.

        Keys still become type str (interpreted as latin1 in python3!)
        because it's too painful to keep them as byte strings in
        python3 and in practice they're nearly always ascii anyway.
        """
        # This is gross, but python3 doesn't give us another way.
        # Latin1 is the universal donor of character encodings.
        result = parse_qs(qs, keep_blank_values, strict_parsing,
                          encoding='latin1', errors='strict')
        encoded = {}
        for k, v in result.iteritems():
            encoded[k] = [i.encode('latin1') for i in v]
        return encoded 
Example #2
Source File: Interaction.py    From pilot with Apache License 2.0 6 votes vote down vote up
def waitMessage(self):
        try:
            if self.getRank() == 0:
                ansData = self.recvQueue.get(True, timeout=0.0001)
            else:
                # wait for message from Rank 0
                # if self.comm.Iprobe(source=0):
                #    time.sleep(0.0001)
                # get the answer
                ansData = self.comm.Irecv(source=0)
            # decode
            #answer = cgi.parse_qs(ansData)
            answer = json.loads(ansData)
            return True,answer
        except:
            errtype,errvalue = sys.exc_info()[:2]
            errMsg = 'failed to receive msg with: %s' % traceback.format_exc()
            return False,errMsg 
Example #3
Source File: escape.py    From bottle-auth with MIT License 6 votes vote down vote up
def parse_qs_bytes(qs, keep_blank_values=False, strict_parsing=False):
        """Parses a query string like urlparse.parse_qs, but returns the
        values as byte strings.

        Keys still become type str (interpreted as latin1 in python3!)
        because it's too painful to keep them as byte strings in
        python3 and in practice they're nearly always ascii anyway.
        """
        # This is gross, but python3 doesn't give us another way.
        # Latin1 is the universal donor of character encodings.
        result = parse_qs(qs, keep_blank_values, strict_parsing,
                          encoding='latin1', errors='strict')
        encoded = {}
        for k,v in result.iteritems():
            encoded[k] = [i.encode('latin1') for i in v]
        return encoded 
Example #4
Source File: model.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def _decode_payload(cls, body):
    compressed_payload_str = None
    if body.startswith(cls.PAYLOAD_KEY_PARAM):
      payload_key = body[len(cls.PAYLOAD_KEY_PARAM):]
      payload_entity = _HugeTaskPayload.get(payload_key)
      compressed_payload_str = payload_entity.payload
    elif body.startswith(cls.PAYLOAD_PARAM):
      compressed_payload_str = body[len(cls.PAYLOAD_PARAM):]

    if compressed_payload_str:
      payload_str = zlib.decompress(compressed_payload_str)
    else:
      payload_str = body

    result = {}
    for (name, value) in cgi.parse_qs(payload_str).items():
      if len(value) == 1:
        result[name] = value[0]
      else:
        result[name] = value
    return result 
Example #5
Source File: S3ObjectstorePresignedURLSiteMover.py    From pilot with Apache License 2.0 6 votes vote down vote up
def getPandaProxyRemotePath(self, pandaID, filename, jobSetID, pandaProxySecretKey=None, stageIn=False):
        try:
            if not pandaProxySecretKey or pandaProxySecretKey == "":
                return PilotErrors.ERR_GETKEYPAIR, "Failed to get panda proxy secret key"
            
            data = {'pandaID': pandaID,
                    'secretKey': pandaProxySecretKey,
                    'publicKey': 'publicKey:%s' % self.public_key,
                    'privateKey': 'privateKey:%s' % self.private_key,
                    'url':'%s/%s/%s/%s' % (self.os_endpoint, self.os_bucket_endpoint, jobSetID, filename)}

            if stageIn:
                data['method'] = 'GET'

            res = requests.post(self.pandaProxy+'/getPresignedURL',data=data)
            if res.status_code == 200:
                tmpDict = cgi.parse_qs(res.text.encode('ascii'))
                if int(tmpDict['StatusCode'][0]) == 0:
                    return int(tmpDict['StatusCode'][0]), "", tmpDict['presignedURL'][0]
                else:
                    return int(tmpDict['StatusCode'][0]), tmpDict['ErrorMsg'][0], None
            return PilotErrors.ERR_UNKNOWN, "Failed to get remote path (presigned  url): %s" % res.text, None
        except:
            return PilotErrors.ERR_UNKNOWN, "Failed to get remote path (presigned url): %s" % traceback.format_exc(), None 
Example #6
Source File: S3ObjectstorePresignedURLSiteMover.py    From pilot with Apache License 2.0 6 votes vote down vote up
def getPandaProxyRemoteFileInfo(self, pandaID, filename, jobSetID, pandaProxySecretKey=None):
        try:
            if not pandaProxySecretKey or pandaProxySecretKey == "":
                return PilotErrors.ERR_GETKEYPAIR, "Failed to get panda proxy secret key"

            data = {'pandaID': pandaID,
                    'secretKey': pandaProxySecretKey,
                    'publicKey': 'publicKey:%s' % self.public_key,
                    'privateKey': 'privateKey:%s' % self.private_key,
                    'url':'%s/%s/%s/%s' % (self.os_endpoint, self.os_bucket_endpoint, jobSetID, filename)}

            res = requests.post(self.pandaProxy+'/getFileInfo',data=data)
            if res.status_code == 200:
                tmpDict = cgi.parse_qs(res.text.encode('ascii'))
                if int(tmpDict['StatusCode'][0]) == 0:
                    size, checksum = json.loads(tmpDict['fileInfo'][0])
                    return int(tmpDict['StatusCode'][0]), "", size, checksum
                else:
                    return int(tmpDict['StatusCode'][0]), tmpDict['ErrorMsg'][0], None, None
            return PilotErrors.ERR_UNKNOWN, "Failed to get remote file info: %s" % res.text, None, None
        except:
            return PilotErrors.ERR_UNKNOWN, "Failed to get remote file info: %s" % traceback.format_exc(), None, None 
Example #7
Source File: test_support.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def decode_task_payload(task):
  """Decodes POST task payload.

  This can only decode POST payload for a normal task. For huge task,
  use model.HugeTask.decode_payload.

  Args:
    task: a dict representing a taskqueue task as documented in taskqueue_stub.

  Returns:
    parameter_name -> parameter_value dict. If multiple parameter values are
    present, then parameter_value will be a list.
  """
  if not task:
    return {}
  # taskqueue_stub base64 encodes body when it returns the task to us.
  body = base64.b64decode(task["body"])
  result = {}
  for (name, value) in cgi.parse_qs(body).items():
    if len(value) == 1:
      result[name] = value[0]
    else:
      result[name] = value
  return result 
Example #8
Source File: addon.py    From plugin.video.sparkle with GNU General Public License v3.0 6 votes vote down vote up
def parse_query(self, query, defaults={'mode': 'main'}):
        '''
        Parse a query string as used in a URL or passed to your addon by XBMC.
        
        Example:
         
        >>> addon.parse_query('name=test&type=basic')
        {'mode': 'main', 'name': 'test', 'type': 'basic'} 
            
        Args:
            query (str): A query string.
            
        Kwargs:
            defaults (dict): A dictionary containing key/value pairs parsed 
            from the query string. If a key is repeated in the query string
            its value will be a list containing all of that keys values.  
        '''
        queries = cgi.parse_qs(query)
        q = defaults
        for key, value in queries.items():
            if len(value) == 1:
                q[key] = value[0]
            else:
                q[key] = value
        return q 
Example #9
Source File: GenerationServer.py    From dcept with GNU General Public License v3.0 6 votes vote down vote up
def do_POST(s):
		length = int(s.headers['content-length'])
		postvars = cgi.parse_qs(s.rfile.read(length), keep_blank_values=1)

		logging.debug(postvars)

		try:					
			username     = postvars['u'][0]
			domain		 = postvars['d'][0]
			encTimestamp = postvars['t'][0]
		except:		
			s.send_response(500)
			s.end_headers()	
			return		

		cracker.enqueueJob(username, domain, encTimestamp, dcept.passwordHit)		

		s.send_response(200)
		s.end_headers() 
Example #10
Source File: model.py    From locality-sensitive-hashing with MIT License 6 votes vote down vote up
def _decode_payload(cls, body):
    compressed_payload_str = None
    if body.startswith(cls.PAYLOAD_KEY_PARAM):
      payload_key = body[len(cls.PAYLOAD_KEY_PARAM):]
      payload_entity = _HugeTaskPayload.get(payload_key)
      compressed_payload_str = payload_entity.payload
    elif body.startswith(cls.PAYLOAD_PARAM):
      compressed_payload_str = body[len(cls.PAYLOAD_PARAM):]

    if compressed_payload_str:
      payload_str = zlib.decompress(compressed_payload_str)
    else:
      payload_str = body

    result = {}
    for (name, value) in cgi.parse_qs(payload_str).items():
      if len(value) == 1:
        result[name] = value[0]
      else:
        result[name] = value
    return result 
Example #11
Source File: http.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
    """
    Like C{cgi.parse_qs}, but with support for parsing byte strings on Python 3.

    @type qs: C{bytes}
    """
    d = {}
    items = [s2 for s1 in qs.split(b"&") for s2 in s1.split(b";")]
    for item in items:
        try:
            k, v = item.split(b"=", 1)
        except ValueError:
            if strict_parsing:
                raise
            continue
        if v or keep_blank_values:
            k = unquote(k.replace(b"+", b" "))
            v = unquote(v.replace(b"+", b" "))
            if k in d:
                d[k].append(v)
            else:
                d[k] = [v]
    return d 
Example #12
Source File: poetrygenerator.py    From poetry-generator with MIT License 6 votes vote down vote up
def redirect_to_poem(environ, start_response):
    # We might have a POST body indicating the poem type; try to read it.

    # The environment variable CONTENT_LENGTH may be empty or missing
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0

    # Read and parse the HTTP request body which is passed by the WSGI server
    request_body = environ['wsgi.input'].read(request_body_size)
    poemtype = None
    qs = parse_qs(request_body)
    if qs:
        poemtype = qs.get('poemtype')[0]
    if poemtype != 'mushypoem':
        poemtype = 'poem'

    seed = os.urandom(8).encode('hex')

    start_response('302 Found', [
        ('Location', '/' + poemtype + '/' + seed)
    ])

    return [] 
Example #13
Source File: facebook.py    From django-simple-forum with MIT License 6 votes vote down vote up
def extend_access_token(self, app_id, app_secret):
        """
        Extends the expiration time of a valid OAuth access token. See
        <https://developers.facebook.com/roadmap/offline-access-removal/
        #extend_token>

        """
        args = {
            "client_id": app_id,
            "client_secret": app_secret,
            "grant_type": "fb_exchange_token",
            "fb_exchange_token": self.access_token,
        }
        response = urllib2.urlopen("https://graph.facebook.com/oauth/"
                                   "access_token?" +
                                   urllib.parse.urlencode(args)).read().decode('utf-8')
        query_str = parse_qs(response)
        if "access_token" in query_str:
            result = {"accesstoken": query_str["access_token"][0]}
            if "expires" in query_str:
                result["expire"] = query_str["expires"][0]
            return result
        else:
            response = json.loads(response)
            raise GraphAPIError(response) 
Example #14
Source File: facebook.py    From django-simple-forum with MIT License 6 votes vote down vote up
def get_access_token_from_code(code, redirect_uri, app_id, app_secret):

    args = {
        "code": code,
        "redirect_uri": redirect_uri,
        "client_id": app_id,
        "client_secret": app_secret,
    }
    # We would use GraphAPI.request() here, except for that the fact
    # that the response is a key-value pair, and not JSON.
    response = urllib2.urlopen("https://graph.facebook.com/oauth/access_token" +
                              "?" + urllib.parse.urlencode(args)).read().decode('utf-8')
    query_str = parse_qs(response)
    if "access_token" in query_str:
        result = {"access_token": query_str["access_token"][0]}
        if "expires" in query_str:
            result["expires"] = query_str["expires"][0]
        return result
    else:
        jsonResponse = json.loads(str(response))
        # response = json.loads(response)
        encoding = response.info().get_content_charset('utf8')
        data = json.loads(response.read().decode(encoding))
        return data 
Example #15
Source File: URL.py    From teye_scanner_for_book with GNU General Public License v3.0 6 votes vote down vote up
def parse_qs(url_encoded_string, ignoreExceptions=True,encoding=DEFAULT_ENCODING):
	'''
	'''
	parsed_qs = None
	result = querystring(encoding=encoding)

	if url_encoded_string:
		try:
			parsed_qs = cgi.parse_qs(url_encoded_string,keep_blank_values=True,strict_parsing=False)
		except Exception:
			if not ignoreExceptions:
				raise 'Strange things found when parsing query string: "%s"' % url_encoded_string
		else:
			for p, v in parsed_qs.iteritems():
				if type(v) is not list:
					v = [v]
				result[p] = v

	return result 
Example #16
Source File: Search.py    From p2ptv-pi with MIT License 6 votes vote down vote up
def get(self, urlpath):
        if not urlpath.startswith(URLPATH_SEARCH_PREFIX):
            return streaminfo404()
        fakeurl = 'http://127.0.0.1' + urlpath
        o = urlparse.urlparse(fakeurl)
        qdict = cgi.parse_qs(o[4])
        if DEBUG:
            print >> sys.stderr, 'searchmap: qdict', qdict
        searchstr = qdict['q'][0]
        searchstr = searchstr.strip()
        collection = qdict['collection'][0]
        metafeedurl = qdict['metafeed'][0]
        print >> sys.stderr, '\nbg: search: Got search for', `searchstr`, 'in', collection
        self.id2hits.garbage_collect_timestamp_smaller(time.time() - HITS_TIMEOUT)
        if collection == 'metafeed':
            if not self.check_reload_metafeed(metafeedurl):
                return {'statuscode': 504,
                 'statusmsg': '504 MetaFeed server did not respond'}
            return self.process_search_metafeed(searchstr)
        else:
            return self.process_search_p2p(searchstr) 
Example #17
Source File: views.py    From MobileSF with GNU General Public License v3.0 6 votes vote down vote up
def findBodyType(request):
    bd_typ ="none"
    try:
        if request["body"]:
            try:
                json.loads(request["body"])
                bd_typ ="json"
            except:
                pass
            try:
                config = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
                #Prevent Entity Expansion Attacks against the Framework
                etree.fromstring(request["body"],config)
                bd_typ ="xml"
            except:
                pass
            qs=parse_qs(request["body"])
            if qs:
                bd_typ="form"
        return bd_typ
    except:
        PrintException("[ERROR] Finding Request Body type") 
Example #18
Source File: test_views.py    From dirigible-spreadsheet with MIT License 6 votes vote down vote up
def test_copy_sheet_requires_login_for_anonymous_user(self):
        self.sheet.is_public = True
        worksheet = Worksheet()
        worksheet.a1.value = 'some-cell-content'
        self.sheet.jsonify_worksheet(worksheet)
        self.sheet.save()
        self.request.user = AnonymousUser()
        self.request.META['SERVER_NAME'] = 'servername'
        self.request.META['SERVER_PORT'] = '80'
        self.request.get_full_path = lambda: 'request-path'

        response = copy_sheet(self.request, self.user.username, self.sheet.id)

        self.assertTrue(isinstance(response, HttpResponseRedirect))

        redirect_url = urlparse(response['Location'])
        self.assertEquals(redirect_url.path, settings.LOGIN_URL)
        redirect_query_params = parse_qs(redirect_url.query)
        self.assertEquals(redirect_query_params['next'], ['request-path']) 
Example #19
Source File: http.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
    """
    Like C{cgi.parse_qs}, but with support for parsing byte strings on Python 3.

    @type qs: C{bytes}
    """
    d = {}
    items = [s2 for s1 in qs.split(b"&") for s2 in s1.split(b";")]
    for item in items:
        try:
            k, v = item.split(b"=", 1)
        except ValueError:
            if strict_parsing:
                raise
            continue
        if v or keep_blank_values:
            k = unquote(k.replace(b"+", b" "))
            v = unquote(v.replace(b"+", b" "))
            if k in d:
                d[k].append(v)
            else:
                d[k] = [v]
    return d 
Example #20
Source File: httpserver.py    From honeything with GNU General Public License v3.0 6 votes vote down vote up
def _on_request_body(self, data):
        self._request.body = data
        content_type = self._request.headers.get("Content-Type", "")
        if self._request.method == "POST":
            if content_type.startswith("application/x-www-form-urlencoded"):
                arguments = cgi.parse_qs(self._request.body)
                for name, values in arguments.iteritems():
                    values = [v for v in values if v]
                    if values:
                        self._request.arguments.setdefault(name, []).extend(
                            values)
            elif content_type.startswith("multipart/form-data"):
                if 'boundary=' in content_type:
                    boundary = content_type.split('boundary=',1)[1]
                    if boundary: self._parse_mime_body(boundary, data)
                else:
                    logging.warning("Invalid multipart/form-data")
        self.request_callback(self._request) 
Example #21
Source File: recipe-157501.py    From code with MIT License 5 votes vote down vote up
def __init__(self, path, query, header, here={}, options={}, root={},
                 user={}, restricted=0, edit_content_type='text/html'):
        head, tail = os.path.split(path)

        ## these two attributes are so common in PT markup that it would be a
        ## shame to not set them.
        self.id = tail
        self.title = "Page Template '%s'" % (tail, )

        self.here = here
        self.options = options
        self.root = root
        self.template = self
        self.user = user

        ## gather data about the folder that contains this script
        self.container = {}
        if not restricted:
            self.container.update({'is_mount' : os.path.ismount(head),
                                   'is_link' : os.path.islink(head),
                                   'files' : os.listdir(head),
                                   'name' : os.path.split(head)[-1], })
            self.container.update(dict(zip(self.stat_keys, os.stat(head))))

        ## turn a query string and/or form data in the header into a mapping
        self.request = r = {}
        if query:
            if query.startswith('?'):
                query = query[1:]
            r.update(cgi.parse_qs(query, 0, 0))
        if header:
            r.update(cgi.parse_qs(header, 0, 0))
        [r.__setitem__(k, v[0]) for k, v in r.items() if len(v) == 1]

        ## finally, read in the file as a convenience for the client
        self.pt_edit(open(path, 'r').read(), edit_content_type) 
Example #22
Source File: recipe-225299.py    From code with MIT License 5 votes vote down vote up
def set_params(self, queryString):
        """Parse CGI params into a paramset."""
        self.requestParams.flush()
        inParams = parse_qs(str(queryString), True, False)
        for eachName, eachValue in inParams.items():
            for eachSubValue in eachValue:
                self.requestParams.add_param(eachName, eachSubValue) 
Example #23
Source File: request.py    From ru with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, url, handle):
        #: The entire request url.
        self.url = url

        #: The current request's handle, an integer.
        self.handle = int(handle)

        # urlparse doesn't like the 'plugin' scheme, so pass a protocol
        # relative url, e.g. //plugin.video.helloxbmc/path
        self.scheme, remainder = url.split(':', 1)
        parts = urlparse.urlparse(remainder)
        self.netloc, self.path, self.query_string = (
            parts[1], parts[2], parts[4])
        self.args = unpickle_args(parse_qs(self.query_string)) 
Example #24
Source File: test_cgi.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_deprecated_parse_qs(self):
        # this func is moved to urllib.parse, this is just a sanity check
        with check_warnings(('cgi.parse_qs is deprecated, use urllib.parse.'
                             'parse_qs instead', DeprecationWarning)):
            self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']},
                             cgi.parse_qs('a=A1&b=B2&B=B3')) 
Example #25
Source File: views.py    From MobileSF with GNU General Public License v3.0 5 votes vote down vote up
def QSMutate(qs,typ):
    try:
        m_qs = qs
        if typ == "register":
            dict_qs = parse_qs(qs)
            for key in dict_qs:
                for val in dict_qs[key]:
                    if re.findall("%40|@",val):
                        #Do careful mutation for emails
                        m_email = choice(string.ascii_letters) + choice(string.ascii_letters) + choice(string.ascii_letters) + val[1:]
                        m_qs = m_qs.replace(val,m_email)
                    elif (len(val)> 1) and (val.lower()!= "true") and (val.lower()!="false"):
                        #Rest all thing like username, pin, password, mobile, just mutate characters
                        #String of length 1 is never mutated
                        listify = list (val)
                        shuffle(listify)
                        m_val = ''.join(listify)
                        m_qs = m_qs.replace(val,m_val)
        elif typ == "login":
            #Simple Logic - for timesake
            dict_qs = parse_qs(qs)
            for key in dict_qs:
                for val in dict_qs[key]:
                    if re.findall("pass|password|ps|userpass|pass-word",key,re.I):
                        listify = list (val)
                        shuffle(listify)
                        m_val = ''.join(listify)
                        m_qs = m_qs.replace(val,m_val)
        elif typ == "pin":
            #Simple Logic - for timesake
            dict_qs = parse_qs(qs)
            for key in dict_qs:
                for val in dict_qs[key]:
                    if re.findall("pin|passcode|cvv|code|passlock|lockcode",key,re.I):
                        listify = list (val)
                        shuffle(listify)
                        m_val = ''.join(listify)
                        m_qs = m_qs.replace(val,m_val)
        return m_qs
    except:
        PrintException("[ERROR] Mutating Query String") 
Example #26
Source File: pandaproxy_sitemover.py    From pilot with Apache License 2.0 5 votes vote down vote up
def _getPresignedUrl(self, pandaProxyURL, jobId, osPrivateKey, osPublicKey, pandaProxySecretKey, s3URL, stageIn=False):
        try:
            if not pandaProxySecretKey or pandaProxySecretKey == "":
                raise PilotException("Panda proxy secret key is not set for panda proxy operations")

            data = {'pandaID': jobId,
                    'secretKey':'%s' % pandaProxySecretKey,
                    'publicKey': 'publicKey:%s' % osPublicKey,
                    'privateKey': 'privateKey:%s' % osPrivateKey,
                    'url':'%s' % s3URL}
            if stageIn:
                data['method'] = 'GET'


            requestedURL = pandaProxyURL+'/getPresignedURL'
            self.log("agb: get presinged url: requested url='%s',  data=%s" % (requestedURL, data) )

            res = requests.post(requestedURL, data=data)
            self.log("result=%s" % res)
            self.log("res.text.encode('ascii') = %s" % res.text.encode('ascii'))
            if res.status_code == 200:
                tmpDict = cgi.parse_qs(res.text.encode('ascii'))
                if int(tmpDict['StatusCode'][0]) == 0:
                    return tmpDict['presignedURL'][0]
                else:
                    raise PilotException( "get remote path presigned url from panda proxy error %s: %s" % (tmpDict['StatusCode'][0], tmpDict['ErrorMsg'][0]) )
            raise PilotException( "failed to get remote path presigned url from panda proxy, status code:  %s" % res.status_code)
        except Exception as e:
            raise PilotException( "failure when get presigned url from panda proxy: %s" % str(e)) 
Example #27
Source File: auth.py    From honeything with GNU General Public License v3.0 5 votes vote down vote up
def _oauth_parse_response(body):
    p = cgi.parse_qs(body, keep_blank_values=False)
    token = dict(key=p["oauth_token"][0], secret=p["oauth_token_secret"][0])

    # Add the extra parameters the Provider included to the token
    special = ("oauth_token", "oauth_token_secret")
    token.update((k, p[k][0]) for k in p if k not in special)
    return token 
Example #28
Source File: httpserver.py    From honeything with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, method, uri, version="HTTP/1.0", headers=None,
                 body=None, remote_ip=None, protocol=None, host=None,
                 files=None, connection=None):
        self.method = method
        self.uri = uri
        self.version = version
        self.headers = headers or httputil.HTTPHeaders()
        self.body = body or ""
        if connection and connection.xheaders:
            # Squid uses X-Forwarded-For, others use X-Real-Ip
            self.remote_ip = self.headers.get(
                "X-Real-Ip", self.headers.get("X-Forwarded-For", remote_ip))
            self.protocol = self.headers.get("X-Scheme", protocol) or "http"
        else:
            self.remote_ip = remote_ip
            self.protocol = protocol or "http"
        self.host = host or self.headers.get("Host") or "127.0.0.1"
        self.files = files or {}
        self.connection = connection
        self._start_time = time.time()
        self._finish_time = None

        scheme, netloc, path, query, fragment = urlparse.urlsplit(uri)
        self.path = path
        self.query = query
        arguments = cgi.parse_qs(query)
        self.arguments = {}
        for name, values in arguments.iteritems():
            values = [v for v in values if v]
            if values: self.arguments[name] = values 
Example #29
Source File: EventRangesPandaProxy.py    From pilot with Apache License 2.0 5 votes vote down vote up
def downloadEventRangesPandaProxy(jobId, jobsetId, pandaProxySecretKey):
    """ Download event ranges from the Panda proxy """

    tolog("pp: start to download new event ranges for jobId=%s, jobsetId=%s" % (jobId, jobsetId))

            
    data = {
        'pandaID' : jobId, 
        'jobsetID':jobsetId,
        'secretKey':pandaProxySecretKey,
        'baseURL':envPandaServerURL()
        }
    postURL = envPandaProxyURL()+'/getEventRanges'
    tolog( "pp: POST url: '%s', request data=%s" % (postURL,data))
    res = requests.post(postURL, data)
    if res.status_code != 200:
        tolog('pp: downloadEventRangesPandaProxy request failed, ret status: %s' % res.status_code )
        message = "Failed to download event range - error code = %d" % (res.status_code)
    else:
        tolog("pp: res=%s" % res)
        tolog("pp: res.text.encode('ascii') = %s" % res.text.encode('ascii'))
        tmpDict =  cgi.parse_qs(res.text.encode('ascii'))
        tolog("pp: tmpDict = %s" % tmpDict)
        #resCgiParsed = {'eventRanges': ['[{\"eventRangeID\": \"10204500-3123350504-7783643170-1-10\", \"LFN\": \"EVNT.01416937._000001.pool.root.1\", \"lastEvent\": 1, \"startEvent\": 1, \"scope\": \"valid1\", \"GUID\": \"1141217E-433C-3E47-8898-615B968DA5E5\"}, {\"eventRangeID\": \"10204500-3123350504-7783643170-2-10\", \"LFN\": \"EVNT.01416937._000001.pool.root.1\", \"lastEvent\": 2, \"startEvent\": 2, \"scope\": \"valid1\", \"GUID\": \"1141217E-433C-3E47-8898-615B968DA5E5\"}, {\"eventRangeID\": \"10204500-3123350504-7783643170-3-10\", \"LFN\": \"EVNT.01416937._000001.pool.root.1\", \"lastEvent\": 3, \"startEvent\": 3, \"scope\": \"valid1\", \"GUID\": \"1141217E-433C-3E47-8898-615B968DA5E5\"}, {\"eventRangeID\": \"10204500-3123350504-7783643170-4-10\", \"LFN\": \"EVNT.01416937._000001.pool.root.1\", \"lastEvent\": 4, \"startEvent\": 4, \"scope\": \"valid1\", \"GUID\": \"1141217E-433C-3E47-8898-615B968DA5E5\"}]'], 'StatusCode': ['0']}
        retStatus = int(tmpDict['StatusCode'][0])
        if  retStatus== 0:
            message = tmpDict['eventRanges'][0]
            tolog('pp: downloadEventRangesPandaProxy ranges: %s' % message)
        else:
            message = "Failed to download event range from panda proxy - error code = %d" % statusCode
            tolog('pp: download event range: panda proxy returned error: %s' % statusCode)
    if message == "" or message == "[]":
        tolog('pp: no more events' )
        message = "No more events"
    tolog("pp: return =>message<= : =>%s<= type: %s" % (message, type(message)))
    return message 
Example #30
Source File: URL.py    From teye_scanner_for_book with GNU General Public License v3.0 5 votes vote down vote up
def get_querystring( self, ignoreExceptions=True ):
		'''
		'''
		return parse_qs(self.qs, ignoreExceptions=True,encoding=self._encoding)