aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources.py
diff options
context:
space:
mode:
Diffstat (limited to 'pkg_resources.py')
-rw-r--r--pkg_resources.py69
1 files changed, 49 insertions, 20 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index 4d816e2a..03aa75ad 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -13,13 +13,41 @@ The package resource API is designed to work with normal filesystem packages,
method.
"""
-import sys, os, time, re, imp, types, zipfile, zipimport
-from urlparse import urlparse, urlunparse
+import sys, os, zipfile, zipimport, time, re, imp, types
+try:
+ from urlparse import urlparse, urlunparse
+except ImportError:
+ from urllib.parse import urlparse, urlunparse
try:
frozenset
except NameError:
from sets import ImmutableSet as frozenset
+try:
+ basestring
+ next = lambda o: o.next()
+ from cStringIO import StringIO
+ def exec_(code, globs=None, locs=None):
+ if globs is None:
+ frame = sys._getframe(1)
+ globs = frame.f_globals
+ if locs is None:
+ locs = frame.f_locals
+ del frame
+ elif locs is None:
+ locs = globs
+ exec("""exec code in globs, locs""")
+except NameError:
+ basestring = str
+ from io import StringIO
+ from functools import reduce
+ exec_ = eval("exec")
+ def execfile(fn, globs=None, locs=None):
+ if globs is None:
+ globs = globals()
+ if locs is None:
+ locs = globs
+ exec_(compile(open(fn).read(), fn, 'exec'), globs, locs)
# capture these to bypass sandboxing
from os import utime
@@ -44,7 +72,7 @@ try:
except ImportError:
pass
-def _bypass_ensure_directory(name, mode=0777):
+def _bypass_ensure_directory(name, mode=0x1FF): # 0777
# Sandbox-bypassing version of ensure_directory()
if not WRITE_SUPPORT:
raise IOError('"os.mkdir" not supported on this platform.')
@@ -58,20 +86,20 @@ _state_vars = {}
def _declare_state(vartype, **kw):
g = globals()
- for name, val in kw.iteritems():
+ for name, val in kw.items():
g[name] = val
_state_vars[name] = vartype
def __getstate__():
state = {}
g = globals()
- for k, v in _state_vars.iteritems():
+ for k, v in _state_vars.items():
state[k] = g['_sget_'+v](g[k])
return state
def __setstate__(state):
g = globals()
- for k, v in state.iteritems():
+ for k, v in state.items():
g['_sset_'+_state_vars[k]](k, g[k], v)
return state
@@ -650,7 +678,7 @@ class WorkingSet(object):
env = full_env + plugin_env
shadow_set = self.__class__([])
- map(shadow_set.add, self) # put all our entries in shadow_set
+ list(map(shadow_set.add, self)) # put all our entries in shadow_set
for project_name in plugin_projects:
@@ -661,7 +689,8 @@ class WorkingSet(object):
try:
resolvees = shadow_set.resolve(req, env, installer)
- except ResolutionError,v:
+ except ResolutionError:
+ v = sys.exc_info()[1]
error_info[dist] = v # save error info
if fallback:
continue # try the next older version of project
@@ -669,7 +698,7 @@ class WorkingSet(object):
break # give up on this project, keep going
else:
- map(shadow_set.add, resolvees)
+ list(map(shadow_set.add, resolvees))
distributions.update(dict.fromkeys(resolvees))
# success, no need to try any more versions of this project
@@ -718,7 +747,8 @@ class WorkingSet(object):
self.callbacks[:]
)
- def __setstate__(self, (entries, keys, by_key, callbacks)):
+ def __setstate__(self, e_k_b_c):
+ entries, keys, by_key, callbacks = e_k_b_c
self.entries = entries[:]
self.entry_keys = keys.copy()
self.by_key = by_key.copy()
@@ -1029,7 +1059,7 @@ variable to point to an accessible directory.
if os.name == 'posix':
# Make the resource executable
- mode = ((os.stat(tempname).st_mode) | 0555) & 07777
+ mode = ((os.stat(tempname).st_mode) | 0x16D) & 0xFFF # 0555, 07777
os.chmod(tempname, mode)
@@ -1401,7 +1431,7 @@ class NullProvider:
len(script_text), 0, script_text.split('\n'), script_filename
)
script_code = compile(script_text,script_filename,'exec')
- exec script_code in namespace, namespace
+ exec_(script_code, namespace, namespace)
def _has(self, path):
raise NotImplementedError(
@@ -1921,7 +1951,7 @@ def StringIO(*args, **kw):
try:
from cStringIO import StringIO
except ImportError:
- from StringIO import StringIO
+ from io import StringIO
return StringIO(*args,**kw)
def find_nothing(importer, path_item, only=False):
@@ -2219,8 +2249,8 @@ class EntryPoint(object):
def require(self, env=None, installer=None):
if self.extras and not self.dist:
raise UnknownExtra("Can't require() without a distribution", self)
- map(working_set.add,
- working_set.resolve(self.dist.requires(self.extras),env,installer))
+ list(map(working_set.add,
+ working_set.resolve(self.dist.requires(self.extras),env,installer)))
@@ -2491,7 +2521,7 @@ class Distribution(object):
def __getattr__(self,attr):
"""Delegate all unrecognized public attributes to .metadata provider"""
if attr.startswith('_'):
- raise AttributeError,attr
+ raise AttributeError(attr)
return getattr(self._provider, attr)
@@ -2672,7 +2702,7 @@ class DistInfoDistribution(Distribution):
# Including any condition expressions
for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
distvers, mark = self._preparse_requirement(req)
- parsed = parse_requirements(distvers).next()
+ parsed = next(parse_requirements(distvers))
parsed.marker_fn = compile_marker(mark)
reqs.append(parsed)
@@ -2747,7 +2777,7 @@ def parse_requirements(strs):
while not TERMINATOR(line,p):
if CONTINUE(line,p):
try:
- line = lines.next(); p = 0
+ line = next(lines); p = 0
except StopIteration:
raise ValueError(
"\\ must not appear on the last nonblank line"
@@ -2976,6 +3006,5 @@ run_main = run_script # backward compatibility
# all distributions added to the working set in the future (e.g. by
# calling ``require()``) will get activated as well.
add_activation_listener(lambda dist: dist.activate())
-working_set.entries=[]; map(working_set.add_entry,sys.path) # match order
-
+working_set.entries=[]; list(map(working_set.add_entry,sys.path)) # match order