Anonymous avatar Anonymous committed 51ca1c4

added file container

Comments (0)

Files changed (2)

 class Distribution(object):
 
     def __init__(self, path):
-        self.info_path = path
-        self.container = os.path.split(path)[0]
+        self.path = path
+        self.container, self.info_path = os.path.split(path)
         self.pkg_info_path = join(path, 'PKG-INFO')
         self.record_path = join(path, 'RECORD')
         pkginfo = self._open_pkginfo()
     def _open_record(self):
         return open(self.record_path)
 
+    def _open_file(self, file, mode):
+        return open(file, mode)
+
     def _read_record(self):
         """Reads RECORD."""
         files = []
         path into a local absolute path.
         """
         self._load_record()  # initializes self._files
-
         for location, md5, size  in self._files:
             local_path = self._local_path(location)
-            if not local_path.startswith(self.info_path):
+            if not local_path.startswith(self.path):
                 continue
-            # the file is located under self.info_path
+            # the file is located under self.path
             if local:
                 yield local_path
             else:
         """
         path = path.translate(SEP_TRANS)
         if path[0] != '/':
-            local_path = join(self.info_path, path)
+            local_path = join(self.path, path)
         else:
             local_path = join(self.container, path)
 
-            if not local_path.startswith(self.info_path):
+            if not local_path.startswith(self.path):
                 raise DistutilsError('%s is not located in %s' % \
-                                     (path, self.info_path))
-        return open(local_path, binary and 'rb' or 'r')
+                                     (path, self.path))
+        return self._open_file(local_path, binary and 'rb' or 'r')
 
 class ZippedDistribution(Distribution):
 
         self.zipfile = zipfile
         super(ZippedDistribution, self).__init__(path)
         self.container = self.zipfile.filename
+        self.path = join(self.zipfile.filename, path)
 
     def _open_pkginfo(self):
         return self.zipfile.open(self.pkg_info_path)
     def _open_record(self):
         return self.zipfile.open(self.record_path)
 
+    def _open_file(self, path, mode):
+        if path.startswith(self.container):
+            path = path[len(self.container)+1:]
+        return self.zipfile.open(path, mode)
+
 #
 # DistributionDirectory represents a directory that contains egg-info files
 #
     pkgutil._dist_dirs.load([SITE_PKG])
 
 def teardown():
+    if not hasattr(sys, 'old'):
+        return
     sys.path = sys.old
     del sys.old
 
 
     files = list(dist.get_installed_files(local=True))
 
-    site_packages = os.path.split(dist.info_path)[0]
-    location = os.path.join(site_packages, 'mercurial', 'filelog.py')
+    location = os.path.join(dist.container, 'mercurial', 'filelog.py')
     assert_equals(files[0], (location, '98676876876876', '12'))
 
     f = dist.get_egginfo_file('RECORD')
                    'mercurial-1.0.1.egg-info/RECORD'])
 
     assert_equals(list(dist.get_egginfo_files(local=True)),
-                  [os.path.join(SITE_PKG, 'mercurial-1.0.1.egg-info/PKG_INFO'),
-                   os.path.join(SITE_PKG, 'mercurial-1.0.1.egg-info/RECORD')])
+                  [os.path.join(SITE_PKG+'.zip',
+                                'mercurial-1.0.1.egg-info/PKG_INFO'),
+                   os.path.join(SITE_PKG+'.zip',
+                                'mercurial-1.0.1.egg-info/RECORD')])
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.