Python urlparse.unquote() Examples
The following are 26
code examples of urlparse.unquote().
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: views.py From DjanGoat with MIT License | 6 votes |
def check_if_valid_token(request): if 'HTTP_AUTHORIZATION' not in request.META: return False else: token = urlparse.unquote(request.META['HTTP_AUTHORIZATION']) regex = re.compile("(.*?)-(.*)") split_token = token.split('=')[1] regex_groups = regex.search(split_token) if regex_groups.group(1): group_id = regex_groups.group(1) else: return False if regex_groups.group(2): group_hash = regex_groups.group(2) else: return False sha = SHA.new() sha.update(ACCESS_TOKEN_SALT + ":" + str(group_id)) return group_hash == sha.hexdigest()
Example #2
Source File: views.py From DjanGoat with MIT License | 6 votes |
def api_index(request): if check_if_valid_token(request): try: token = urlparse.unquote(request.META['HTTP_AUTHORIZATION']) user_id = extrapolate_user(token) user = User.objects.get(user_id=user_id) if user.is_admin: data = serializers.serialize("json", User.objects.all()) return HttpResponse(data, content_type='application/json') else: data = serializers.serialize("json", User.objects.filter(user_id=user_id)) return HttpResponse(data, content_type='application/json') except User.DoesNotExist: return HttpResponse("null", content_type='application/json') else: return HttpResponse('Unauthorized', status=401)
Example #3
Source File: proxy.py From xbmc with GNU General Public License v3.0 | 6 votes |
def do_GET(self): """Respond to GET requests""" try: from urllib.parse import unquote except ImportError: from urlparse import unquote path, headers, data = self._ParseBaseRequest('GET') if None is path: return if ('mpd' == path[0]) and (2 == len(path)): self._AlterMPD(unquote(path[1]), headers, data) elif ('subtitles' == path[0]) and (3 == len(path)): self._TranscodeSubtitle(unquote(path[1]), headers, data, path[2]) else: Log('[PS] Invalid request received', Log.DEBUG) self.send_error(501, 'Invalid request')
Example #4
Source File: proxy.py From xbmc with GNU General Public License v3.0 | 6 votes |
def do_POST(self): """Respond to POST requests""" try: from urllib.parse import unquote except ImportError: from urlparse import unquote path, headers, data = self._ParseBaseRequest('POST') if None is path: return if ('gpr' == path[0]) and (2 == len(path)): self._AlterGPR(unquote(path[1]), headers, data) else: Log('[PS] Invalid request received', Log.DEBUG) self.send_error(501, 'Invalid request')
Example #5
Source File: proxy.py From xbmc with GNU General Public License v3.0 | 6 votes |
def _ParseBaseRequest(self, method): """Return path, headers and post data commonly required by all methods""" try: from urllib.parse import unquote, urlparse, parse_qsl except ImportError: from urlparse import unquote, urlparse, parse_qsl path = py2_decode(urlparse(self.path).path[1:]) # Get URI without the trailing slash path = path.split('/') # license/<asin>/<ATV endpoint> Log('[PS] Requested {} path {}'.format(method, path), Log.DEBUG) # Retrieve headers and data headers = {k: self.headers[k] for k in self.headers if k not in ['host', 'content-length']} data_length = self.headers.get('content-length') data = {k: v for k, v in parse_qsl(self.rfile.read(int(data_length)))} if data_length else None return (path, headers, data)
Example #6
Source File: yum.py From atomic-reactor with BSD 3-Clause "New" or "Revised" License | 6 votes |
def filename(self): '''Returns the filename to be used for saving the repo file. The filename is derived from the repo url by injecting a suffix after the name and before the file extension. This suffix is a partial md5 checksum of the full repourl. This avoids multiple repos from being written to the same file. ''' urlpath = unquote(urlsplit(self.repourl, allow_fragments=False).path) basename = os.path.basename(urlpath) if not basename.endswith(REPO_SUFFIX): basename += REPO_SUFFIX if self.add_hash: suffix = '-' + md5(self.repourl.encode('utf-8')).hexdigest()[:5] # nosec else: suffix = '' final_name = suffix.join(os.path.splitext(basename)) return final_name
Example #7
Source File: device_proxy.py From a10sdk-python with Apache License 2.0 | 6 votes |
def GET(self, obj, query_params=None): # Replace the a10_url with just the base path, stripping out any previous querystring parse_result = urlparse.urlparse(obj.a10_url) obj.a10_url = parse_result.path obj.a10_url = self.url_encoder(obj.a10_url) if query_params: obj.a10_url += '?' + urlparse.unquote(urllib.urlencode(query_params)) conn = self.get_connection() conn.request("GET", obj.a10_url, "", self.headers) response = conn.getresponse() conn.close() obj.__setattr__("DEBUG_CONNECTION", conn.__dict__) obj.__setattr__("DEBUG_Payload", "") obj.__setattr__("DEBUG_Response", response) obj.__setattr__("DEBUG_URL", obj.a10_url) obj.__setattr__("DEBUG_headers", self.headers) return self.request_handler("GET", obj, response) # TODO: Due to Bug 175975, add zero_length kwarg to optionally send zero-length POST. Remove code once bug resolved
Example #8
Source File: storage.py From nidaba with GNU General Public License v2.0 | 5 votes |
def get_storage_path_url(url): """ Returns the file tuple for an API server URL Args: url (unicode): API server URL Returns: (unicode, unicode): file tuple """ o = urlparse.urlsplit(url)[2] return get_storage_path(_sanitize_path(nidaba_cfg['storage_path'], urlparse.unquote(os.path.join(*o.split('/')[4:]))))
Example #9
Source File: views.py From DjanGoat with MIT License | 5 votes |
def api(request, id_number): # pylint: disable=unused-argument if check_if_valid_token(request): token = urlparse.unquote(request.META['HTTP_AUTHORIZATION']) user_id = extrapolate_user(token) data = serializers.serialize("json", User.objects.filter(user_id=user_id)) return HttpResponse(data, content_type='application/json') else: return HttpResponse('Unauthorized', status=401) # This is purposely vulnerable see - https://github.com/OWASP/railsgoat/wiki/Extras:-Broken-Regular-Expression
Example #10
Source File: utils.py From dwc_network_server_emulator with GNU Affero General Public License v3.0 | 5 votes |
def qs_to_dict(s): """Convert query string to dict.""" ret = urlparse.parse_qs(s, True) for k, v in ret.items(): try: # I'm not sure about the replacement for '-', but it'll at # least let it be decoded. # For the most part it's not important since it's mostly # used for the devname/ingamesn fields. ret[k] = base64.b64decode(urlparse.unquote(v[0]) .replace("*", "=") .replace("?", "/") .replace(">", "+") .replace("-", "/")) except TypeError: """ print("Could not decode following string: ret[%s] = %s" % (k, v[0])) print("url: %s" % s) """ # If you don't assign it like this it'll be a list, which # breaks other code. ret[k] = v[0] return ret
Example #11
Source File: ClonedResourceDetails.py From WebTrap with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_relative_file_path(self): resource_url = urlparse.urlparse(self.resource_url) resource_path = urlparse.unquote(resource_url.path) if resource_path.endswith('/'): resource_path += 'index.html' return resource_path.lstrip('/')
Example #12
Source File: runtime.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def CgiDictFromParsedUrl(url): """Extract CGI variables from a parsed url into a dict. Returns a dict containing the following CGI variables for the provided url: SERVER_PORT, QUERY_STRING, SERVER_NAME and PATH_INFO. Args: url: An instance of urlparse.SplitResult. Returns: A dict containing the CGI variables derived from url. """ environ = {} if url.port is not None: environ['SERVER_PORT'] = str(url.port) elif url.scheme == 'https': environ['SERVER_PORT'] = '443' elif url.scheme == 'http': environ['SERVER_PORT'] = '80' environ['QUERY_STRING'] = url.query environ['SERVER_NAME'] = url.hostname if url.path: environ['PATH_INFO'] = urlparse.unquote(url.path) else: environ['PATH_INFO'] = '/' return environ
Example #13
Source File: device_proxy.py From a10sdk-python with Apache License 2.0 | 5 votes |
def DELETE(self, obj, query_params=None): obj.a10_url = self.url_encoder(obj.a10_url) if query_params: obj.a10_url += '?' + urlparse.unquote(urllib.urlencode(query_params)) conn = self.get_connection() payload = None conn.request("DELETE", self.url_encoder(obj.a10_url), "", self.headers) response = conn.getresponse() conn.close() obj.__setattr__("DEBUG_CONNECTION", conn.__dict__) obj.__setattr__("DEBUG_Payload", "") obj.__setattr__("DEBUG_Response", response) obj.__setattr__("DEBUG_URL", obj.a10_url) obj.__setattr__("DEBUG_headers", self.headers) return self.request_handler("DELETE", obj, response)
Example #14
Source File: client.py From bugatsinho.github.io with GNU General Public License v3.0 | 5 votes |
def url2name(url): from os.path import basename url = url.split('|')[0] return basename(unquote(urlparse.urlsplit(url)[2]))
Example #15
Source File: movie.py From plugin.video.bimozie with GNU General Public License v3.0 | 5 votes |
def extract_link(response, movie_links): # print response.encode('utf8') sources = re.search(r"<iframe.*src=\"(.*)\"", response) if sources: sources = re.search(r"var url\s=\s'(.*)';", response) if sources: source = sources.group(1) base_url = urlparse(unquote(source)) movie_links.append((unquote(source), base_url.netloc)) sources = re.search(r"var source = (\[.*?\])", response) if sources: sources = json.loads(sources.group(1)) for link in sources: movie_links.append((link.get('file'), link.get('label')))
Example #16
Source File: base.py From yahooquery with MIT License | 5 votes |
def _get_symbol(self, response, params): if isinstance(params, list): query_params = dict( parse.parse_qsl(parse.urlsplit(response.url).query)) return query_params['symbol'] if 'symbols' in params: return None return parse.unquote(response.url.rsplit('/')[-1].split('?')[0])
Example #17
Source File: api.py From kodi with GNU General Public License v3.0 | 5 votes |
def _parse_stream_map(self, data): """ Python's `parse_qs` can't properly decode the stream map containing video data so we use this instead. Keyword arguments: data -- The parsed response from YouTube. """ videoinfo = { "itag": [], "url": [], "quality": [], "fallback_host": [], "sig": [], "type": [] } text = data["url_encoded_fmt_stream_map"][0] # Split individual videos videos = text.split(",") # Unquote the characters and split to parameters videos = [video.split("&") for video in videos] for video in videos: for kv in video: key, value = kv.split("=") videoinfo.get(key, []).append(unquote(value)) return videoinfo
Example #18
Source File: jsonrpc.py From fortran-language-server with MIT License | 5 votes |
def path_from_uri(uri): # Convert file uri to path (strip html like head part) if not uri.startswith("file://"): return uri if os.name == "nt": _, path = uri.split("file:///", 1) else: _, path = uri.split("file://", 1) return os.path.normpath(unquote(path))
Example #19
Source File: px.py From px with MIT License | 5 votes |
def file_url_to_local_path(file_url): parts = urlparse.urlparse(file_url) path = urlparse.unquote(parts.path) if path.startswith('/') and not path.startswith('//'): if len(parts.netloc) == 2 and parts.netloc[1] == ':': return parts.netloc + path return 'C:' + path if len(path) > 2 and path[1] == ':': return path
Example #20
Source File: utils.py From a4kScrapers with MIT License | 5 votes |
def normalize(string): unescaped = unescape(string) unquoted = unquote(unescaped) return unicodedata.normalize("NFKD", unquoted).replace('\n', '')
Example #21
Source File: link.py From poetry with MIT License | 5 votes |
def path(self): return urlparse.unquote(urlparse.urlsplit(self.url)[2])
Example #22
Source File: link.py From poetry with MIT License | 5 votes |
def filename(self): _, netloc, path, _, _ = urlparse.urlsplit(self.url) name = posixpath.basename(path.rstrip("/")) or netloc name = urlparse.unquote(name) assert name, "URL %r produced no filename" % self.url return name
Example #23
Source File: compat.py From pledgeservice with Apache License 2.0 | 5 votes |
def unquote_bytes_to_wsgi(bytestring): return unquote_to_bytes(bytestring)
Example #24
Source File: compat.py From pledgeservice with Apache License 2.0 | 5 votes |
def unquote_bytes_to_wsgi(bytestring): return unquote_to_bytes(bytestring).decode('latin-1')
Example #25
Source File: connection.py From django-defender with Apache License 2.0 | 5 votes |
def parse_redis_url(url, password_quote): """Parses a redis URL.""" # create config with some sane defaults redis_config = { "DB": 0, "PASSWORD": None, "HOST": "localhost", "PORT": 6379, "SSL": False, } if not url: return redis_config url = urlparse.urlparse(url) # Remove query strings. path = url.path[1:] path = path.split("?", 2)[0] if path: redis_config.update({"DB": int(path)}) if url.password: password = url.password if password_quote: password = urlparse.unquote(password) redis_config.update({"PASSWORD": password}) if url.hostname: redis_config.update({"HOST": url.hostname}) if url.port: redis_config.update({"PORT": int(url.port)}) if url.scheme in ["https", "rediss"]: redis_config.update({"SSL": True}) return redis_config
Example #26
Source File: parser.py From recommonmark with MIT License | 4 votes |
def visit_link(self, mdnode): ref_node = nodes.reference() # Check destination is supported for cross-linking and remove extension destination = mdnode.destination _, ext = splitext(destination) # Check if the destination starts with a url scheme, since internal and # external links need to be handled differently. url_check = urlparse(destination) known_url_schemes = self.config.get('known_url_schemes') if known_url_schemes: scheme_known = url_check.scheme in known_url_schemes else: scheme_known = bool(url_check.scheme) # TODO check for other supported extensions, such as those specified in # the Sphinx conf.py file but how to access this information? if not scheme_known and ext.replace('.', '') in self.supported: destination = destination.replace(ext, '') ref_node['refuri'] = destination # TODO okay, so this is acutally not always the right line number, but # these mdnodes won't have sourcepos on them for whatever reason. This # is better than 0 though. ref_node.line = self._get_line(mdnode) if mdnode.title: ref_node['title'] = mdnode.title next_node = ref_node # If there's not a url scheme (e.g. 'https' for 'https:...' links), # or there is a scheme but it's not in the list of known_url_schemes, # then assume it's a cross-reference and pass it to Sphinx as an `:any:` ref. if not url_check.fragment and not scheme_known: wrap_node = addnodes.pending_xref( reftarget=unquote(destination), reftype='any', refdomain=None, # Added to enable cross-linking refexplicit=True, refwarn=True ) # TODO also not correct sourcepos wrap_node.line = self._get_line(mdnode) if mdnode.title: wrap_node['title'] = mdnode.title wrap_node.append(ref_node) next_node = wrap_node self.current_node.append(next_node) self.current_node = ref_node