本文整理汇总了Python中urllib.request.url2pathname函数的典型用法代码示例。如果您正苦于以下问题:Python url2pathname函数的具体用法?Python url2pathname怎么用?Python url2pathname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url2pathname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: path
def path(source, res=''):
if source:
res = url2pathname(source.url) + '>>' + res
path(source.prev, res)
else:
res += url2pathname(philosophy)
print(res)
示例2: play
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:]))
示例3: readMedia
def readMedia(self, media):
conf = {}
uuid = ''
for opt in media:
if(opt.attrib['name'] == 'uuid'):
uuid = url.url2pathname(opt.attrib['value'])
else:
conf[opt.attrib['name']] = literal_eval(url.url2pathname(opt.attrib['value']))
return (uuid, conf)
示例4: identify
def identify(self, song):
media = self.instance.media_new(song.path)
media.parse()
media.get_meta(vlc.Meta.Album)
track_info = {}
try:
track_info = {
'track_nb': media.get_meta(vlc.Meta.TrackNumber),
'title': media.get_meta(vlc.Meta.Title),
'album': media.get_meta(vlc.Meta.Album),
'artist': media.get_meta(vlc.Meta.Artist),
'label': media.get_meta(vlc.Meta.Publisher),
'date': media.get_meta(vlc.Meta.Date),
'genre': media.get_meta(vlc.Meta.Genre),
'artwork': media.get_meta(vlc.Meta.ArtworkURL)
}
if track_info['artwork'] is not None:
track_info['artwork'] = url2pathname(track_info['artwork'][7:])
print(track_info)
except:
# TODO:
# - clean messed up tags
# - create empty trackinfos
pass
# return track_info
song.track_info = track_info
示例5: drag_data_received
def drag_data_received(self,widget, drag_context, x, y, selection_data, info, timestamp):
model = self.treeview.get_model()
for filename in selection_data.get_uris():
if len(filename)>8:
filename = url2pathname(filename)
filename = filename[7:]
model.append([filename])
示例6: drag_data_received
def drag_data_received(self, widget, context, x, y, sel_data, info, time):
"""
Handle the standard gtk interface for drag_data_received.
If the selection data is define, extract the value from sel_data.data,
and decide if this is a move or a reorder.
The only data we accept on mediaview is dropping a file, so URI_LIST.
We assume this is what we obtain
"""
if not sel_data:
return
files = sel_data.get_uris()
for file in files:
protocol, site, mfile, j, k, l = urlparse(file)
if protocol == "file":
name = url2pathname(mfile)
mime = get_type(name)
if not is_valid_type(mime):
return
photo = Media()
self.uistate.set_busy_cursor(True)
photo.set_checksum(create_checksum(name))
self.uistate.set_busy_cursor(False)
base_dir = str(media_path(self.dbstate.db))
if os.path.exists(base_dir):
name = relative_path(name, base_dir)
photo.set_path(name)
photo.set_mime_type(mime)
basename = os.path.basename(name)
(root, ext) = os.path.splitext(basename)
photo.set_description(root)
with DbTxn(_("Drag Media Object"), self.dbstate.db) as trans:
self.dbstate.db.add_media(photo, trans)
widget.emit_stop_by_name('drag_data_received')
示例7: run
def run(node):
"""
Primary entry-point for running this module.
:param node: dict
{
"url": "https://some-site.com"
}
:return:
{
document_url: metadata,
...
}
:rtype: dict
"""
mapper = lambda x: redis_load(x, r)
url = node.get('url', 'http://www.cic.gc.ca')
pool = ThreadPool(32)
docs = redis_docs(url, r)
metadata = pool.map(mapper, docs)
return {
url2pathname(k): v
for k,v in metadata if v
}
示例8: get_filename
def get_filename(self, basename):
"""
Returns full path to a file, for example:
get_filename('css/one.css') -> '/full/path/to/static/css/one.css'
"""
filename = None
# first try finding the file in the root
try:
# call path first so remote storages don't make it to exists,
# which would cause network I/O
filename = self.storage.path(basename)
if not self.storage.exists(basename):
filename = None
except NotImplementedError:
# remote storages don't implement path, access the file locally
if compressor_file_storage.exists(basename):
filename = compressor_file_storage.path(basename)
# secondly try to find it with staticfiles (in debug mode)
if not filename and self.finders:
filename = self.finders.find(url2pathname(basename))
if filename:
return filename
# or just raise an exception as the last resort
raise UncompressableFileError(
"'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
(basename, settings.COMPRESS_ROOT,
self.finders and " or with staticfiles." or "."))
示例9: url_to_file_path
def url_to_file_path(self, url):
url_path = urlparse(url).path
if url_path.endswith('/'):
url_path += 'index.html'
if url_path.startswith('/'):
url_path = url_path[1:]
return url2pathname(url_path)
示例10: _url_to_local_path
def _url_to_local_path(url, path):
"""Mirror a url path in a local destination (keeping folder structure)."""
destination = parse.urlparse(url).path
# First char should be '/', and it needs to be discarded
if len(destination) < 2 or destination[0] != '/':
raise ValueError('Invalid URL')
destination = os.path.join(path, request.url2pathname(destination)[1:])
return destination
示例11: file_uri_to_path
def file_uri_to_path(uri):
if PathCreateFromUrlW is not None:
path_len = ctypes.c_uint32(260)
path = ctypes.create_unicode_buffer(path_len.value)
PathCreateFromUrlW(uri, path, ctypes.byref(path_len), 0)
return path.value
else:
return url2pathname(urlparse(uri).path)
示例12: nativejoin
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: _get_filesystem_path
def _get_filesystem_path(self, url_path, basedir=settings.MEDIA_ROOT):
"""
Makes a filesystem path from the specified URL path
"""
if url_path.startswith(settings.MEDIA_URL):
# strip media root url
url_path = url_path[len(settings.MEDIA_URL):]
return os.path.normpath(os.path.join(basedir, url2pathname(url_path)))
示例14: format_uri
def format_uri(self, uri):
path = url2pathname(uri) # escape special chars
path = path.strip('\r\n\x00') # remove \r\n and NULL
if path.startswith('file:\\\\\\'): # windows
path = path[8:] # 8 is len('file:///')
elif path.startswith('file://'): #nautilus, rox
path = path[7:] # 7 is len('file://')
elif path.startswith('file:'): # xffm
path = path[5:] # 5 is len('file:')
return path
示例15: urlpath2path
def urlpath2path(url):
"""Like :func:`ur.url2pathname()`, but prefixing with UNC(\\\\?\\) long paths and preserving last slash."""
import urllib.request as ur
p = ur.url2pathname(url)
if _is_dir_regex.search(url) and p[-1] != os.sep:
p = p + osp.sep
if len(p) > 200:
p += _unc_prefix
return p