本文整理汇总了Python中six.moves.urllib_parse.urljoin方法的典型用法代码示例。如果您正苦于以下问题:Python urllib_parse.urljoin方法的具体用法?Python urllib_parse.urljoin怎么用?Python urllib_parse.urljoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.urllib_parse
的用法示例。
在下文中一共展示了urllib_parse.urljoin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _normalize_name
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def _normalize_name(self, name):
"""
Normalizes the name so that paths like /path/to/ignored/../foo.txt
work. We check to make sure that the path pointed to is not outside
the directory specified by the LOCATION setting.
"""
if name.startswith("https://") or name.startswith("http://"):
return name
base_path = force_text(self.location)
base_path = base_path.rstrip('/')
final_path = urljoin(base_path.rstrip('/') + "/", name)
base_path_len = len(base_path)
if (not final_path.startswith(base_path) or
final_path[base_path_len:base_path_len + 1] not in ('', '/')):
raise SuspiciousOperation("Attempted access to '%s' denied." %
name)
return final_path.lstrip('/')
示例2: _normalize_name
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def _normalize_name(self, name):
"""
Normalizes the name so that paths like /path/to/ignored/../foo.txt
work. We check to make sure that the path pointed to is not outside
the directory specified by the LOCATION setting.
"""
base_path = force_text(self.location)
base_path = base_path.rstrip('/')
final_path = urljoin(base_path.rstrip('/') + "/", name)
base_path_len = len(base_path)
if (not final_path.startswith(base_path) or
final_path[base_path_len:base_path_len + 1] not in ('', '/')):
raise SuspiciousOperation("Attempted access to '%s' denied." %
name)
return final_path.lstrip('/')
示例3: base_url_pair_getter
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def base_url_pair_getter(get_url):
""" Returns a function for gettting a tuple of `(base_url, url)` when
called with an etree `Element` or `ElementTree`.
In the returned pair `base_url` is the value returned from
`:func:get_base_url` on the etree `Element` or `ElementTree`.
There second value is the value returned by calling the `get_url`
on the same the same etree `Element` or `ElementTree`, joined to
the `base_url` using `urljoin`. This allows `get_url` to return
a relative URL.
"""
@composable
def get_base_url_pair(elem_or_tree):
base_url = get_base_url(elem_or_tree)
url = get_url(elem_or_tree)
if url:
url = URL(urljoin(base_url, url.strip()))
return (URL(base_url), url)
return get_base_url_pair
示例4: urls_from_robots_txt
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def urls_from_robots_txt(response):
""" Yields sitemap URLs from "/robots.txt" """
url = URL(response.request_url or response.url or '')
if url.parsed.path != '/robots.txt':
return
charset = response.headers.get_content_charset()
lines = getreader(charset or 'ISO-8859-1')(response)
for line in lines:
content, _, comment = line.partition('#')
field, _, value = content.partition(':')
if field.strip().lower() != 'sitemap':
continue
# we shouldn't need to urljoin but we do just in case
joined = URL(urljoin(response.url, value.strip()))
# set sitemap=True in fragment to help downstream processing
yield "url", joined.update_fragment_dict(sitemap=True)
示例5: process_request
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def process_request(self, req, resp):
'''Get user from auth token'''
if req.context.get('auth_token') is None:
# If the user doesnt have a token, redirect to login
if req.path not in (urljoin(self.config.baseurl, self.config.loginurl), urljoin(self.config.baseurl, self.config.registerurl)) and \
urljoin(self.config.baseurl, 'static') not in req.path:
raise falcon.HTTPFound(urljoin(self.config.baseurl, self.config.loginurl))
else:
# try to get user
# get sql session
session = self.config.storage.sessionmaker()
# query for user
user = self.db.users.detail(req.context['auth_token'], req.params, session)
if user is not None:
# user not found
req.context['user'] = user
if req.path in (urljoin(self.config.baseurl, self.config.loginurl), urljoin(self.config.baseurl, self.config.registerurl)):
raise falcon.HTTPFound(self.config.baseurl)
elif req.path not in (urljoin(self.config.baseurl, self.config.loginurl), urljoin(self.config.baseurl, self.config.registerurl), urljoin(self.config.baseurl, self.config.logouturl)) and \
urljoin(self.config.baseurl, 'static') not in req.path:
raise falcon.HTTPFound(urljoin(self.config.baseurl, self.config.loginurl))
示例6: edit
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def edit(self):
'''Generate Edit template for client from a Report object'''
f = Response()
f.entries = [
FormEntry(name='name', type='text', value=self.name, label='Name', placeholder='Name for Report...', required=True),
FormEntry(name='id', type='text', value=self.id, label='Id', hidden=True),
FormEntry(name='notebook name', type='text', value=self.meta.notebook.name, label='Notebook', required=True, readonly=True),
FormEntry(name='notebook', type='text', value=self.meta.notebook.id, required=True, readonly=True, hidden=True),
FormEntry(name='job name', type='text', value=self.meta.job.name, label='Job', required=True, readonly=True),
FormEntry(name='job', type='text', value=self.meta.job.id, required=True, readonly=True, hidden=True),
FormEntry(name='parameters', type='textarea', value=self.meta.parameters, label='Parameters', placeholder='JSON Parameters...'),
FormEntry(name='type', type='select', value=self.meta.type, label='Type', options=_REPORT_TYPES, required=True),
FormEntry(name='output', type='select', value=self.meta.output, label='Output', options=_OUTPUT_TYPES, required=True),
FormEntry(name='code', type='select', value='yes' if self.meta.strip_code else 'no', label='Strip Code', options=['yes', 'no'], required=True),
FormEntry(name='save', type='submit', value='save', url=urljoin(self.config.apiurl, 'reports?action=save')),
FormEntry(name='delete', type='submit', value='delete', url=urljoin(self.config.apiurl, 'reports?action=delete'))
]
return f.to_json()
示例7: entry
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def entry(self):
'''Generate ListTable entry for client from a Report object'''
f = Response()
f.entries = [
DOMEntry(name='name', type='label', value=self.name, label='Name'),
DOMEntry(name='id', type='label', value=self.id, label='Id', hidden=True),
DOMEntry(name='notebook', type='label', value=self.meta.notebook.name, label='Notebook'),
DOMEntry(name='job', type='label', value=self.meta.job.name, label='Job'),
DOMEntry(name='parameters', type='json', value=self.meta.parameters, label='Parameters'),
DOMEntry(name='type', type='label', value=self.meta.type, label='Type'),
DOMEntry(name='output', type='label', value=self.meta.output, label='Output'),
DOMEntry(name='strip_code', type='label', value=str(self.meta.strip_code), label='Strip Code'),
DOMEntry(name='template', type='label', value=self.meta.template, label='Template'),
# DOMEntry(type='label', value=self.meta.run, label='Run'),
DOMEntry(name='created', type='label', value=self.meta.created.strftime('%m/%d/%Y %H:%M:%S'), label='Created'),
DOMEntry(name='modified', type='label', value=self.meta.modified.strftime('%m/%d/%Y %H:%M:%S'), label='Modified'),
DOMEntry(name='delete', type='button', value='delete', label='delete', url=urljoin(self.config.apiurl, 'reports?action=delete'))
]
return f.to_json()
示例8: edit
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def edit(self):
'''Generate Edit template for client from a Job object'''
f = Response()
f.entries = [
FormEntry(name='name', type='text', value=self.name, label='Name', placeholder='Name for Job...', required=True),
FormEntry(name='id', type='text', value=self.id, label='Id', hidden=True),
FormEntry(name='notebook name', type='text', value=self.meta.notebook.name, label='Notebook', required=True, readonly=True),
FormEntry(name='notebook', type='text', value=self.meta.notebook.id, required=True, readonly=True, hidden=True),
FormEntry(name='starttime', value=self.meta.start_time.strftime('%Y-%m-%dT%H:%M'), type='datetime', label='Start Time/Date', required=True),
FormEntry(name='interval', type='select', value=self.meta.interval, label='Interval', options=_INTERVAL_TYPES, required=True),
FormEntry(name='level', type='select', value=self.meta.level, label='Level', options=_SERVICE_LEVELS, required=True),
FormEntry(name='reports', type='text', value=str(self.meta.reports), readonly=True),
FormEntry(name='save', type='submit', value='save', url=urljoin(self.config.apiurl, 'jobs?action=save')),
FormEntry(name='delete', type='submit', value='delete', url=urljoin(self.config.apiurl, 'jobs?action=delete'))
]
return f.to_json()
示例9: entry
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def entry(self):
'''Generate ListTable entry for client from a Notebook object'''
f = Response()
f.entries = [
DOMEntry(name='name', type='label', value=self.name, label='Name'),
DOMEntry(name='id', type='label', value=self.id, label='Id', hidden=True),
DOMEntry(name='visibility', type='label', value=self.meta.privacy, label='Visibility'),
DOMEntry(name='level', type='label', value=self.meta.level, label='Level'),
DOMEntry(name='notebook', type='ipynb', value=self.meta.notebook, label='Notebook'),
DOMEntry(name='requirements', type='textfile', value=self.meta.requirements, label='requirements'),
DOMEntry(name='dockerfile', type='textfile', value=self.meta.dockerfile, label='Dockerfile'),
DOMEntry(name='jobs', type='label', value=str(self.meta.jobs), label='Jobs'),
DOMEntry(name='reports', type='label', value=str(self.meta.reports), label='Reports'),
DOMEntry(name='created', type='label', value=self.meta.created.strftime('%m/%d/%Y %H:%M:%S'), label='Created'),
DOMEntry(name='modified', type='label', value=self.meta.modified.strftime('%m/%d/%Y %H:%M:%S'), label='Modified'),
DOMEntry(name='delete', type='button', value='delete', label='delete', url=urljoin(self.config.apiurl, 'notebooks?action=delete'))
]
return f.to_json()
示例10: _ComputePaths
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def _ComputePaths(package, version, root_url, service_path):
"""Compute the base url and base path.
Attributes:
package: name field of the discovery, i.e. 'storage' for storage service.
version: version of the service, i.e. 'v1'.
root_url: root url of the service, i.e. 'https://www.googleapis.com/'.
service_path: path of the service under the rool url, i.e. 'storage/v1/'.
Returns:
base url: string, base url of the service,
'https://www.googleapis.com/storage/v1/' for the storage service.
base path: string, common prefix of service endpoints after the base url.
"""
full_path = urllib_parse.urljoin(root_url, service_path)
api_path_component = '/'.join((package, version, ''))
if api_path_component not in full_path:
return full_path, ''
prefix, _, suffix = full_path.rpartition(api_path_component)
return prefix + api_path_component, suffix
示例11: bind_app
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def bind_app(self, app):
"""Recreate this SitemapEntry in the context of
:class:`app <Application>`.
:returns: :class:`SitemapEntry`
"""
lbl = self.label
url = self.url
if callable(lbl):
lbl = lbl(app)
if url is not None:
url = urljoin(app.url, url)
return SitemapEntry(lbl, url,
[ch.bind_app(app) for ch in self.children],
className=self.className,
ui_icon=self.ui_icon,
small=self.small,
tool_name=self.tool_name,
matching_urls=self.matching_urls,
mount_point=app.config.options.mount_point,
)
示例12: full_url
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def full_url(link):
"""
Return an absolute version of a possibly-relative URL.
This uses the PAYFAST_URL_BASE setting.
"""
url_base = (conf.URL_BASE() if callable(conf.URL_BASE) else
conf.URL_BASE)
return urljoin(url_base, link)
示例13: notify_new_email
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def notify_new_email(email, user):
""" Ask the user to confirm to the email belong to them.
"""
root_url = pagure_config.get("APP_URL", flask.request.url_root)
url = urljoin(
root_url or flask.request.url_root,
flask.url_for("ui_ns.confirm_email", token=email.token),
)
text = """Dear %(username)s,
You have registered a new email on pagure at %(root_url)s.
To finish your validate this registration, please click on the following
link or copy/paste it in your browser, this link will remain valid only 2 days:
%(url)s
The email will not be activated until you finish this step.
Sincerely,
Your pagure admin.
""" % (
{"username": user.username, "url": url, "root_url": root_url}
)
send_email(
text,
"Confirm new email",
email.email,
user_from=user.fullname or user.user,
)
示例14: compute_paths
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def compute_paths(img, settings, derivative):
process_dir = settings["IMAGE_PROCESS_DIR"]
img_src = urlparse(img["src"])
img_src_path = url2pathname(img_src.path[1:])
img_src_dirname, filename = os.path.split(img_src_path)
derivative_path = os.path.join(process_dir, derivative)
base_url = urljoin(img_src.geturl(), pathname2url(derivative_path))
if PELICAN_MAJOR_VERSION < 4:
file_paths = settings["filenames"]
else:
file_paths = settings["static_content"]
for f, contobj in file_paths.items():
if img_src_path.endswith(contobj.get_url_setting("save_as")):
source = contobj.source_path
base_path = os.path.join(
contobj.settings["OUTPUT_PATH"],
os.path.dirname(contobj.get_url_setting("save_as")),
process_dir,
derivative,
)
break
else:
if "SITEURL" in settings:
site_url = urlparse(settings["SITEURL"])
site_url_path = url2pathname(site_url.path[1:])
else:
# if SITEURL is undefined, don't break!
site_url_path = None
if site_url_path:
src_path = img_src_path.partition(site_url_path)[2].lstrip("/")
else:
src_path = img_src_path.lstrip("/")
source = os.path.join(settings["PATH"], src_path)
base_path = os.path.join(
settings["OUTPUT_PATH"], os.path.dirname(src_path), derivative_path
)
return Path(base_url, source, base_path, filename, process_dir)
示例15: test_efz_download_audio
# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import urljoin [as 别名]
def test_efz_download_audio():
available_audio_files = nussl.efz_utils.get_available_audio_files()
best = get_smallest_file(available_audio_files)
key = available_audio_files[best]['file_name']
with tempfile.TemporaryDirectory() as tmp_dir:
path1 = nussl.efz_utils.download_audio_file(key)
assert os.path.exists(path1)
assert os.path.expanduser('~/.nussl/') in path1
path2 = nussl.efz_utils.download_audio_file(key, tmp_dir)
assert os.path.exists(path2)
current_hash = nussl.efz_utils._hash_file(path2)
a = nussl.AudioSignal(path2, sample_rate=8000)
a.write_audio_to_file(path2)
next_hash = nussl.efz_utils._hash_file(path2)
assert current_hash != next_hash
path2 = nussl.efz_utils.download_audio_file(key, tmp_dir)
next_hash = nussl.efz_utils._hash_file(path2)
assert current_hash == next_hash
a.write_audio_to_file(path2 + 'garbage')
pytest.raises(FailedDownloadError, nussl.core.efz_utils._download_file,
key + 'garbage', constants.NUSSL_EFZ_AUDIO_URL, tmp_dir, 'audio')
assert not os.path.exists(path2 + 'garbage')
pytest.raises(FailedDownloadError, nussl.core.efz_utils._download_file,
key, 'garbage' + constants.NUSSL_EFZ_AUDIO_URL, tmp_dir, 'audio')
file_url = urljoin(constants.NUSSL_EFZ_AUDIO_URL, key)
pytest.raises(MismatchedHashError, nussl.core.efz_utils._download_file,
key, file_url, tmp_dir, 'audio', file_hash=123)