Skip to content

Commit 1831996

Browse files
committed
Add a more complete set of future.moves stdlib interfaces (issue #104)
1 parent 132e6c5 commit 1831996

35 files changed

+552
-53
lines changed

docs/standard_library_imports.rst

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,71 @@ the standard Python 3 names and locations, it provides access to either the
88
corresponding native standard library modules (``future.moves``) or to backported
99
modules from Python 3.3 (``future.backports``).
1010

11+
.. _list-standard-library-moves:
12+
13+
List of moved standard library modules
14+
--------------------------------------
15+
16+
The complete list of modules available via one of the interfaces below is::
17+
18+
from collections import Counter, OrderedDict # backported to Py2.6
19+
from collections import UserList, UserDict
20+
21+
import configparser
22+
import copyreg
23+
24+
import dbm
25+
import dbm.dumb
26+
import dbm.gnu
27+
import dbm.ndbm
28+
29+
from itertools import filterfalse, zip_longest
30+
31+
import html
32+
import html.entities
33+
import html.parser
34+
35+
import http
36+
import http.client
37+
import http.cookies
38+
import http.cookiejar
39+
import http.server
40+
41+
import queue
42+
43+
import socketserver
44+
45+
from subprocess import check_output # backported to Py2.6
46+
from subprocess import getoutput, getstatusoutput
47+
48+
from sys import intern
49+
50+
import urllib.error
51+
import urllib.parse
52+
import urllib.request
53+
import urllib.response
54+
import urllib.robotparser
55+
56+
import winreg # Windows only
57+
58+
import xmlrpc.client
59+
import xmlrpc.server
60+
61+
import _dummy_thread
62+
import _markupbase
63+
import _thread
64+
65+
.. Disabled: import test.support
66+
67+
68+
69+
Interfaces
70+
----------
71+
1172
There are currently four interfaces to the reorganized standard library.
1273

1374
Context-manager interface
14-
-------------------------
75+
~~~~~~~~~~~~~~~~~~~~~~~~~
1576

1677
The recommended interface is via a context-manager called ``hooks``::
1778

@@ -29,7 +90,7 @@ The recommended interface is via a context-manager called ``hooks``::
2990
# and other moved modules and definitions
3091

3192
Direct interface
32-
----------------
93+
~~~~~~~~~~~~~~~~
3394

3495
The second interface avoids import hooks. It may therefore be more
3596
robust, at the cost of less idiomatic code. Use it as follows::
@@ -53,7 +114,7 @@ One workaround is to replace the dot with an underscore::
53114
import future.moves.http.client as http_client
54115

55116
``import_`` and ``from_import`` functions
56-
-----------------------------------------
117+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57118

58119
A third interface, which also works with two-level imports, is to use the
59120
``import_`` and ``from_import`` functions from ``future.standard_library`` as
@@ -67,7 +128,7 @@ follows::
67128
urlopen, urlsplit = from_import('urllib.request', 'urlopen', 'urlsplit')
68129

69130
install_hooks() call
70-
--------------------
131+
~~~~~~~~~~~~~~~~~~~~
71132

72133
The fourth interface to the reorganized standard library is via an
73134
explicit call to ``install_hooks()``::
@@ -114,39 +175,6 @@ modules on Py2::
114175
.. but it has the advantage that it can be used by automatic translation scripts such as ``futurize`` and ``pasteurize``.
115176
116177
117-
List of standard library modules
118-
--------------------------------
119-
120-
The complete list of modules available via one of the four interfaces above is::
121-
122-
import socketserver
123-
import queue
124-
import configparser
125-
from collections import UserList
126-
from collections import Counter, OrderedDict # backported to Py2.6
127-
from itertools import filterfalse, zip_longest
128-
129-
import html
130-
import html.entities
131-
import html.parser
132-
133-
import http
134-
import http.client
135-
import http.server
136-
import http.cookies
137-
import http.cookiejar
138-
139-
import urllib
140-
import urllib.parse
141-
import urllib.request
142-
import urllib.error
143-
144-
import xmlrpc.client
145-
import xmlrpc.server
146-
147-
.. Disabled: import test.support
148-
149-
150178
Comparing future.moves and six.moves
151179
------------------------------------
152180

docs/whatsnew.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
What's New
44
**********
55

6+
What's new in version 0.13.2
7+
============================
8+
9+
This release expands the ``future.moves`` package to include most of the remaining
10+
modules that were moved in the standard library reorganization (PEP 3108).
11+
(Issue #104). See :ref:`list-standard-library-moves` for an updated list.
12+
613
What's new in version 0.13.1
714
============================
815

future/moves/_dummy_thread.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import absolute_import
2+
from future.utils import PY3
3+
4+
if PY3:
5+
from _dummy_thread import *
6+
else:
7+
__future_module__ = True
8+
from dummy_thread import *

future/moves/_thread.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import absolute_import
2+
from future.utils import PY3
3+
4+
if PY3:
5+
from _thread import *
6+
else:
7+
__future_module__ = True
8+
from thread import *

future/moves/builtins.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from __future__ import absolute_import
2+
from future.utils import PY3
3+
4+
if PY3:
5+
from builtins import *
6+
else:
7+
__future_module__ = True
8+
from __builtin__ import *
9+
# Overwrite any old definitions with the equivalent future.builtins ones:
10+
from future.builtins import *

future/moves/collections.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from __future__ import absolute_import
2+
3+
from collections import *
4+
5+
from future.utils import PY2, PY26
6+
7+
if PY2:
8+
from UserList import UserList
9+
from UserDict import UserDict
10+
11+
if PY26:
12+
from future.backports.misc import OrderedDict, Counter

future/moves/configparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import absolute_import
2+
3+
from future.utils import PY2
4+
5+
if PY2:
6+
from ConfigParser import *
7+
else:
8+
from configparser import *

future/moves/copyreg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import absolute_import
2+
from future.utils import PY3
3+
4+
if PY3:
5+
from copyreg import *
6+
else:
7+
__future_module__ = True
8+
from copy_reg import *

future/moves/dbm/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import absolute_import
2+
from future.utils import PY3
3+
4+
if PY3:
5+
from dbm import *
6+
else:
7+
__future_module__ = True
8+
from whichdb import *
9+
from anydbm import *
10+
11+
# Py3.3's dbm/__init__.py imports ndbm but doesn't expose it via __all__.
12+
# In case some (badly written) code depends on dbm.ndbm after import dbm,
13+
# we simulate this:
14+
if PY3:
15+
from dbm import ndbm
16+
else:
17+
try:
18+
from future.moves.dbm import ndbm
19+
except ImportError:
20+
ndbm = None

future/moves/dbm/dumb.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import absolute_import
2+
3+
from future.utils import PY3
4+
5+
if PY3:
6+
from dbm.dumb import *
7+
else:
8+
__future_module__ = True
9+
from dumbdbm import *

0 commit comments

Comments
 (0)