summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick van Hattem <wolph@wol.ph>2015-01-13 09:57:22 +0100
committerRick van Hattem <wolph@wol.ph>2015-01-13 09:57:22 +0100
commit9a29821c96be607794cf7d455b8bbfc0197e9765 (patch)
tree59c949df1ddd8f9b206de981373865faf7bbcab5
parent7330876ca5a33ff17d30c430514e00a2650a51de (diff)
downloadsix-9a29821c96be607794cf7d455b8bbfc0197e9765.tar.gz
added flake8 for pep8 and pyflakes support
-rw-r--r--setup.cfg16
-rw-r--r--six.py85
-rw-r--r--tox.ini11
3 files changed, 92 insertions, 20 deletions
diff --git a/setup.cfg b/setup.cfg
index 5e40900..4a5b847 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,2 +1,18 @@
[wheel]
universal = 1
+
+[flake8]
+max-line-length = 100
+ignore = F821
+
+[pytest]
+minversion=2.2.0
+pep8ignore =
+ documentation/*.py ALL
+ test_six.py ALL
+
+flakes-ignore =
+ documentation/*.py ALL
+ test_six.py ALL
+ six.py UndefinedName
+
diff --git a/six.py b/six.py
index a8cdb22..b64c59e 100644
--- a/six.py
+++ b/six.py
@@ -57,6 +57,7 @@ else:
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
+
def __len__(self):
return 1 << 31
try:
@@ -88,7 +89,7 @@ class _LazyDescr(object):
def __get__(self, obj, tp):
result = self._resolve()
- setattr(obj, self.name, result) # Invokes __set__.
+ setattr(obj, self.name, result) # Invokes __set__.
try:
# This is a bit ugly, but it avoids running this again by
# removing this descriptor.
@@ -160,12 +161,14 @@ class MovedAttribute(_LazyDescr):
class _SixMetaPathImporter(object):
+
"""
A meta path importer to import six.moves and its submodules.
This class implements a PEP302 finder and loader. It should be compatible
with Python 2.5 and all existing versions of Python3
"""
+
def __init__(self, six_module_name):
self.name = six_module_name
self.known_modules = {}
@@ -223,6 +226,7 @@ _importer = _SixMetaPathImporter(__name__)
class _MovedItems(_LazyModule):
+
"""Lazy loading of moved objects"""
__path__ = [] # mark as package
@@ -230,7 +234,12 @@ class _MovedItems(_LazyModule):
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
- MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"),
+ MovedAttribute(
+ "filterfalse",
+ "itertools",
+ "itertools",
+ "ifilterfalse",
+ "filterfalse"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("intern", "__builtin__", "sys"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
@@ -244,7 +253,12 @@ _moved_attributes = [
MovedAttribute("UserString", "UserString", "collections"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
- MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
+ MovedAttribute(
+ "zip_longest",
+ "itertools",
+ "itertools",
+ "izip_longest",
+ "zip_longest"),
MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
@@ -256,8 +270,14 @@ _moved_attributes = [
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
MovedModule("http_client", "httplib", "http.client"),
- MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
- MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"),
+ MovedModule(
+ "email_mime_multipart",
+ "email.MIMEMultipart",
+ "email.mime.multipart"),
+ MovedModule(
+ "email_mime_nonmultipart",
+ "email.MIMENonMultipart",
+ "email.mime.nonmultipart"),
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
@@ -271,8 +291,14 @@ _moved_attributes = [
MovedModule("tkinter", "Tkinter"),
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
- MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
- MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
+ MovedModule(
+ "tkinter_scrolledtext",
+ "ScrolledText",
+ "tkinter.scrolledtext"),
+ MovedModule(
+ "tkinter_simpledialog",
+ "SimpleDialog",
+ "tkinter.simpledialog"),
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
@@ -286,9 +312,22 @@ _moved_attributes = [
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
"tkinter.simpledialog"),
- MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
- MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
- MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
+ MovedModule(
+ "urllib_parse",
+ __name__ +
+ ".moves.urllib_parse",
+ "urllib.parse"),
+ MovedModule(
+ "urllib_error",
+ __name__ +
+ ".moves.urllib_error",
+ "urllib.error"),
+ MovedModule(
+ "urllib",
+ __name__ +
+ ".moves.urllib",
+ __name__ +
+ ".moves.urllib"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
@@ -307,6 +346,7 @@ _importer._add_module(moves, "moves")
class Module_six_moves_urllib_parse(_LazyModule):
+
"""Lazy loading of moved objects in six.moves.urllib_parse"""
@@ -346,6 +386,7 @@ _importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_pa
class Module_six_moves_urllib_error(_LazyModule):
+
"""Lazy loading of moved objects in six.moves.urllib_error"""
@@ -365,6 +406,7 @@ _importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.er
class Module_six_moves_urllib_request(_LazyModule):
+
"""Lazy loading of moved objects in six.moves.urllib_request"""
@@ -383,7 +425,10 @@ _urllib_request_moved_attributes = [
MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
- MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
+ MovedAttribute(
+ "HTTPPasswordMgrWithDefaultRealm",
+ "urllib2",
+ "urllib.request"),
MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
@@ -414,6 +459,7 @@ _importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.
class Module_six_moves_urllib_response(_LazyModule):
+
"""Lazy loading of moved objects in six.moves.urllib_response"""
@@ -434,6 +480,7 @@ _importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib
class Module_six_moves_urllib_robotparser(_LazyModule):
+
"""Lazy loading of moved objects in six.moves.urllib_robotparser"""
@@ -451,6 +498,7 @@ _importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.url
class Module_six_moves_urllib(types.ModuleType):
+
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
__path__ = [] # mark as package
parse = _importer._get_module("moves.urllib_parse")
@@ -595,6 +643,7 @@ _add_doc(iterlists,
if PY3:
def b(s):
return s.encode("latin-1")
+
def u(s):
return s
unichr = chr
@@ -614,12 +663,15 @@ else:
def b(s):
return s
# Workaround for standalone backslash
+
def u(s):
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
unichr = unichr
int2byte = chr
+
def byte2int(bs):
return ord(bs[0])
+
def indexbytes(buf, i):
return ord(buf[i])
iterbytes = functools.partial(itertools.imap, ord)
@@ -632,7 +684,6 @@ _add_doc(u, """Text literal""")
if PY3:
exec_ = getattr(moves.builtins, "exec")
-
def reraise(tp, value, tb=None):
if value is None:
value = tp()
@@ -653,7 +704,6 @@ else:
_locs_ = _globs_
exec("""exec _code_ in _globs_, _locs_""")
-
exec_("""def reraise(tp, value, tb=None):
raise tp, value, tb
""")
@@ -675,13 +725,14 @@ if print_ is None:
fp = kwargs.pop("file", sys.stdout)
if fp is None:
return
+
def write(data):
if not isinstance(data, basestring):
data = str(data)
# If the file has an encoding, encode unicode with it.
if (isinstance(fp, file) and
- isinstance(data, unicode) and
- fp.encoding is not None):
+ isinstance(data, unicode) and
+ fp.encoding is not None):
errors = getattr(fp, "errors", None)
if errors is None:
errors = "strict"
@@ -736,12 +787,14 @@ if sys.version_info[0:2] < (3, 4):
else:
wraps = functools.wraps
+
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
# This requires a bit of explanation: the basic idea is to make a dummy
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
class metaclass(meta):
+
def __new__(cls, name, this_bases, d):
return meta(name, bases, d)
return type.__new__(metaclass, 'temporary_class', (), {})
@@ -779,7 +832,7 @@ if sys.meta_path:
# the six meta path importer, since the other six instance will have
# inserted an importer with different class.
if (type(importer).__name__ == "_SixMetaPathImporter" and
- importer.name == __name__):
+ importer.name == __name__):
del sys.meta_path[i]
break
del i, importer
diff --git a/tox.ini b/tox.ini
index b29b31a..09131f8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,15 @@
[tox]
-envlist=py25,py26,py27,py31,py32,py33,py34,pypy
+envlist=py25,py26,py27,py31,py32,py33,py34,pypy,flake8
indexserver=
default = http://pypi.python.org/simple
testrun = http://pypi.testrun.org
[testenv]
-deps=pytest
+deps= pytest
commands= py.test -rfsxX {posargs}
-[pytest]
-minversion=2.2.0
+[testenv:flake8]
+basepython=python
+deps=flake8
+commands= flake8 six.py
+