diff options
author | Marc Abramowitz <marc@marc-abramowitz.com> | 2013-12-08 21:27:01 -0800 |
---|---|---|
committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2013-12-08 21:27:01 -0800 |
commit | 18c431dbc11eaa83a78ea15dac848fd970d9222c (patch) | |
tree | ea267d4d3467d6d4964f6a453109a76dc0bb9362 | |
parent | c97fb65a16dca879b9d215cb6ed1ffdc93c8ef20 (diff) | |
parent | b92f218239ea695f23bebe6659c150b166dfc281 (diff) | |
download | six-18c431dbc11eaa83a78ea15dac848fd970d9222c.tar.gz |
Merge from tip to issue_19
-rw-r--r-- | CHANGES | 15 | ||||
-rw-r--r-- | documentation/conf.py | 4 | ||||
-rw-r--r-- | documentation/index.rst | 17 | ||||
-rw-r--r-- | six.py | 23 | ||||
-rw-r--r-- | test_six.py | 18 |
5 files changed, 63 insertions, 14 deletions
@@ -3,6 +3,21 @@ Changelog for Six This file lists the changes in each six version. +Development version +------------------- + +- Pull request #21: Add import mapping for urllib's proxy_bypass function. + +- Issue #43: Add import mapping for the Python 2 xmlrpclib module. + +- Issue #39: Add import mapping for the Python 2 thread module. + +- Issue #40: Add import mapping for the Python 2 gdbm module. + +- Issue #35: On Python versions less than 2.7, print_ now encodes unicode + strings when outputing to standard streams. (Python 2.7 handles this + automatically.) + 1.4.1 ----- diff --git a/documentation/conf.py b/documentation/conf.py index 7872444..e5c160a 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -213,5 +213,5 @@ man_pages = [ # -- Intersphinx --------------------------------------------------------------- -intersphinx_mapping = {"py2" : ("http://docs.python.org/", None), - "py3" : ("http://docs.python.org/py3k/", None)} +intersphinx_mapping = {"py2" : ("http://docs.python.org/2/", None), + "py3" : ("http://docs.python.org/3/", None)} diff --git a/documentation/index.rst b/documentation/index.rst index 9f879c1..394fb9c 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -17,8 +17,8 @@ Six can be downloaded on `PyPi <http://pypi.python.org/pypi/six/>`_. Its bug tracker and code hosting is on `BitBucket <http://bitbucket.org/gutworth/six>`_. The name, "six", comes from the fact that 2*3 equals 6. Why not addition? -Multiplication is more powerful, and, anyway, "five" has already been `snatched -away <http://codespeak.net/z3/five/>`_. +Multiplication is more powerful, and, anyway, "five" has already been snatched +away by the Zope Five project. Indices and tables @@ -243,10 +243,10 @@ Python 2 and 3. :func:`exec` with them should be avoided. -.. function:: print_(*args, *, file=sys.stdout, end="\n", sep=" ") +.. function:: print_(*args, *, file=sys.stdout, end="\\n", sep=" ") Print *args* into *file*. Each argument will be separated with *sep* and - *end* will be written to the file at the last. + *end* will be written to the file after the last argument is printed. .. note:: @@ -454,6 +454,8 @@ Supported renames: +------------------------------+-------------------------------------+-------------------------------------+ | ``cStringIO`` | :func:`py2:cStringIO.StringIO` | :class:`py3:io.StringIO` | +------------------------------+-------------------------------------+-------------------------------------+ +| ``dbm_gnu`` | :func:`py2:gdbm` | :class:`py3:dbm.gnu` | ++------------------------------+-------------------------------------+-------------------------------------+ | ``email_mime_multipart`` | :mod:`py2:email.MIMEMultipart` | :mod:`py3:email.mime.multipart` | +------------------------------+-------------------------------------+-------------------------------------+ | ``email_mime_text`` | :mod:`py2:email.MIMEText` | :mod:`py3:email.mime.text` | @@ -496,13 +498,15 @@ Supported renames: +------------------------------+-------------------------------------+-------------------------------------+ | ``socketserver`` | :mod:`py2:SocketServer` | :mod:`py3:socketserver` | +------------------------------+-------------------------------------+-------------------------------------+ +| ``_thread`` | :mod:`py2:thread` | :mod:`py3:_thread` | ++------------------------------+-------------------------------------+-------------------------------------+ | ``tkinter`` | :mod:`py2:Tkinter` | :mod:`py3:tkinter` | +------------------------------+-------------------------------------+-------------------------------------+ | ``tkinter_dialog`` | :mod:`py2:Dialog` | :mod:`py3:tkinter.dialog` | +------------------------------+-------------------------------------+-------------------------------------+ | ``tkinter_filedialog`` | :mod:`py2:FileDialog` | :mod:`py3:tkinter.FileDialog` | +------------------------------+-------------------------------------+-------------------------------------+ -| ``tkinter_scrolledtext`` | :mod:`py2:ScrolledText` | :mod:`py3:tkinter.scolledtext` | +| ``tkinter_scrolledtext`` | :mod:`py2:ScrolledText` | :mod:`py3:tkinter.scrolledtext` | +------------------------------+-------------------------------------+-------------------------------------+ | ``tkinter_simpledialog`` | :mod:`py2:SimpleDialog` | :mod:`py2:tkinter.simpledialog` | +------------------------------+-------------------------------------+-------------------------------------+ @@ -540,6 +544,8 @@ Supported renames: +------------------------------+-------------------------------------+-------------------------------------+ | ``winreg`` | :mod:`py2:_winreg` | :mod:`py3:winreg` | +------------------------------+-------------------------------------+-------------------------------------+ +| ``xmlrpc_client`` | :mod:`py2:xmlrpclib` | :mod:`py3:xmlrpclib` | ++------------------------------+-------------------------------------+-------------------------------------+ | ``xrange`` | :func:`py2:xrange` | :func:`py3:range` | +------------------------------+-------------------------------------+-------------------------------------+ | ``zip`` | :func:`py2:itertools.izip` | :func:`py3:zip` | @@ -611,6 +617,7 @@ Contains items from Python 3's :mod:`py3:urllib.request` and Python 2's: * :func:`py2:urllib.urlcleanup` * :class:`py2:urllib.URLopener` * :class:`py2:urllib.FancyURLopener` +* :func:`py2:urllib.proxy_bypass` and :mod:`py2:urllib2`: @@ -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"), @@ -168,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"), @@ -189,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: @@ -283,6 +286,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) @@ -483,8 +487,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): @@ -492,10 +495,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.""" @@ -515,14 +514,24 @@ 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. + if (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) diff --git a/test_six.py b/test_six.py index b2ffe84..b4d1d0e 100644 --- a/test_six.py +++ b/test_six.py @@ -530,6 +530,24 @@ def test_print_(): assert out.getvalue() == "None\n" +@py.test.mark.skipif("sys.version_info[:2] >= (2, 6)") +def test_print_encoding(monkeypatch): + # Fool the type checking in print_. + monkeypatch.setattr(six, "file", six.BytesIO, raising=False) + out = six.BytesIO() + out.encoding = "utf-8" + out.errors = None + six.print_(six.u("\u053c"), end="", file=out) + assert out.getvalue() == six.b("\xd4\xbc") + out = six.BytesIO() + out.encoding = "ascii" + out.errors = "strict" + py.test.raises(UnicodeEncodeError, six.print_, six.u("\u053c"), file=out) + out.errors = "backslashreplace" + six.print_(six.u("\u053c"), end="", file=out) + assert out.getvalue() == six.b("\\u053c") + + def test_print_exceptions(): py.test.raises(TypeError, six.print_, x=3) py.test.raises(TypeError, six.print_, end=3) |