本文整理汇总了Python中urllib.request.url2pathname方法的典型用法代码示例。如果您正苦于以下问题:Python request.url2pathname方法的具体用法?Python request.url2pathname怎么用?Python request.url2pathname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib.request
的用法示例。
在下文中一共展示了request.url2pathname方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logs_for_status
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def test_logs_for_status(bep_file, status):
targets = []
with open(bep_file, encoding="utf-8") as f:
raw_data = f.read()
decoder = json.JSONDecoder()
pos = 0
while pos < len(raw_data):
try:
bep_obj, size = decoder.raw_decode(raw_data[pos:])
except ValueError as e:
eprint("JSON decoding error: " + str(e))
return targets
if "testSummary" in bep_obj:
test_target = bep_obj["id"]["testSummary"]["label"]
test_status = bep_obj["testSummary"]["overallStatus"]
if test_status in status:
outputs = bep_obj["testSummary"]["failed"]
test_logs = []
for output in outputs:
test_logs.append(url2pathname(urlparse(output["uri"]).path))
targets.append((test_target, test_logs))
pos += size + 1
return targets
示例2: playAction
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def playAction(cls, action):
if not cls.useSounds:
return
if isinstance(action, str):
key_no = cls.actionToKeyNo[action]
else:
key_no = action
typ = cls.soundcombo[key_no]
if typ == SOUND_BEEP:
sys.stdout.write("\a")
sys.stdout.flush()
elif typ == SOUND_URI:
uri = cls.sounduri[key_no]
if not os.path.isfile(url2pathname(uri[5:])):
conf.set("soundcombo%d" % key_no, SOUND_MUTE)
return
cls.getPlayer().play(uri)
示例3: get_partial_names_for_template
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def get_partial_names_for_template(template=None, get_all=True, requested_partials=None):
template = template or settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE
if requested_partials:
# Transform the requested partials into a list
requested_partials = url2pathname(requested_partials).split(',')
else:
requested_partials = []
try:
partials = settings.DJANGOCMS_SPA_TEMPLATES[template]['partials']
except KeyError:
try:
default_template_path = settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE
partials = settings.DJANGOCMS_SPA_TEMPLATES[default_template_path]['partials']
except KeyError:
partials = []
if get_all:
return partials
else:
return [partial for partial in partials if partial in requested_partials]
示例4: file_path
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def file_path(self, url):
"""Return the relative path to the file on disk for the given URL."""
relative_url = url[len(self.base_url[2]):]
return url2pathname(relative_url)
示例5: file_path
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def file_path(self, url):
"""
Return the relative path to the media file on disk for the given URL.
"""
relative_url = url[len(self.base_url[2]):]
return url2pathname(relative_url)
示例6: play
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def play(self, uri):
try:
winsound.PlaySound(None, 0)
winsound.PlaySound(
url2pathname(uri[5:]), winsound.SND_FILENAME | winsound.SND_ASYNC)
except RuntimeError:
log.error("ERROR: RuntimeError while playing %s." %
url2pathname(uri[5:]))
示例7: on_recent_game_activated
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def on_recent_game_activated(self, uri):
if isinstance(uri, str):
path = url2pathname(uri)
recent_manager.add_item("file:" + pathname2url(path))
# Drag 'n' Drop
示例8: update_recent
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def update_recent(self, gamemodel, uri):
if isinstance(uri, str):
path = url2pathname(uri)
recent_manager.add_item("file:" + pathname2url(path))
示例9: s3_open
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def s3_open(self, req):
# The implementation was inspired mainly by the code behind
# urllib.request.FileHandler.file_open().
bucket_name = req.host
key_name = url2pathname(req.selector)[1:]
if not bucket_name or not key_name:
raise URLError('url must be in the format s3://<bucket>/<key>')
try:
conn = self._conn
except AttributeError:
conn = self._conn = boto.s3.connection.S3Connection()
bucket = conn.get_bucket(bucket_name, validate=False)
key = bucket.get_key(key_name)
origurl = 's3://{}/{}'.format(bucket_name, key_name)
if key is None:
raise URLError('no such resource: {}'.format(origurl))
headers = [
('Content-type', key.content_type),
('Content-encoding', key.content_encoding),
('Content-language', key.content_language),
('Content-length', key.size),
('Etag', key.etag),
('Last-modified', key.last_modified),
]
headers = email.message_from_string(
'\n'.join('{}: {}'.format(key, value) for key, value in headers
if value is not None))
return addinfourl(_FileLikeKey(key), headers, origurl)
示例10: uri_to_filename
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def uri_to_filename(uri: str) -> str:
if os.name == 'nt':
# url2pathname does not understand %3A (VS Code's encoding forced on all servers :/)
return url2pathname(urlparse(uri).path).strip('\\')
else:
return url2pathname(urlparse(uri).path)
示例11: url2path
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def url2path(path):
"""Path to URL."""
return url2pathname(path)
示例12: nativejoin
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def nativejoin(base, path):
"""
Joins two paths - returning a native file path.
Given a base path and a relative location, (in posix format)
return a file path in a (relatively) OS native way.
"""
return url2pathname(pathjoin(base, path))
示例13: s3_open
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def s3_open(self, req):
# The implementation was inspired mainly by the code behind
# urllib.request.FileHandler.file_open().
#
# recipe copied from:
# http://code.activestate.com/recipes/578957-urllib-handler-for-amazon-s3-buckets/
# converted to boto3
if version_info[0] < 3:
bucket_name = req.get_host()
key_name = url2pathname(req.get_selector())[1:]
else:
bucket_name = req.host
key_name = url2pathname(req.selector)[1:]
if not bucket_name or not key_name:
raise URLError('url must be in the format s3://<bucket>/<key>')
s3 = boto3.resource('s3')
key = s3.Object(bucket_name, key_name)
client = boto3.client('s3')
obj = client.get_object(Bucket=bucket_name, Key=key_name)
filelike = _FileLikeKey(obj['Body'])
origurl = 's3://{}/{}'.format(bucket_name, key_name)
if key is None:
raise URLError('no such resource: {}'.format(origurl))
headers = [
('Content-type', key.content_type),
('Content-encoding', key.content_encoding),
('Content-language', key.content_language),
('Content-length', key.content_length),
('Etag', key.e_tag),
('Last-modified', key.last_modified),
]
headers = email.message_from_string(
'\n'.join('{}: {}'.format(key, value) for key, value in headers
if value is not None))
return addinfourl(filelike, headers, origurl)
示例14: process_single_item
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def process_single_item(
item: Union[bytes, str],
args: IcatCLIOptions,
parsed_opts: ParsedOpts,
url_pat: Optional[Pattern] = None,
maybe_dir: bool = True
) -> None:
is_tempfile = False
file_removed = False
try:
if isinstance(item, bytes):
tf = NamedTemporaryFile(prefix='stdin-image-data-', delete=False)
tf.write(item), tf.close()
item = tf.name
is_tempfile = True
if url_pat is not None and url_pat.match(item) is not None:
from urllib.request import urlretrieve
with NamedTemporaryFile(prefix='url-image-data-', delete=False) as tf:
try:
with socket_timeout(30):
urlretrieve(item, filename=tf.name)
except Exception as e:
raise SystemExit('Failed to download image at URL: {} with error: {}'.format(item, e))
item = tf.name
is_tempfile = True
file_removed = process(item, args, parsed_opts, is_tempfile)
elif item.lower().startswith('file://'):
from urllib.parse import urlparse
from urllib.request import url2pathname
pitem = urlparse(item)
if os.sep == '\\':
item = pitem.netloc + pitem.path
else:
item = pitem.path
item = url2pathname(item)
file_removed = process(item, args, parsed_opts, is_tempfile)
else:
if maybe_dir and os.path.isdir(item):
for (x, mt) in scan(item):
process_single_item(x, args, parsed_opts, url_pat=None, maybe_dir=False)
else:
file_removed = process(item, args, parsed_opts, is_tempfile)
finally:
if is_tempfile and not file_removed:
os.remove(item)