本文整理汇总了Python中PySide.QtCore.QUrl.decode方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.decode方法的具体用法?Python QUrl.decode怎么用?Python QUrl.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.decode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_url
# 需要导入模块: from PySide.QtCore import QUrl [as 别名]
# 或者: from PySide.QtCore.QUrl import decode [as 别名]
def handle_url(path, style, url, for_import=False):
if ((url.startswith('"') and url.endswith('"')) or
(url.startswith("'") and url.endswith("'"))):
url = url[1:-1]
# Make a QUrl.
url = QUrl(url.decode('unicode_escape'))
if url.scheme() == 'data':
return data_url(url)
# If it's relative, build an absolute URL. If not, return.
if not url.isRelative():
return
url = url.toLocalFile()
if url.startswith('/'):
url = url[1:]
else:
url = style.path.join(path, url)
if for_import:
return url
return find_url(style, url)
示例2: _qss_url
# 需要导入模块: from PySide.QtCore import QUrl [as 别名]
# 或者: from PySide.QtCore.QUrl import decode [as 别名]
def _qss_url(self, path, url, allow_inheritance=True, _suppress=False,
for_import=False):
"""
Process a url() and return an absolute URL, or None if the URL isn't
valid.
"""
if (url.startswith('"') and url.endswith('"')) or \
(url.startswith("'") and url.endswith("'")):
url = url[1:-1]
# Make a QUrl.
url = QUrl(url.decode('unicode_escape'))
# Is it a data uri?
if url.scheme() == 'data':
# Extract the useful information from the path.
format, sep, data = url.path().partition(',')
if not sep and not data:
data = format
format = ''
mimetype, _, format = format.partition(';')
if not mimetype:
ext = 'txt'
else:
_, _, ext = mimetype.rpartition('/')
if not format:
format = 'charset=US-ASCII'
# Build the filename.
fn = os.path.join(profile.cache_path, u'data-uris',
'%s.%s' % (hashlib.md5(data).hexdigest(), ext))
# Ensure the path exists and write the file.
try:
if not os.path.exists(os.path.dirname(fn)):
os.makedirs(os.path.dirname(fn))
with open(fn, 'wb') as f:
if format == 'base64':
f.write(base64.b64decode(data))
elif format.startswith('charset='):
data = urllib.unquote(data).encode('latin1')
cs = format[8:]
if cs and cs.lower() not in ('utf-8','utf8'):
data = data.decode(cs).encode('utf-8')
f.write(data)
else:
return
except (ValueError, OSError, IOError, TypeError):
log.debug('Error parsing data URI.', exc_info=1)
return
# Substitute the right / on Windows, and return the path.
if os.name == 'nt':
fn = fn.replace('\\', '/')
return fn
# If it's relative, build an absolute URL. If not, return.
if not url.isRelative():
return
url = url.toLocalFile()
if url.startswith('/'):
url = url[1:]
else:
url = profile.join(path, url)
# If we're dealing with import, return a relative path.
if for_import:
return url
return self.get_path(url, allow_inheritance, False, _suppress)