MCPcopy Create free account
hub / github.com/twisted/twisted / mapPath

Method mapPath

src/twisted/python/modules.py:503–524  ·  view source on GitHub ↗

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.

(self, fsPathString)

Source from the content-addressed store, hash-verified

501 self.importer = importer
502
503 def mapPath(self, fsPathString):
504 """
505 Map the given FS path to a ZipPath, by looking at the ZipImporter's
506 "archive" attribute and using it as our ZipArchive root, then walking
507 down into the archive from there.
508
509 @return: a L{zippath.ZipPath} or L{zippath.ZipArchive} instance.
510 """
511 za = ZipArchive(self.importer.archive)
512 myPath = FilePath(self.importer.archive)
513 itsPath = FilePath(fsPathString)
514 if myPath == itsPath:
515 return za
516 # This is NOT a general-purpose rule for sys.path or __file__:
517 # zipimport specifically uses regular OS path syntax in its
518 # pathnames, even though zip files specify that slashes are always
519 # the separator, regardless of platform.
520 segs = itsPath.segmentsFrom(myPath)
521 zp = za
522 for seg in segs:
523 zp = zp.child(seg)
524 return zp
525
526
527registerAdapter(_ZipMapImpl, zipimport.zipimporter, IPathImportMapper)

Callers 1

_smartPathMethod · 0.45

Calls 4

ZipArchiveClass · 0.90
FilePathClass · 0.90
segmentsFromMethod · 0.80
childMethod · 0.45

Tested by

no test coverage detected