Python urlparse.ParseResult() Examples
The following are 11
code examples of urlparse.ParseResult().
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: 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 #2
Source File: main_window.py From encompass with GNU General Public License v3.0 | 6 votes |
def update_receive_qr(self): import urlparse, urllib addr = str(self.receive_address_e.text()) amount = None message = None url = None amount = self.receive_amount_e.get_amount() message = unicode(self.receive_message_e.text()).encode('utf8') self.save_request_button.setEnabled((amount is not None) or (message != "")) uri_scheme = chainkey.chainparams.get_active_chain().coin_name.lower() if addr: query = [] if amount: query.append('amount=%s'%format_satoshis(amount)) if message: query.append('message=%s'%urllib.quote(message)) p = urlparse.ParseResult(scheme=uri_scheme, netloc='', path=addr, params='', query='&'.join(query), fragment='') url = urlparse.urlunparse(p) else: url = "" self.receive_qr.setData(url) if self.qr_window: self.qr_window.set_content(addr, amount, message, url)
Example #3
Source File: helpers.py From feedthefox with Mozilla Public License 2.0 | 6 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 #4
Source File: repeater.py From pappy-proxy with MIT License | 6 votes |
def geturl(self, include_params=True): params = self.params query = self.query fragment = self.fragment if not include_params: params = "" query = "" fragment = "" r = ParseResult(scheme=self.scheme, netloc=self.netloc, path=self.path, params=params, query=query, fragment=fragment) return r.geturl()
Example #5
Source File: views.py From guides-cms with GNU Affero General Public License v3.0 | 6 votes |
def strip_subfolder(url): """ Strip off the subfolder if it exists so we always use the exact same share url for saving counts. """ subfolder = app.config.get('SUBFOLDER', None) if not subfolder: return url p = urlparse.urlparse(url) if not p.path.startswith(subfolder): return url new_path = p.path.replace('%s' % (subfolder), '', 1) new_url = urlparse.ParseResult(p.scheme, p.netloc, new_path, p.params, p.query, p.fragment) return new_url.geturl()
Example #6
Source File: app.py From daenerys with Apache License 2.0 | 5 votes |
def validate_url(self, url): url_path = urllib.quote(url.path, safe=b"/%") url_query = urllib.quote(url.query, safe=b"?=&") url = ParseResult(url.scheme, url.netloc, url_path, url.params, url_query, url.fragment) has_hostname = url.hostname is not None and len(url.hostname) > 0 has_http_scheme = url.scheme in ("http", "https") has_path = not len(url.path) or url.path.startswith("/") if not (has_hostname and has_http_scheme and has_path): raise NotSupported("invalid url: %s" % repr(url)) return url
Example #7
Source File: utils.py From openag_python with GNU General Public License v3.0 | 5 votes |
def replicate_per_farm_dbs(cloud_url=None, local_url=None, farm_name=None): """ Sete up replication of the per-farm databases from the local server to the cloud server. :param str cloud_url: Used to override the cloud url from the global configuration in case the calling function is in the process of initializing the cloud server :param str local_url: Used to override the local url from the global configuration in case the calling function is in the process of initializing the local server :param str farm_name: Used to override the farm name from the global configuratino in case the calling function is in the process of initializing the farm """ cloud_url = cloud_url or config["cloud_server"]["url"] local_url = local_url or config["local_server"]["url"] farm_name = farm_name or config["cloud_server"]["farm_name"] username = config["cloud_server"]["username"] password = config["cloud_server"]["password"] # Add credentials to the cloud url parsed_cloud_url = urlparse(cloud_url) if not parsed_cloud_url.username: new_netloc = "{}:{}@{}".format( username, password, parsed_cloud_url.netloc ) cloud_url = ParseResult( parsed_cloud_url.scheme, new_netloc, parsed_cloud_url.path, parsed_cloud_url.params, parsed_cloud_url.query, parsed_cloud_url.fragment ).geturl() server = Server(local_url) for db_name in per_farm_dbs: remote_db_name = "{}/{}/{}".format(username, farm_name, db_name) server.replicate( db_name, db_name, urljoin(cloud_url, remote_db_name), continuous=True )
Example #8
Source File: middleware.py From daywatch with MIT License | 5 votes |
def should_follow(self, response, spider): parsed = urlparse(response.url) url = ParseResult( parsed.scheme, parsed.netloc, parsed.path, parsed.params, None, None ) url = url.geturl() return url not in spider.disallow_urls
Example #9
Source File: import_google_fonts.py From tensorboard with Apache License 2.0 | 5 votes |
def open_url(url): ru = urlparse.urlparse(url) pu = urlparse.ParseResult("", "", ru.path, ru.params, ru.query, ru.fragment) if ru.scheme == "https": c = httplib.HTTPSConnection(ru.netloc) else: c = httplib.HTTPConnection(ru.netloc) c.putrequest("GET", pu.geturl()) c.putheader("User-Agent", FLAGS.user_agent) c.endheaders() return c.getresponse()
Example #10
Source File: client.py From python-phoenixdb with Apache License 2.0 | 5 votes |
def parse_url(url): url = urlparse.urlparse(url) if not url.scheme and not url.netloc and url.path: netloc = url.path if ':' not in netloc: netloc = '{}:8765'.format(netloc) return urlparse.ParseResult('http', netloc, '/', '', '', '') return url # Defined in phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
Example #11
Source File: sitemap.py From swarm with GNU General Public License v3.0 | 4 votes |
def _parse_url(self,dst,src): """ Check wether target url 'dst' is in the same domain(include port) with url 'src', and convert url into complete url without params. Returns: String of complete url with query params if it has. if target url is not in the same domain, return ''; """ LOG.debug('detecting url: '+dst) s_parsed=urlparse.urlparse(src) s_scheme=s_parsed.scheme s_netloc=s_parsed.netloc s_cur_dir=s_parsed.path if s_cur_dir[-1]!='/': s_cur_dir='/'.join(s_cur_dir.split('/')[:-1]) else: s_cur_dir=s_cur_dir[:-1] d_parsed=urlparse.urlparse(dst) d_scheme=d_parsed.scheme if d_parsed.netloc.find(':')==-1 and d_parsed.netloc!='': if d_scheme=='http': d_netloc=d_parsed.netloc+':80' elif d_scheme=='https': d_netloc=d_parsed.netloc+':443' elif d_scheme=='': d_netloc=d_parsed.netloc+':80' if s_scheme=='http' else d_parsed.netloc+':443' else: d_netloc=d_parsed.netloc else: d_netloc=d_parsed.netloc # add '/' as prefix if the path does not starts with '/' if d_parsed.path!='': d_path='/'+d_parsed.path if d_parsed.path[0]!='/' else d_parsed.path else: d_path='/' d_query=d_parsed.query # if it is a relative url if d_netloc=='': return urlparse.ParseResult(s_scheme,s_netloc,s_cur_dir+d_path,'',d_query,'').geturl() elif d_netloc==s_netloc and (d_scheme==s_scheme or d_scheme==''): return urlparse.ParseResult(s_scheme,s_netloc,d_path,'',d_query,'').geturl() else: return ''