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)
| 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 | |
| 527 | registerAdapter(_ZipMapImpl, zipimport.zipimporter, IPathImportMapper) |
no test coverage detected