本文整理汇总了Python中twisted.python.filepath.FilePath.segmentsFrom方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.segmentsFrom方法的具体用法?Python FilePath.segmentsFrom怎么用?Python FilePath.segmentsFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.segmentsFrom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _UnixFixHome
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import segmentsFrom [as 别名]
class _UnixFixHome(object):
"""
Mixin class to fix the HOME environment variable to something usable.
@ivar home: FilePath pointing at C{homePath}.
@type home: L{FilePath}
@ivar homePath: relative path to the directory used as HOME during the
tests.
@type homePath: C{str}
"""
def setUp(self):
path = self.mktemp()
self.home = FilePath(path)
self.homePath = os.path.join(*self.home.segmentsFrom(FilePath(".")))
if len(self.home.path) >= 70:
# UNIX_MAX_PATH is 108, and the socket file is generally of length
# 30, so we can't rely on mktemp...
self.homePath = "_tmp"
self.home = FilePath(self.homePath)
self.home.makedirs()
self.savedEnviron = os.environ.copy()
os.environ["HOME"] = self.homePath
def tearDown(self):
os.environ.clear()
os.environ.update(self.savedEnviron)
self.home.remove()
示例2: mapPath
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import segmentsFrom [as 别名]
def mapPath(self, fsPathString):
"""
Map the given FS path to a ZipPath, by looking at the ZipImporter's
"archive" attribute and using it as our ZipArchive root, then walking
down into the archive from there.
@return: a L{zippath.ZipPath} or L{zippath.ZipArchive} instance.
"""
za = ZipArchive(self.importer.archive)
myPath = FilePath(self.importer.archive)
itsPath = FilePath(fsPathString)
if myPath == itsPath:
return za
# This is NOT a general-purpose rule for sys.path or __file__:
# zipimport specifically uses regular OS path syntax in its pathnames.
segs = itsPath.segmentsFrom(myPath)
zp = za
for seg in segs:
zp = zp.child(seg)
return zp