Python six.moves.urllib_parse.urlunparse() Examples
The following are 16
code examples of six.moves.urllib_parse.urlunparse().
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
six.moves.urllib_parse
, or try the search function
.
Example #1
Source File: general_name.py From teleport with Apache License 2.0 | 6 votes |
def _idna_encode(self, value): parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{0}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #2
Source File: general_name.py From teleport with Apache License 2.0 | 6 votes |
def _idna_encode(self, value): idna = _lazy_import_idna() parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #3
Source File: general_name.py From teleport with Apache License 2.0 | 6 votes |
def _idna_encode(self, value): idna = _lazy_import_idna() parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #4
Source File: general_name.py From learn_python3_spider with MIT License | 6 votes |
def _idna_encode(self, value): idna = _lazy_import_idna() parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #5
Source File: general_name.py From quickstart-git2s3 with Apache License 2.0 | 6 votes |
def _idna_encode(self, value): parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{0}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #6
Source File: test_saml.py From Dailyfresh-B2C with Apache License 2.0 | 6 votes |
def modify_start_url(self, start_url): """ Given a SAML redirect URL, parse it and change the ID to a consistent value, so the request is always identical. """ # Parse the SAML Request URL to get the XML being sent to TestShib url_parts = urlparse(start_url) query = dict((k, v[0]) for (k, v) in parse_qs(url_parts.query).items()) xml = OneLogin_Saml2_Utils.decode_base64_and_inflate( query['SAMLRequest'] ) # Modify the XML: xml = xml.decode() xml, changed = re.subn(r'ID="[^"]+"', 'ID="TEST_ID"', xml) self.assertEqual(changed, 1) # Update the URL to use the modified query string: query['SAMLRequest'] = OneLogin_Saml2_Utils.deflate_and_base64_encode( xml ) url_parts = list(url_parts) url_parts[4] = urlencode(query) return urlunparse(url_parts)
Example #7
Source File: general_name.py From quickstart-redhat-openshift with Apache License 2.0 | 6 votes |
def _idna_encode(self, value): idna = _lazy_import_idna() parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #8
Source File: general_name.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _idna_encode(self, value): idna = _lazy_import_idna() parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. return urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment ))
Example #9
Source File: general_name.py From oss-ftp with MIT License | 5 votes |
def __init__(self, value): if not isinstance(value, six.text_type): raise TypeError("value must be a unicode string") parsed = urllib_parse.urlparse(value) if not parsed.hostname: netloc = "" elif parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{0}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. uri = urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment )).encode("ascii") self._value = value self._encoded = uri
Example #10
Source File: general_name.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def __init__(self, value): if not isinstance(value, six.text_type): raise TypeError("value must be a unicode string") parsed = urllib_parse.urlparse(value) if not parsed.hostname: netloc = "" elif parsed.port: netloc = ( idna.encode(parsed.hostname) + ":{0}".format(parsed.port).encode("ascii") ).decode("ascii") else: netloc = idna.encode(parsed.hostname).decode("ascii") # Note that building a URL in this fashion means it should be # semantically indistinguishable from the original but is not # guaranteed to be exactly the same. uri = urllib_parse.urlunparse(( parsed.scheme, netloc, parsed.path, parsed.params, parsed.query, parsed.fragment )).encode("ascii") self._value = value self._encoded = uri
Example #11
Source File: driver.py From networking-odl with Apache License 2.0 | 5 votes |
def get_sample_data(self, meter_name, parse_url, params, cache): extractor = self._get_extractor(meter_name) if extractor is None: # The way to getting meter is not implemented in this driver or # OpenDaylight REST API has not api to getting meter. return None iter = self._get_iter(meter_name) if iter is None: # The way to getting meter is not implemented in this driver or # OpenDaylight REST API has not api to getting meter. return None parts = urlparse.ParseResult(params.get('scheme', ['http'])[0], parse_url.netloc, parse_url.path, None, None, None) endpoint = urlparse.urlunparse(parts) data = self._prepare_cache(endpoint, params, cache) samples = [] if data: for sample in iter(extractor, data): if sample is not None: # set controller name to resource_metadata sample[2]['controller'] = 'OpenDaylight_V2' samples.append(sample) return samples
Example #12
Source File: utils.py From networking-odl with Apache License 2.0 | 5 votes |
def get_odl_url(path=''): '''Make a URL for some ODL resource (path)''' purl = urlparse.urlsplit(cfg.CONF.ml2_odl.url) features_url = urlparse.urlunparse(( purl.scheme, purl.netloc, path, '', '', '')) return features_url
Example #13
Source File: webtest.py From cheroot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def strip_netloc(url): """Return absolute-URI path from URL. Strip the scheme and host from the URL, returning the server-absolute portion. Useful for wrapping an absolute-URI for which only the path is expected (such as in calls to :py:meth:`WebCase.getPage`). >>> strip_netloc('https://google.com/foo/bar?bing#baz') '/foo/bar?bing' >>> strip_netloc('//google.com/foo/bar?bing#baz') '/foo/bar?bing' >>> strip_netloc('/foo/bar?bing#baz') '/foo/bar?bing' """ parsed = urllib_parse.urlparse(url) scheme, netloc, path, params, query, fragment = parsed stripped = '', '', path, params, query, '' return urllib_parse.urlunparse(stripped) # Add any exceptions which your web framework handles # normally (that you don't want server_error to trap).
Example #14
Source File: __init__.py From patroni with MIT License | 5 votes |
def parse_connection_string(value): """Original Governor stores connection strings for each cluster members if a following format: postgres://{username}:{password}@{connect_address}/postgres Since each of our patroni instances provides own REST API endpoint it's good to store this information in DCS among with postgresql connection string. In order to not introduce new keys and be compatible with original Governor we decided to extend original connection string in a following way: postgres://{username}:{password}@{connect_address}/postgres?application_name={api_url} This way original Governor could use such connection string as it is, because of feature of `libpq` library. This method is able to split connection string stored in DCS into two parts, `conn_url` and `api_url`""" scheme, netloc, path, params, query, fragment = urlparse(value) conn_url = urlunparse((scheme, netloc, path, params, '', fragment)) api_url = ([v for n, v in parse_qsl(query) if n == 'application_name'] or [None])[0] return conn_url, api_url
Example #15
Source File: request.py From patroni with MIT License | 5 votes |
def __call__(self, member, method='GET', endpoint=None, data=None, **kwargs): url = member.api_url if endpoint: scheme, netloc, _, _, _, _ = urlparse(url) url = urlunparse((scheme, netloc, endpoint, '', '', '')) return self.request(method, url, data, **kwargs)
Example #16
Source File: webtest.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def strip_netloc(url): """Return absolute-URI path from URL. Strip the scheme and host from the URL, returning the server-absolute portion. Useful for wrapping an absolute-URI for which only the path is expected (such as in calls to getPage). >>> strip_netloc('https://google.com/foo/bar?bing#baz') '/foo/bar?bing' >>> strip_netloc('//google.com/foo/bar?bing#baz') '/foo/bar?bing' >>> strip_netloc('/foo/bar?bing#baz') '/foo/bar?bing' """ parsed = urllib_parse.urlparse(url) scheme, netloc, path, params, query, fragment = parsed stripped = '', '', path, params, query, '' return urllib_parse.urlunparse(stripped) # Add any exceptions which your web framework handles # normally (that you don't want server_error to trap).