Fix for six.py

This commit is contained in:
echel0n 2014-04-22 08:08:22 -07:00
commit 4a9a378d52

View file

@ -25,7 +25,7 @@ import sys
import types import types
__author__ = "Benjamin Peterson <benjamin@python.org>" __author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.6.1" __version__ = "1.5.2"
# Useful for very coarse version differentiation. # Useful for very coarse version differentiation.
@ -83,11 +83,7 @@ class _LazyDescr(object):
self.name = name self.name = name
def __get__(self, obj, tp): def __get__(self, obj, tp):
try: result = self._resolve()
result = self._resolve()
except ImportError:
# See the nice big comment in MovedModule.__getattr__.
raise AttributeError("%s could not be imported " % self.name)
setattr(obj, self.name, result) # Invokes __set__. setattr(obj, self.name, result) # Invokes __set__.
# This is a bit ugly, but it avoids running this again. # This is a bit ugly, but it avoids running this again.
delattr(obj.__class__, self.name) delattr(obj.__class__, self.name)
@ -109,22 +105,15 @@ class MovedModule(_LazyDescr):
return _import_module(self.mod) return _import_module(self.mod)
def __getattr__(self, attr): def __getattr__(self, attr):
# It turns out many Python frameworks like to traverse sys.modules and # Hack around the Django autoreloader. The reloader tries to get
# try to load various attributes. This causes problems if this is a # __file__ or __name__ of every module in sys.modules. This doesn't work
# platform-specific module on the wrong platform, like _winreg on # well if this MovedModule is for an module that is unavailable on this
# Unixes. Therefore, we silently pretend unimportable modules do not # machine (like winreg on Unix systems). Thus, we pretend __file__ and
# have any attributes. See issues #51, #53, #56, and #63 for the full # __name__ don't exist if the module hasn't been loaded yet. See issues
# tales of woe. # #51 and #53.
# if attr in ("__file__", "__name__") and self.mod not in sys.modules:
# First, if possible, avoid loading the module just to look at __file__, raise AttributeError
# __name__, or __path__. _module = self._resolve()
if (attr in ("__file__", "__name__", "__path__") and
self.mod not in sys.modules):
raise AttributeError(attr)
try:
_module = self._resolve()
except ImportError:
raise AttributeError(attr)
value = getattr(_module, attr) value = getattr(_module, attr)
setattr(self, attr, value) setattr(self, attr, value)
return value return value
@ -233,7 +222,6 @@ _moved_attributes = [
MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"), MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"), MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
MovedModule("xmlrpc_server", "xmlrpclib", "xmlrpc.server"),
MovedModule("winreg", "_winreg"), MovedModule("winreg", "_winreg"),
] ]
for attr in _moved_attributes: for attr in _moved_attributes:
@ -253,7 +241,6 @@ class Module_six_moves_urllib_parse(_LazyModule):
_urllib_parse_moved_attributes = [ _urllib_parse_moved_attributes = [
MovedAttribute("ParseResult", "urlparse", "urllib.parse"), MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
MovedAttribute("SplitResult", "urlparse", "urllib.parse"),
MovedAttribute("parse_qs", "urlparse", "urllib.parse"), MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
MovedAttribute("parse_qsl", "urlparse", "urllib.parse"), MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
MovedAttribute("urldefrag", "urlparse", "urllib.parse"), MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
@ -267,7 +254,6 @@ _urllib_parse_moved_attributes = [
MovedAttribute("unquote", "urllib", "urllib.parse"), MovedAttribute("unquote", "urllib", "urllib.parse"),
MovedAttribute("unquote_plus", "urllib", "urllib.parse"), MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
MovedAttribute("urlencode", "urllib", "urllib.parse"), MovedAttribute("urlencode", "urllib", "urllib.parse"),
MovedAttribute("splitquery", "urllib", "urllib.parse"),
] ]
for attr in _urllib_parse_moved_attributes: for attr in _urllib_parse_moved_attributes:
setattr(Module_six_moves_urllib_parse, attr.name, attr) setattr(Module_six_moves_urllib_parse, attr.name, attr)