本文整理汇总了Python中arelle.PackageManager.isMappedUrl方法的典型用法代码示例。如果您正苦于以下问题:Python PackageManager.isMappedUrl方法的具体用法?Python PackageManager.isMappedUrl怎么用?Python PackageManager.isMappedUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arelle.PackageManager
的用法示例。
在下文中一共展示了PackageManager.isMappedUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: openFileStream
# 需要导入模块: from arelle import PackageManager [as 别名]
# 或者: from arelle.PackageManager import isMappedUrl [as 别名]
def openFileStream(cntlr, filepath, mode='r', encoding=None):
if PackageManager.isMappedUrl(filepath):
filepath = PackageManager.mappedUrl(filepath)
else:
filepath = cntlr.modelManager.disclosureSystem.mappedUrl(filepath)
if archiveFilenameParts(filepath): # file is in an archive
return openFileSource(filepath, cntlr).file(filepath, binary='b' in mode, encoding=encoding)[0]
if isHttpUrl(filepath) and cntlr:
_cacheFilepath = cntlr.webCache.getfilename(filepath)
if _cacheFilepath is None:
raise IOError(_("Unable to open file: {0}.").format(filepath))
filepath = _cacheFilepath
# file path may be server (or memcache) or local file system
if filepath.startswith(SERVER_WEB_CACHE) and cntlr:
filestream = None
cacheKey = filepath[len(SERVER_WEB_CACHE) + 1:].replace("\\","/")
if cntlr.isGAE: # check if in memcache
cachedBytes = gaeGet(cacheKey)
if cachedBytes:
filestream = io.BytesIO(cachedBytes)
if filestream is None:
filestream = io.BytesIO()
cntlr.webCache.retrieve(cntlr.webCache.cacheFilepathToUrl(filepath),
filestream=filestream)
if cntlr.isGAE:
gaeSet(cacheKey, filestream.getvalue())
if mode.endswith('t') or encoding:
contents = filestream.getvalue()
filestream.close()
filestream = FileNamedStringIO(filepath, contents.decode(encoding or 'utf-8'))
return filestream
# local file system
elif encoding is None and 'b' not in mode:
openedFileStream = io.open(filepath, mode='rb')
hdrBytes = openedFileStream.read(512)
encoding = XmlUtil.encoding(hdrBytes, default=None)
openedFileStream.close()
return io.open(filepath, mode=mode, encoding=encoding)
else:
# local file system
return io.open(filepath, mode=mode, encoding=encoding)