Python urlparse.parse_qsl() Examples
The following are 30
code examples of urlparse.parse_qsl().
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
urlparse
, or try the search function
.
Example #1
Source File: cgi.py From jawfish with MIT License | 7 votes |
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" ib = self.innerboundary if not valid_boundary(ib): raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) self.list = [] if self.qs_on_post: for key, value in urlparse.parse_qsl(self.qs_on_post, self.keep_blank_values, self.strict_parsing): self.list.append(MiniFieldStorage(key, value)) FieldStorageClass = None klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, ib, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, ib, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
Example #2
Source File: helpers.py From sugardough with Apache License 2.0 | 7 votes |
def urlparams(url_, hash=None, **query): """Add a fragment and/or query paramaters to a URL. New query params will be appended to exising parameters, except duplicate names, which will be replaced. """ url = urlparse.urlparse(url_) fragment = hash if hash is not None else url.fragment # Use dict(parse_qsl) so we don't get lists of values. query_dict = dict(urlparse.parse_qsl(url.query)) query_dict.update(query) query_string = urlencode( [(k, v) for k, v in query_dict.items() if v is not None]) new = urlparse.ParseResult(url.scheme, url.netloc, url.path, url.params, query_string, fragment) return new.geturl()
Example #3
Source File: util.py From splunk-ref-pas-code with Apache License 2.0 | 6 votes |
def _add_query_parameter(url, name, value): """Adds a query parameter to a url. Replaces the current value if it already exists in the URL. Args: url: string, url to add the query parameter to. name: string, query parameter name. value: string, query parameter value. Returns: Updated query parameter. Does not update the url if value is None. """ if value is None: return url else: parsed = list(urlparse.urlparse(url)) q = dict(parse_qsl(parsed[4])) q[name] = value parsed[4] = urllib.urlencode(q) return urlparse.urlunparse(parsed)
Example #4
Source File: webservice.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def get_params(self): ''' Get the params ''' try: path = self.path[1:] if '?' in path: path = path.split('?', 1)[1] params = dict(urlparse.parse_qsl(path)) except Exception: params = {} if params.get('transcode'): params['transcode'] = params['transcode'].lower() == 'true' if params.get('server') and params['server'].lower() == 'none': params['server'] = None return params
Example #5
Source File: cartodb.py From qgis-cartodb with GNU General Public License v2.0 | 6 votes |
def __init__(self, key, secret, email, password, cartodb_domain, host='carto.com', protocol='https', proxy_info=None, *args, **kwargs): super(CartoDBOAuth, self).__init__(cartodb_domain, host, protocol, *args, **kwargs) self.consumer_key = key self.consumer_secret = secret consumer = oauth.Consumer(self.consumer_key, self.consumer_secret) client = oauth.Client(consumer, proxy_info=proxy_info) client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1() params = {} params["x_auth_username"] = email params["x_auth_password"] = password params["x_auth_mode"] = 'client_auth' # Get Access Token access_token_url = ACCESS_TOKEN_URL % {'user': cartodb_domain, 'domain': host, 'protocol': protocol} resp, token = client.request(access_token_url, method="POST", body=urllib.urlencode(params)) access_token = dict(urlparse.parse_qsl(token)) token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret']) # prepare client self.client = oauth.Client(consumer, token)
Example #6
Source File: oauth.py From wc-api-python with MIT License | 6 votes |
def get_oauth_url(self): """ Returns the URL with OAuth params """ params = OrderedDict() if "?" in self.url: url = self.url[:self.url.find("?")] for key, value in parse_qsl(urlparse(self.url).query): params[key] = value else: url = self.url params["oauth_consumer_key"] = self.consumer_key params["oauth_timestamp"] = self.timestamp params["oauth_nonce"] = self.generate_nonce() params["oauth_signature_method"] = "HMAC-SHA256" params["oauth_signature"] = self.generate_oauth_signature(params, url) query_string = urlencode(params) return "%s?%s" % (url, query_string)
Example #7
Source File: cgi.py From openprocurement.api with Apache License 2.0 | 6 votes |
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" ib = self.innerboundary if not valid_boundary(ib): raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) self.list = [] if self.qs_on_post: for key, value in urlparse.parse_qsl(self.qs_on_post, self.keep_blank_values, self.strict_parsing): self.list.append(MiniFieldStorage(key, value)) FieldStorageClass = None klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, ib, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, ib, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
Example #8
Source File: cgi.py From BinderFilter with MIT License | 6 votes |
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" ib = self.innerboundary if not valid_boundary(ib): raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) self.list = [] if self.qs_on_post: for key, value in urlparse.parse_qsl(self.qs_on_post, self.keep_blank_values, self.strict_parsing): self.list.append(MiniFieldStorage(key, value)) FieldStorageClass = None klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, ib, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, ib, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
Example #9
Source File: util.py From billing-export-python with Apache License 2.0 | 6 votes |
def _add_query_parameter(url, name, value): """Adds a query parameter to a url. Replaces the current value if it already exists in the URL. Args: url: string, url to add the query parameter to. name: string, query parameter name. value: string, query parameter value. Returns: Updated query parameter. Does not update the url if value is None. """ if value is None: return url else: parsed = list(urlparse.urlparse(url)) q = dict(parse_qsl(parsed[4])) q[name] = value parsed[4] = urllib.urlencode(q) return urlparse.urlunparse(parsed)
Example #10
Source File: account.py From rucio with Apache License 2.0 | 6 votes |
def GET(self): """ list all rucio accounts. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 406 Not Acceptable 500 InternalError :param Rucio-Account: Account identifier. :param Rucio-Auth-Token: as an 32 character hex string. :returns: A list containing all account names as dict. """ header('Content-Type', 'application/x-json-stream') filter = {} if ctx.query: filter = dict(parse_qsl(ctx.query[1:])) for account in list_accounts(filter=filter): yield render_json(**account) + "\n"
Example #11
Source File: tools.py From billing-export-python with Apache License 2.0 | 6 votes |
def do_GET(s): """Handle a GET request. Parses the query parameters and prints a message if the flow has completed. Note that we can't detect if an error occurred. """ s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() query = s.path.split('?', 1)[-1] query = dict(parse_qsl(query)) s.server.query_params = query s.wfile.write("<html><head><title>Authentication Status</title></head>") s.wfile.write("<body><p>The authentication flow has completed.</p>") s.wfile.write("</body></html>")
Example #12
Source File: pundle.py From pundler with BSD 2-Clause "Simplified" License | 6 votes |
def parse_vcs_requirement(req): """Parses VCS line to egg name, version etc. """ if '+' not in req: return None vcs, url = req.split('+', 1) if vcs not in ('git', 'svn', 'hg'): return None parsed_url = urlparse(url) parsed = dict(parse_qsl(parsed_url.fragment)) if 'egg' not in parsed: return None egg = parsed['egg'].rsplit('-', 1) if len(egg) > 1: try: pkg_resources_parse_version(egg[1]) except pkg_resources._vendor.packaging.version.InvalidVersion: return parsed['egg'].lower(), req, None return egg[0].lower(), req, egg[1] else: return parsed['egg'].lower(), req, None
Example #13
Source File: account.py From rucio with Apache License 2.0 | 6 votes |
def GET(self): """ list all rucio accounts. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 406 Not Acceptable 500 InternalError :param Rucio-Account: Account identifier. :param Rucio-Auth-Token: as an 32 character hex string. :returns: A list containing all account names as dict. """ header('Content-Type', 'application/x-json-stream') filter = {} if ctx.query: filter = dict(parse_qsl(ctx.query[1:])) for account in list_accounts(filter=filter): yield render_json(**account) + "\n"
Example #14
Source File: util.py From earthengine with MIT License | 6 votes |
def _add_query_parameter(url, name, value): """Adds a query parameter to a url. Replaces the current value if it already exists in the URL. Args: url: string, url to add the query parameter to. name: string, query parameter name. value: string, query parameter value. Returns: Updated query parameter. Does not update the url if value is None. """ if value is None: return url else: parsed = list(urlparse.urlparse(url)) q = dict(urlparse.parse_qsl(parsed[4])) q[name] = value parsed[4] = urllib.urlencode(q) return urlparse.urlunparse(parsed)
Example #15
Source File: tools.py From earthengine with MIT License | 6 votes |
def do_GET(self): """Handle a GET request. Parses the query parameters and prints a message if the flow has completed. Note that we can't detect if an error occurred. """ self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() query = self.path.split('?', 1)[-1] query = dict(urlparse.parse_qsl(query)) self.server.query_params = query self.wfile.write("<html><head><title>Authentication Status</title></head>") self.wfile.write("<body><p>The authentication flow has completed.</p>") self.wfile.write("</body></html>")
Example #16
Source File: tools.py From sndlatr with Apache License 2.0 | 6 votes |
def do_GET(s): """Handle a GET request. Parses the query parameters and prints a message if the flow has completed. Note that we can't detect if an error occurred. """ s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() query = s.path.split('?', 1)[-1] query = dict(parse_qsl(query)) s.server.query_params = query s.wfile.write("<html><head><title>Authentication Status</title></head>") s.wfile.write("<body><p>The authentication flow has completed.</p>") s.wfile.write("</body></html>")
Example #17
Source File: cgi.py From pmatic with GNU General Public License v2.0 | 6 votes |
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" ib = self.innerboundary if not valid_boundary(ib): raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) self.list = [] if self.qs_on_post: for key, value in urlparse.parse_qsl(self.qs_on_post, self.keep_blank_values, self.strict_parsing): self.list.append(MiniFieldStorage(key, value)) FieldStorageClass = None klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, ib, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, ib, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
Example #18
Source File: util.py From sndlatr with Apache License 2.0 | 6 votes |
def _add_query_parameter(url, name, value): """Adds a query parameter to a url. Replaces the current value if it already exists in the URL. Args: url: string, url to add the query parameter to. name: string, query parameter name. value: string, query parameter value. Returns: Updated query parameter. Does not update the url if value is None. """ if value is None: return url else: parsed = list(urlparse.urlparse(url)) q = dict(parse_qsl(parsed[4])) q[name] = value parsed[4] = urllib.urlencode(q) return urlparse.urlunparse(parsed)
Example #19
Source File: cgi.py From meddle with MIT License | 6 votes |
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" ib = self.innerboundary if not valid_boundary(ib): raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) self.list = [] if self.qs_on_post: for key, value in urlparse.parse_qsl(self.qs_on_post, self.keep_blank_values, self.strict_parsing): self.list.append(MiniFieldStorage(key, value)) FieldStorageClass = None klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, ib, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, ib, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
Example #20
Source File: oauth_providers.py From kansha with BSD 3-Clause "New" or "Revised" License | 6 votes |
def fetch(self, url, post=False, headers=None, **kw): params = urllib.urlencode(kw) if params and not post: url += ('?' + params) request = urllib2.Request(url, params if post else None, headers or {}) if self.timeout: response = urllib2.urlopen(request, timeout=self.timeout) else: response = urllib2.urlopen(request) content_type = response.info().getheader('content-type').split(';')[0] data = response.read() response.close() if response.getcode() != 200: return None return json.loads(data)if content_type in ('application/json', 'text/javascript') else dict(urlparse.parse_qsl(data))
Example #21
Source File: tools.py From splunk-ref-pas-code with Apache License 2.0 | 6 votes |
def do_GET(s): """Handle a GET request. Parses the query parameters and prints a message if the flow has completed. Note that we can't detect if an error occurred. """ s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() query = s.path.split('?', 1)[-1] query = dict(parse_qsl(query)) s.server.query_params = query s.wfile.write("<html><head><title>Authentication Status</title></head>") s.wfile.write("<body><p>The authentication flow has completed.</p>") s.wfile.write("</body></html>")
Example #22
Source File: cgi.py From oss-ftp with MIT License | 6 votes |
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" ib = self.innerboundary if not valid_boundary(ib): raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) self.list = [] if self.qs_on_post: for key, value in urlparse.parse_qsl(self.qs_on_post, self.keep_blank_values, self.strict_parsing): self.list.append(MiniFieldStorage(key, value)) FieldStorageClass = None klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, ib, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, ib, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
Example #23
Source File: test_search.py From arxiv.py with MIT License | 6 votes |
def get_parse_callable(): class Result(dict): def get(self, k): return 200 def parse(url): for k, v in parse_qsl(url.split("?")[1]): if k == "max_results": max_result = int(v) result = Result() result['entries'] = [ get_random_arxiv_entry() for _ in range(max_result)] return result return parse
Example #24
Source File: cgi.py From oss-ftp with MIT License | 5 votes |
def read_urlencoded(self): """Internal: read data in query string format.""" qs = self.fp.read(self.length) if self.qs_on_post: qs += '&' + self.qs_on_post self.list = list = [] for key, value in urlparse.parse_qsl(qs, self.keep_blank_values, self.strict_parsing): list.append(MiniFieldStorage(key, value)) self.skip_lines()
Example #25
Source File: test_urlparse.py From BinderFilter with MIT License | 5 votes |
def test_qsl(self): for orig, expect in parse_qsl_test_cases: result = urlparse.parse_qsl(orig, keep_blank_values=True) self.assertEqual(result, expect, "Error parsing %r" % orig) expect_without_blanks = [v for v in expect if len(v[1])] result = urlparse.parse_qsl(orig, keep_blank_values=False) self.assertEqual(result, expect_without_blanks, "Error parsing %r" % orig)
Example #26
Source File: oauth_providers.py From kansha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __call__(self, environ, start_response): params = dict(urlparse.parse_qsl(environ['QUERY_STRING'])) if ('state' in params): environ['QUERY_STRING'] += ('&' + params['state']) return self.app(environ, start_response)
Example #27
Source File: client.py From billing-export-python with Apache License 2.0 | 5 votes |
def _update_query_params(uri, params): """Updates a URI with new query parameters. Args: uri: string, A valid URI, with potential existing query parameters. params: dict, A dictionary of query parameters. Returns: The same URI but with the new query parameters added. """ parts = list(urlparse.urlparse(uri)) query_params = dict(parse_qsl(parts[4])) # 4 is the index of the query part query_params.update(params) parts[4] = urllib.urlencode(query_params) return urlparse.urlunparse(parts)
Example #28
Source File: cgi.py From BinderFilter with MIT License | 5 votes |
def read_urlencoded(self): """Internal: read data in query string format.""" qs = self.fp.read(self.length) if self.qs_on_post: qs += '&' + self.qs_on_post self.list = list = [] for key, value in urlparse.parse_qsl(qs, self.keep_blank_values, self.strict_parsing): list.append(MiniFieldStorage(key, value)) self.skip_lines()
Example #29
Source File: cgi.py From BinderFilter with MIT License | 5 votes |
def parse_qsl(qs, keep_blank_values=0, strict_parsing=0): """Parse a query given as a string argument.""" warn("cgi.parse_qsl is deprecated, use urlparse.parse_qsl instead", PendingDeprecationWarning, 2) return urlparse.parse_qsl(qs, keep_blank_values, strict_parsing)
Example #30
Source File: client.py From billing-export-python with Apache License 2.0 | 5 votes |
def _parse_exchange_token_response(content): """Parses response of an exchange token request. Most providers return JSON but some (e.g. Facebook) return a url-encoded string. Args: content: The body of a response Returns: Content as a dictionary object. Note that the dict could be empty, i.e. {}. That basically indicates a failure. """ resp = {} try: resp = simplejson.loads(content) except StandardError: # different JSON libs raise different exceptions, # so we just do a catch-all here resp = dict(parse_qsl(content)) # some providers respond with 'expires', others with 'expires_in' if resp and 'expires' in resp: resp['expires_in'] = resp.pop('expires') return resp