本文整理匯總了Python中imp.source_from_cache方法的典型用法代碼示例。如果您正苦於以下問題:Python imp.source_from_cache方法的具體用法?Python imp.source_from_cache怎麽用?Python imp.source_from_cache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類imp
的用法示例。
在下文中一共展示了imp.source_from_cache方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cache_zip_file
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def cache_zip_file(self, zip_path):
"""Read a zip file and cache the modules and packages found inside it.
"""
zip = zipfile.ZipFile(zip_path)
for archiveName in zip.namelist():
baseName, ext = os.path.splitext(archiveName)
if ext not in ('.pyc', '.pyo'):
continue
if '__pycache__' in baseName:
if sys.version_info[:2] < (3, 2) \
or not baseName.endswith(imp.get_tag()):
continue
baseName = os.path.splitext(source_from_cache(archiveName))[0]
nameparts = baseName.split("/")
if len(nameparts) > 1 and nameparts[-1] == '__init__':
# dir/__init__.pyc -> dir is a package
self.record_loadable_module(nameparts[:-1], None, zip, True)
self.record_loadable_module(nameparts, archiveName, zip, False)
示例2: source_from_cache
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def source_from_cache(path):
basename, ext = os.path.splitext(path)
if ext not in ('.pyc', '.pyo'):
raise ValueError('Not a cached Python file extension', ext)
# Should we look for .pyw files?
return basename + '.py'
示例3: test_source_from_cache
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def test_source_from_cache(self):
# Given the path to a PEP 3147 defined .pyc file, return the path to
# its source. This tests the good path.
path = os.path.join('foo', 'bar', 'baz', '__pycache__',
'qux.{}.pyc'.format(self.tag))
expect = os.path.join('foo', 'bar', 'baz', 'qux.py')
self.assertEqual(imp.source_from_cache(path), expect)
示例4: test_source_from_cache_no_cache_tag
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def test_source_from_cache_no_cache_tag(self):
# If sys.implementation.cache_tag is None, raise NotImplementedError.
path = os.path.join('blah', '__pycache__', 'whatever.pyc')
with support.swap_attr(sys.implementation, 'cache_tag', None):
with self.assertRaises(NotImplementedError):
imp.source_from_cache(path)
示例5: test_source_from_cache_bad_path
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def test_source_from_cache_bad_path(self):
# When the path to a pyc file is not in PEP 3147 format, a ValueError
# is raised.
self.assertRaises(
ValueError, imp.source_from_cache, '/foo/bar/bazqux.pyc')
示例6: test_source_from_cache_no_slash
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def test_source_from_cache_no_slash(self):
# No slashes at all in path -> ValueError
self.assertRaises(
ValueError, imp.source_from_cache, 'foo.cpython-32.pyc')
示例7: test_source_from_cache_too_few_dots
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def test_source_from_cache_too_few_dots(self):
# Too few dots in final path component -> ValueError
self.assertRaises(
ValueError, imp.source_from_cache, '__pycache__/foo.pyc')
示例8: test_source_from_cache_no__pycache__
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def test_source_from_cache_no__pycache__(self):
# Another problem with the path -> ValueError
self.assertRaises(
ValueError, imp.source_from_cache,
'/foo/bar/foo.cpython-32.foo.pyc')
示例9: source_from_cache
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import source_from_cache [as 別名]
def source_from_cache(path): # Pre PEP 3147 - cache is just .pyc/.pyo
assert path.endswith(('.pyc', '.pyo'))
return path[:-1]