aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Thiem <ptthiem@gmail.com>2013-02-16 11:34:11 -0600
committerPhilip Thiem <ptthiem@gmail.com>2013-02-16 11:34:11 -0600
commit6f6de308e3ade9a262308297f0a96af261c9dde5 (patch)
treef473feb90ac264b1804437b6905b315b185130ec
parent4e2823bc3f2f5505ee15fc72ebcc287e5061199d (diff)
downloadexternal_python_setuptools-6f6de308e3ade9a262308297f0a96af261c9dde5.tar.gz
external_python_setuptools-6f6de308e3ade9a262308297f0a96af261c9dde5.tar.bz2
external_python_setuptools-6f6de308e3ade9a262308297f0a96af261c9dde5.zip
Backout the pkg_resources.py fix
--HG-- branch : distribute extra : rebase_source : d144d2afc763c9ed6420d32bad3015075d265226
-rw-r--r--pkg_resources.py51
-rw-r--r--setuptools/tests/win_script_wrapper.txt6
2 files changed, 14 insertions, 43 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index c29afb56..fbae7b57 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -13,8 +13,7 @@ The package resource API is designed to work with normal filesystem packages,
method.
"""
-import sys, os, zipimport, time, re, imp, types
-import zipfile
+import sys, os, zipimport, time, re, imp, types
from urlparse import urlparse, urlunparse
try:
@@ -1350,37 +1349,6 @@ class EmptyProvider(NullProvider):
empty_provider = EmptyProvider()
-def build_zipmanifest(path):
- """
- This builds a similar dictionary to the zipimport directory
- caches. However instead of tuples, ZipInfo objects are stored.
-
- The translation of the tuple is as follows:
- * [0] - zipinfo.filename on stock pythons this needs "/" --> os.sep
- on pypy it is the same (one reason why distribute did work
- in some cases on pypy and win32).
- * [1] - zipinfo.compress_type
- * [2] - zipinfo.compress_size
- * [3] - zipinfo.file_size
- * [4] - len(utf-8 encoding of filename) if zipinfo & 0x800
- len(ascii encoding of filename) otherwise
- * [5] - (zipinfo.date_time[0] - 1980) << 9 |
- zipinfo.date_time[1] << 5 | zipinfo.date_time[2]
- * [6] - (zipinfo.date_time[3] - 1980) << 11 |
- zipinfo.date_time[4] << 5 | (zipinfo.date_time[5] // 2)
- * [7] - zipinfo.CRC
- """
- zipinfo = dict()
- zfile = zipfile.ZipFile(path)
- #Got ZipFile has not __exit__ on python 3.1
- try:
- for zitem in zfile.namelist():
- zpath = zitem.replace('/', os.sep)
- zipinfo[zpath] = zfile.getinfo(zitem)
- assert zipinfo[zpath] is not None
- finally:
- zfile.close()
- return zipinfo
class ZipProvider(EggProvider):
@@ -1390,7 +1358,7 @@ class ZipProvider(EggProvider):
def __init__(self, module):
EggProvider.__init__(self,module)
- self.zipinfo = build_zipmanifest(self.load.archive)
+ self.zipinfo = zipimport._zip_directory_cache[self.loader.archive]
self.zip_pre = self.loader.archive+os.sep
def _zipinfo_name(self, fspath):
@@ -1425,10 +1393,12 @@ class ZipProvider(EggProvider):
return self._extract_resource(manager, zip_path)
@staticmethod
- def _get_date_and_size(zip_stat):
- size = zip_stat.file_size
- date_time = zip_stat.date_time + (0, 0, -1) # ymdhms+wday, yday, dst
- #1980 offset already done
+ def _get_date_and_size(zip_stat):
+ t,d,size = zip_stat[5], zip_stat[6], zip_stat[3]
+ date_time = (
+ (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd
+ (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc.
+ )
timestamp = time.mktime(date_time)
return timestamp, size
@@ -1441,7 +1411,7 @@ class ZipProvider(EggProvider):
)
return os.path.dirname(last) # return the extracted directory name
- timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
+ timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
if not WRITE_SUPPORT:
raise IOError('"os.rename" and "os.unlink" are not supported '
@@ -1640,7 +1610,7 @@ class EggMetadata(ZipProvider):
def __init__(self, importer):
"""Create a metadata provider from a zipimporter"""
- self.zipinfo = build_zipmanifest(importer.archive)
+ self.zipinfo = zipimport._zip_directory_cache[importer.archive]
self.zip_pre = importer.archive+os.sep
self.loader = importer
if importer.prefix:
@@ -2871,4 +2841,3 @@ run_main = run_script # backward compatibility
add_activation_listener(lambda dist: dist.activate())
working_set.entries=[]; map(working_set.add_entry,sys.path) # match order
-
diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt
index 82719273..3dc725c8 100644
--- a/setuptools/tests/win_script_wrapper.txt
+++ b/setuptools/tests/win_script_wrapper.txt
@@ -54,11 +54,12 @@ the wrapper:
... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"')
>>> input.write('hello\nworld\n')
>>> input.close()
- >>> print(output.read(),)
+ >>> print(output.read())
\foo-script.py
['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
'hello\nworld\n'
non-optimized
+ <BLANKLINE>
This example was a little pathological in that it exercised windows
(MS C runtime) quoting rules:
@@ -97,11 +98,12 @@ enter the interpreter after running the script, you could use -Oi:
>>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
>>> input.close()
- >>> print(output.read(),)
+ >>> print(output.read())
\foo-script.py
[]
''
---
+ <BLANKLINE>
Testing the GUI Version
-----------------------