From a2d1d9817b862da0b7b19b681b074b4323fb2ad7 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 8 Sep 2013 12:44:56 -0400 Subject: print_: encode unicode with file encoding and errors on Python 2 (fixes #35) --- six.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'six.py') diff --git a/six.py b/six.py index 85898ec..860d506 100644 --- a/six.py +++ b/six.py @@ -521,6 +521,16 @@ else: def write(data): if not isinstance(data, basestring): data = str(data) + # If the file has an encoding, encode unicode with it. In Python + # 2.7, file.write handles this. + if (sys.version_info[1] < 7 and + isinstance(fp, file) and + isinstance(data, unicode) and + fp.encoding is not None): + errors = getattr(fp, "errors", None) + if errors is None: + errors = "strict" + data = data.encode(fp.encoding, errors) fp.write(data) want_unicode = False sep = kwargs.pop("sep", None) -- cgit v1.2.1 From f517a8e36ca0032f5291a65a9cad4f19cdb75c2e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 8 Sep 2013 12:48:25 -0400 Subject: use builtin print function when possible --- six.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'six.py') diff --git a/six.py b/six.py index 860d506..d972faf 100644 --- a/six.py +++ b/six.py @@ -481,8 +481,7 @@ _add_doc(u, """Text literal""") if PY3: - import builtins - exec_ = getattr(builtins, "exec") + exec_ = getattr(moves.builtins, "exec") def reraise(tp, value, tb=None): @@ -490,10 +489,6 @@ if PY3: raise value.with_traceback(tb) raise value - - print_ = getattr(builtins, "print") - del builtins - else: def exec_(_code_, _globs_=None, _locs_=None): """Execute code in a namespace.""" @@ -513,18 +508,18 @@ else: """) +print_ = getattr(moves.builtins, "print", None) +if print_ is None: def print_(*args, **kwargs): - """The new-style print function.""" + """The new-style print function for Python 2.4 and 2.5.""" 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. In Python - # 2.7, file.write handles this. - if (sys.version_info[1] < 7 and - isinstance(fp, file) and + # If the file has an encoding, encode unicode with it. + if (isinstance(fp, file) and isinstance(data, unicode) and fp.encoding is not None): errors = getattr(fp, "errors", None) -- cgit v1.2.1 From fa8d1eebd7938b2614e798815a17e2374636feaa Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 6 Oct 2013 16:34:15 -0400 Subject: add mapping for gdbm (fixes #40) --- six.py | 1 + 1 file changed, 1 insertion(+) (limited to 'six.py') diff --git a/six.py b/six.py index d972faf..b3050c1 100644 --- a/six.py +++ b/six.py @@ -153,6 +153,7 @@ _moved_attributes = [ MovedModule("builtins", "__builtin__"), MovedModule("configparser", "ConfigParser"), MovedModule("copyreg", "copy_reg"), + MovedModule("dbm_gnu", "gdbm", "dbm.gnu"), MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), MovedModule("http_cookies", "Cookie", "http.cookies"), MovedModule("html_entities", "htmlentitydefs", "html.entities"), -- cgit v1.2.1 From b39574d169f7751e70ab4f6faa0fe8683702de6f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 6 Oct 2013 16:38:22 -0400 Subject: mapping for _thread module (fixes #39) --- six.py | 1 + 1 file changed, 1 insertion(+) (limited to 'six.py') diff --git a/six.py b/six.py index b3050c1..f3a572c 100644 --- a/six.py +++ b/six.py @@ -169,6 +169,7 @@ _moved_attributes = [ MovedModule("queue", "Queue"), MovedModule("reprlib", "repr"), MovedModule("socketserver", "SocketServer"), + MovedModule("_thread", "thread", "_thread"), MovedModule("tkinter", "Tkinter"), MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"), MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"), -- cgit v1.2.1 From c2312c1c26a9c68d4c7dad96eba5b39695adbd3f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 14 Oct 2013 10:08:41 -0400 Subject: import mapping for xmlrpclib (fixes #43) --- six.py | 1 + 1 file changed, 1 insertion(+) (limited to 'six.py') diff --git a/six.py b/six.py index f3a572c..176196c 100644 --- a/six.py +++ b/six.py @@ -191,6 +191,7 @@ _moved_attributes = [ 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("winreg", "_winreg"), ] for attr in _moved_attributes: -- cgit v1.2.1 From e381f56197542349ea616f4f71e68b481f98247c Mon Sep 17 00:00:00 2001 From: alexanderlukanin13 Date: Tue, 5 Nov 2013 16:19:16 +0600 Subject: Added six.moves.urllib.request.proxy_bypass --- six.py | 1 + 1 file changed, 1 insertion(+) (limited to 'six.py') diff --git a/six.py b/six.py index 176196c..aa6c4d5 100644 --- a/six.py +++ b/six.py @@ -284,6 +284,7 @@ _urllib_request_moved_attributes = [ MovedAttribute("urlcleanup", "urllib", "urllib.request"), MovedAttribute("URLopener", "urllib", "urllib.request"), MovedAttribute("FancyURLopener", "urllib", "urllib.request"), + MovedAttribute("proxy_bypass", "urllib", "urllib.request"), ] for attr in _urllib_request_moved_attributes: setattr(Module_six_moves_urllib_request, attr.name, attr) -- cgit v1.2.1