From 09a52ed47bb26498c97a579ce1147861df696d84 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Thu, 28 Mar 2013 17:13:53 -0600 Subject: 2to3: Apply `imports` fixer. The `imports` fixer deals with the standard packages that have been renamed, removed, or methods that have moved. cPickle -- removed, use pickle commands -- removed, getoutput, getstatusoutput moved to subprocess urlparse -- removed, urlparse moved to urllib.parse cStringIO -- removed, use StringIO or io.StringIO copy_reg -- renamed copyreg _winreg -- renamed winreg ConfigParser -- renamed configparser __builtin__ -- renamed builtins In the case of `cPickle`, it is imported as `pickle` when python < 3 and performance may be a consideration, but otherwise plain old `pickle` is used. Dealing with `StringIO` is a bit tricky. There is an `io.StringIO` function in the `io` module, available since Python 2.6, but it expects unicode whereas `StringIO.StringIO` expects ascii. The Python 3 equivalent is then `io.BytesIO`. What I have done here is used BytesIO for anything that is emulating a file for testing purposes. That is more explicit than using a redefined StringIO as was done before we dropped support for Python 2.4 and 2.5. Closes #3180. --- doc/cdoc/numpyfilter.py | 6 +++++- doc/numpybook/runcode.py | 6 +++--- doc/sphinxext/numpydoc/comment_eater.py | 2 +- doc/sphinxext/numpydoc/compiler_unparse.py | 2 +- doc/sphinxext/numpydoc/docscrape.py | 2 +- doc/sphinxext/numpydoc/plot_directive.py | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) (limited to 'doc') diff --git a/doc/cdoc/numpyfilter.py b/doc/cdoc/numpyfilter.py index 60bee1b51..7137df2d2 100755 --- a/doc/cdoc/numpyfilter.py +++ b/doc/cdoc/numpyfilter.py @@ -13,7 +13,11 @@ import re import os import textwrap import optparse -import cPickle as pickle + +if sys.version_info[0] >= 3: + import pickle +else: + import cPickle as pickle. CACHE_FILE = 'build/rst-cache.pck' diff --git a/doc/numpybook/runcode.py b/doc/numpybook/runcode.py index 66c74cd74..858168e11 100644 --- a/doc/numpybook/runcode.py +++ b/doc/numpybook/runcode.py @@ -18,7 +18,7 @@ from __future__ import division, absolute_import import sys import optparse -import cStringIO +import io import re import os @@ -27,7 +27,7 @@ newre = re.compile(r"\\begin_inset Note.*PYNEW\s+\\end_inset", re.DOTALL) def getoutput(tstr, dic): print "\n\nRunning..." print tstr, - tempstr = cStringIO.StringIO() + tempstr = io.StringIO() sys.stdout = tempstr code = compile(tstr, '', 'exec') try: @@ -82,7 +82,7 @@ def getnewcodestr(substr, dic): def runpycode(lyxstr, name='MyCode'): schobj = re.compile(r"\\layout %s\s+>>> " % name) - outstr = cStringIO.StringIO() + outstr = io.StringIO() num = 0 indx = [] for it in schobj.finditer(lyxstr): diff --git a/doc/sphinxext/numpydoc/comment_eater.py b/doc/sphinxext/numpydoc/comment_eater.py index 74d0d4768..2c7f4da31 100644 --- a/doc/sphinxext/numpydoc/comment_eater.py +++ b/doc/sphinxext/numpydoc/comment_eater.py @@ -4,7 +4,7 @@ import sys if sys.version_info[0] >= 3: from io import StringIO else: - from cStringIO import StringIO + from io import StringIO import compiler import inspect diff --git a/doc/sphinxext/numpydoc/compiler_unparse.py b/doc/sphinxext/numpydoc/compiler_unparse.py index bb76f7ea3..c36389d13 100644 --- a/doc/sphinxext/numpydoc/compiler_unparse.py +++ b/doc/sphinxext/numpydoc/compiler_unparse.py @@ -18,7 +18,7 @@ from compiler.ast import Const, Name, Tuple, Div, Mul, Sub, Add if sys.version_info[0] >= 3: from io import StringIO else: - from cStringIO import StringIO + from io import StringIO def unparse(ast, single_line_functions=False): s = StringIO() diff --git a/doc/sphinxext/numpydoc/docscrape.py b/doc/sphinxext/numpydoc/docscrape.py index af76b86e5..59d3f9734 100644 --- a/doc/sphinxext/numpydoc/docscrape.py +++ b/doc/sphinxext/numpydoc/docscrape.py @@ -14,7 +14,7 @@ import collections if sys.version_info[0] >= 3: from io import StringIO else: - from cStringIO import StringIO + from io import StringIO class Reader(object): """A line-based string reader. diff --git a/doc/sphinxext/numpydoc/plot_directive.py b/doc/sphinxext/numpydoc/plot_directive.py index 9e92acabb..a7f4655ce 100644 --- a/doc/sphinxext/numpydoc/plot_directive.py +++ b/doc/sphinxext/numpydoc/plot_directive.py @@ -82,7 +82,7 @@ import sphinx if sys.version_info[0] >= 3: from io import StringIO else: - from cStringIO import StringIO + from io import StringIO import warnings warnings.warn("A plot_directive module is also available under " -- cgit v1.2.1 From 4394515cd5632a7f110993ff75033d407d10861d Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Tue, 2 Apr 2013 13:47:32 -0600 Subject: BUG: Fix stray '.' in import statement. There was a stray period at the end of an import statement in `doc/cdoc/numpyfilter.py`. Looks like a cut and paste error that was fixed elsewhere but escaped there because the module isn't tested. A search shows that this was the only spot in which the error was still present. --- doc/cdoc/numpyfilter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/cdoc/numpyfilter.py b/doc/cdoc/numpyfilter.py index 7137df2d2..d5021f92a 100755 --- a/doc/cdoc/numpyfilter.py +++ b/doc/cdoc/numpyfilter.py @@ -17,7 +17,7 @@ import optparse if sys.version_info[0] >= 3: import pickle else: - import cPickle as pickle. + import cPickle as pickle CACHE_FILE = 'build/rst-cache.pck' @@ -47,7 +47,7 @@ def filter_comment(text): if text.startswith('UFUNC_API'): text = text[9:].strip() - html = render_html(text) + html = render_html(text) return html def process_match(m, cache=None): -- cgit v1.2.1