本文整理汇总了Python中utils.parse_url函数的典型用法代码示例。如果您正苦于以下问题:Python parse_url函数的具体用法?Python parse_url怎么用?Python parse_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_url函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: is_internal_url
def is_internal_url(url, reference):
'''checks whether the given url is an internal url
to the reference site'''
refobj = utils.parse_url(reference)
urlobj = utils.parse_url(url)
if not url.startswith('http'):
raise InvalidUrlError
return urlobj.origin == refobj.origin
开发者ID:maxweldsouza,项目名称:jsseo,代码行数:8,代码来源:caching.py
示例2: absolute_to_relative
def absolute_to_relative(url, reference):
'''converts absolute urls to relative urls based on the
reference url'''
if not url.startswith('http'):
raise InvalidUrlError
refobj = utils.parse_url(reference)
urlobj = utils.parse_url(url)
if urlobj.origin == refobj.origin:
return urlobj.path
开发者ID:maxweldsouza,项目名称:jsseo,代码行数:9,代码来源:caching.py
示例3: _patch_uris
def _patch_uris(self, uris, handler="/XMLRPC"):
#Handles patching the uris when they're in a list.
if type(uris) == type([]):
ret = []
for i in range(len(uris)):
t = list(utils.parse_url(uris[i]))
t[2] = handler
ret.append(utils.unparse_url(t))
#Handles patching the uri when it's a string.
else:
t = list(utils.parse_url(uris))
t[2] = handler
ret = utils.unparse_url(t)
return ret
开发者ID:b1-systems,项目名称:spacewalk,代码行数:14,代码来源:repository.py
示例4: _post
def _post(self, url, data=None, headers={}):
host, port, uri, is_ssl = parse_url(url)
conn = HTTPSConnection(host, port, timeout=self.timeout)
headers.update({'Content-type': 'application/x-www-form-urlencoded'})
conn.request('POST', '/' + uri, urlencode(data) if data else None, headers)
response = conn.getresponse()
return conn, response
开发者ID:Gu1,项目名称:python-cloudfiles-hubic,代码行数:7,代码来源:authentication.py
示例5: _extract_url_parameters
def _extract_url_parameters(self, url):
'''
strip out the osdd url parameters
note: not always emitted correctly as param={thing?}. could also be param=thing
except the param=thing is probably a hardcoded term SO HOW DO WE MANAGE THAT?
TODO: manage that (ex: ?product=MOD021QA&collection={mp:collection?})
tuple: (parameter name, namespace(s), param namespace prefix, param type, format)
'''
assert url, 'No URL'
query_params = parse_url(url)
# deal with the namespaced parameters as [query param key, prefix, type]
query_params = [[k] + list(self._extract_parameter_type(v)) for k, v
in query_params.iteritems()]
return [
tidy_dict({
"name": qp[0],
"namespaces": self.parser._namespaces,
"prefix": qp[1],
"type": qp[2],
"format": self._parameter_formats.get(':'.join(qp[1:]))
})
for qp in query_params
]
开发者ID:b-cube,项目名称:pipeline-demo,代码行数:27,代码来源:opensearch_preprocessors.py
示例6: save_page
def save_page(self, url, html):
'''saves the dom for the path'''
try:
urlobj = utils.parse_url(url)
hsh = hashlib.sha1(html.encode('utf-8')).hexdigest()
current = self.db.get_one('''
select page_id, page_sha1 from page
where
site_hostname = %s and
page_path = %s''', (urlobj.origin, urlobj.path))
expires = datetime.datetime.now() + datetime.timedelta(0, default_expiry_time) #secs
logging.info('Saving page: %s', url)
if not current:
# TODO paths should always be present beforehand
self.db.put('''
insert into page
(site_hostname, page_path, page_content, page_sha1,
page_expires, page_expiresevery, page_attempts) values
(%s, %s, %s, %s, %s, %s, %s)
''', (urlobj.origin, urlobj.path, html, hsh, expires, default_expiry_time, 0))
else:
pageid = current[0]
self.db.put('''
update page
set
site_hostname = %s, page_content = %s, page_sha1 = %s,
page_expires = %s, page_expiresevery = %s, page_attempts = %s
where
page_id = %s
''', (urlobj.origin, html, hsh, expires, default_expiry_time, pageid, 0))
except Exception, e:
logging.error('Could not save page', exc_info=True)
开发者ID:maxweldsouza,项目名称:jsseo,代码行数:35,代码来源:mysql_wrapper.py
示例7: cdn_connect
def cdn_connect(self):
"""
Setup the http connection instance for the CDN service.
"""
(host, port, cdn_uri, is_ssl) = parse_url(self.cdn_url)
self.cdn_connection = self.conn_class(host, port, timeout=self.timeout)
self.cdn_enabled = True
开发者ID:ConsumerAffairs,项目名称:python-cloudfiles,代码行数:7,代码来源:connection.py
示例8: insert
def insert(self, bl_type, url):
dn, path, qp = utils.parse_url(url)
dn, path, qp = self.generate_query_parameters(dn, path, qp)
try:
self.blacklists[bl_type][dn][path].add(qp)
except KeyError:
return
开发者ID:jack8daniels2,项目名称:bouncer,代码行数:7,代码来源:memory_trie.py
示例9: _get
def _get(self, url, params=None, headers={}):
host, port, uri, is_ssl = parse_url(url)
conn = HTTPSConnection(host, port, timeout=self.timeout)
conn.request('GET', '/' + uri + ('?'+urlencode(params) if params else ''),
headers=headers)
response = conn.getresponse()
return conn, response
开发者ID:Gu1,项目名称:python-cloudfiles-hubic,代码行数:7,代码来源:authentication.py
示例10: cdn_connect
def cdn_connect(self):
"""
Setup the http connection instance for the CDN service.
"""
(host, port, cdn_uri, is_ssl) = parse_url(self.cdn_url)
conn_class = is_ssl and HTTPSConnection or HTTPConnection
self.cdn_connection = conn_class(host, port)
self.cdn_enabled = True
开发者ID:GunioRobot,项目名称:fileconveyor,代码行数:8,代码来源:connection.py
示例11: __init__
def __init__(self, username, api_key, authurl=default_authurl):
self.authurl = authurl
self.headers = dict()
self.headers['x-auth-user'] = username
self.headers['x-auth-key'] = api_key
self.headers['User-Agent'] = user_agent
(self.host, self.port, self.uri, self.is_ssl) = parse_url(self.authurl)
self.conn_class = self.is_ssl and HTTPSConnection or HTTPConnection
开发者ID:sorenh,项目名称:python-cloudfiles,代码行数:8,代码来源:authentication.py
示例12: capture
def capture(request):
# Merge both QueryDict into dict
parameters = dict([(k, v) for k, v in request.GET.items()])
parameters.update(dict([(k, v) for k, v in request.POST.items()]))
url = parameters.get('url')
if not url:
return HttpResponseBadRequest(_('Missing url parameter'))
try:
url = parse_url(request, url)
except NoReverseMatch:
error_msg = _("URL '%s' invalid (could not reverse)") % url
return HttpResponseBadRequest(error_msg)
method = parameters.get('method', request.method)
selector = parameters.get('selector')
data = parameters.get('data')
waitfor = parameters.get('waitfor')
wait = parameters.get('wait')
render = parameters.get('render', 'png')
size = parameters.get('size')
crop = parameters.get('crop')
try:
width = int(parameters.get('width', ''))
except ValueError:
width = None
try:
height = int(parameters.get('height', ''))
except ValueError:
height = None
stream = StringIO()
try:
casperjs_capture(stream, url, method=method.lower(), width=width,
height=height, selector=selector, data=data,
size=size, waitfor=waitfor, crop=crop, render=render,
wait=wait)
except CaptureError as e:
return HttpResponseBadRequest(e)
except ImportError:
error_msg = _('Resize not supported (PIL not available)')
return HttpResponseBadRequest(error_msg)
except UnsupportedImageFormat:
error_msg = _('Unsupported image format: %s' % render)
return HttpResponseBadRequest(error_msg)
if render == "html":
response = HttpResponse(mimetype='text/html')
body = """<html><body onload="window.print();">
<img src="data:image/png;base64,%s"/></body></html>
""" % base64.encodestring(stream.getvalue())
response.write(body)
else:
response = HttpResponse(mimetype=image_mimetype(render))
response.write(stream.getvalue())
return response
开发者ID:fle,项目名称:django-screamshot,代码行数:58,代码来源:views.py
示例13: __init__
def __init__(self, repo, ref=None, token=None):
"""Initialize repo."""
if repo.count('/') > 1:
_host, _user, _repo = parse_url(repo)
self.repo = '{}/{}'.format(_user, _repo)
else:
self.repo = repo
self.token = token
self.ref = ref
开发者ID:cernanalysispreservation,项目名称:analysis-preservation.cern.ch,代码行数:9,代码来源:github_importer.py
示例14: insert
def insert(self, payload, url):
"""
TODO, In order to allow search of query parameters in any order,
we may be able to use sets. This needs to be investigated.
For now, we'll sort the query arguments. Yuck!
"""
dn, path, qp = utils.parse_url(url)
domain, path_parameters = self.generate_query_parameters(dn, path, qp)
return self._session.execute(self._insert_query.bind((domain, path_parameters, payload)))
开发者ID:jack8daniels2,项目名称:bouncer,代码行数:9,代码来源:bigtable_example.py
示例15: __init__
def __init__(self, repo, ref=None, token=None):
"""Initialize repo."""
if repo.count('/') > 1:
_host, _user, _repo = parse_url(repo)
self.repo = '{}/{}'.format(_user, _repo)
else:
self.repo = repo
self.token = token
self.host = "https://gitlab.cern.ch"
self.ref = ref # branch/tag/commit
开发者ID:cernanalysispreservation,项目名称:analysis-preservation.cern.ch,代码行数:10,代码来源:gitlab_importer.py
示例16: delete_page
def delete_page(self, url):
try:
urlobj = utils.parse_url(url)
self.db.put('''
delete from page
where page_path = %s
and
site_hostname = %s''', (urlobj.path, urlobj.origin))
except Exception, e:
logging.error('Could not delete page', exc_info=True)
开发者ID:maxweldsouza,项目名称:jsseo,代码行数:10,代码来源:mysql_wrapper.py
示例17: __init__
def __init__(self, username, api_key, authurl=us_authurl, timeout=15,
useragent=user_agent):
self.authurl = authurl
self.headers = dict()
self.headers['x-auth-user'] = username
self.headers['x-auth-key'] = api_key
self.headers['User-Agent'] = useragent
self.timeout = timeout
(self.host, self.port, self.uri, self.is_ssl) = parse_url(self.authurl)
self.conn_class = get_conn_class(self.is_ssl)
开发者ID:a-volkov,项目名称:python-cloudfiles,代码行数:10,代码来源:authentication.py
示例18: cdn_connect
def cdn_connect(self):
"""
Setup the http connection instance for the CDN service.
"""
(host, port, cdn_uri, is_ssl) = parse_url(self.cdn_url)
if version_info[0] <= 2 and version_info[1] < 6:
self.conn_class = is_ssl and THTTPSConnection or THTTPConnection
else:
self.conn_class = is_ssl and HTTPSConnection or HTTPConnection
self.cdn_connection = self.conn_class(host, port, timeout=self.timeout)
self.cdn_enabled = True
开发者ID:WMInfoTech,项目名称:rooibos,代码行数:11,代码来源:connection.py
示例19: _authenticate
def _authenticate(self):
"""
Authenticate and setup this instance with the values returned.
"""
(url, self.cdn_url, self.token) = self.auth.authenticate()
self.connection_args = parse_url(url)
self.conn_class = self.connection_args[3] and HTTPSConnection or \
HTTPConnection
self.http_connect()
if self.cdn_url:
self.cdn_connect()
开发者ID:GunioRobot,项目名称:fileconveyor,代码行数:11,代码来源:connection.py
示例20: _authenticate
def _authenticate(self):
"""
Authenticate and setup this instance with the values returned.
"""
(url, self.token) = self.auth.authenticate()
self.connection_args = parse_url(url)
if version_info[0] <= 2 and version_info[1] < 6:
self.conn_class = self.connection_args[3] and THTTPSConnection or THTTPConnection
else:
self.conn_class = self.connection_args[3] and HTTPSConnection or HTTPConnection
self.http_connect()
开发者ID:adregner,项目名称:python-clouddns,代码行数:12,代码来源:connection.py
注:本文中的utils.parse_url函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论