Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aliases for some functions/modules renamed in Python 3. #128

Merged
merged 10 commits into from
May 3, 2020
3 changes: 2 additions & 1 deletion Doc/library/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import itertools
__name__ = '<doctest>'

**Source code:** :source:`Lib/collections.py` and :source:`Lib/_abcoll.py`
**Source code:** :source:`Lib/collections/__init__.py` and
:source:`Lib/_abcoll.py`

--------------

Expand Down
3 changes: 1 addition & 2 deletions Lib/_abcoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ def __contains__(self, key):
return key in self._mapping

def __iter__(self):
for key in self._mapping:
yield key
yield from self._mapping

KeysView.register(type({}.viewkeys()))

Expand Down
5 changes: 3 additions & 2 deletions Lib/collections.py → Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
'''

__all__ = ['Counter', 'deque', 'defaultdict', 'namedtuple', 'OrderedDict']
# For bootstrapping reasons, the collection ABCs are defined in _abcoll.py.
# They should however be considered an integral part of collections.py.

# For backwards compatibility, continue to make the collections ABCs
# available through the collections module.
from _abcoll import *
import _abcoll
__all__ += _abcoll.__all__
Expand Down
2 changes: 2 additions & 0 deletions Lib/collections/abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from _abcoll import *
from _abcoll import __all__
2 changes: 2 additions & 0 deletions Lib/copyreg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from copy_reg import *
from copy_reg import __all__, __doc__
Empty file added Lib/http/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from httplib import (__doc__, HTTPResponse, HTTPConnection, HTTPException,
NotConnected, UnknownProtocol, UnknownTransferEncoding,
UnimplementedFileMode, IncompleteRead, InvalidURL,
ImproperConnectionState, CannotSendRequest,
CannotSendHeader, ResponseNotReady, BadStatusLine,
LineTooLong, error, responses)

__all__ = ["HTTPResponse", "HTTPConnection",
"HTTPException", "NotConnected", "UnknownProtocol",
"UnknownTransferEncoding", "UnimplementedFileMode",
"IncompleteRead", "InvalidURL", "ImproperConnectionState",
"CannotSendRequest", "CannotSendHeader", "ResponseNotReady",
"BadStatusLine", "LineTooLong", "error", "responses"]
5 changes: 5 additions & 0 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cookielib import *
from cookielib import __doc__

__all__ = ['Cookie', 'CookieJar', 'CookiePolicy', 'DefaultCookiePolicy',
'FileCookieJar', 'LWPCookieJar', 'LoadError', 'MozillaCookieJar']
93 changes: 93 additions & 0 deletions Lib/http/cookies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
r"""
Here's a sample session to show how to use this module.
At the moment, this is the only documentation.

The Basics
----------

Importing is easy...

>>> from http import cookies

Most of the time you start by creating a cookie.

>>> C = cookies.SimpleCookie()

Once you've created your Cookie, you can add values just as if it were
a dictionary.

>>> C = cookies.SimpleCookie()
>>> C["fig"] = "newton"
>>> C["sugar"] = "wafer"
>>> C.output()
'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'

Notice that the printable representation of a Cookie is the
appropriate format for a Set-Cookie: header. This is the
default behavior. You can change the header and printed
attributes by using the .output() function

>>> C = cookies.SimpleCookie()
>>> C["rocky"] = "road"
>>> C["rocky"]["path"] = "/cookie"
>>> print(C.output(header="Cookie:"))
Cookie: rocky=road; Path=/cookie
>>> print(C.output(attrs=[], header="Cookie:"))
Cookie: rocky=road

The load() method of a Cookie extracts cookies from a string. In a
CGI script, you would use this method to extract the cookies from the
HTTP_COOKIE environment variable.

>>> C = cookies.SimpleCookie()
>>> C.load("chips=ahoy; vienna=finger")
>>> C.output()
'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'

The load() method is darn-tootin smart about identifying cookies
within a string. Escaped quotation marks, nested semicolons, and other
such trickeries do not confuse it.

>>> C = cookies.SimpleCookie()
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
>>> print(C)
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"

Each element of the Cookie also supports all of the RFC 2109
Cookie attributes. Here's an example which sets the Path
attribute.

>>> C = cookies.SimpleCookie()
>>> C["oreo"] = "doublestuff"
>>> C["oreo"]["path"] = "/"
>>> print(C)
Set-Cookie: oreo=doublestuff; Path=/

Each dictionary element has a 'value' attribute, which gives you
back the value associated with the key.

>>> C = cookies.SimpleCookie()
>>> C["twix"] = "none for you"
>>> C["twix"].value
'none for you'

The SimpleCookie expects that all values should be standard strings.
Just to be sure, SimpleCookie invokes the str() builtin to convert
the value to a string, when the values are set dictionary-style.

>>> C = cookies.SimpleCookie()
>>> C["number"] = 7
>>> C["string"] = "seven"
>>> C["number"].value
'7'
>>> C["string"].value
'seven'
>>> C.output()
'Set-Cookie: number=7\r\nSet-Cookie: string=seven'

Finis.
"""

from Cookie import CookieError, BaseCookie, Morsel, SimpleCookie

__all__ = ['CookieError', 'BaseCookie', 'SimpleCookie']
9 changes: 9 additions & 0 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__all__ = ['HTTPServer', 'BaseHTTPRequestHandler', 'SimpleHTTPRequestHandler',
'CGIHTTPRequestHandler']

from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from CGIHTTPServer import CGIHTTPRequestHandler, executable, nobody_uid
from SimpleHTTPServer import SimpleHTTPRequestHandler, test

if __name__ == '__main__':
test()
2 changes: 2 additions & 0 deletions Lib/importlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ def import_module(name, package=None):
name = _resolve_name(name[level:], package, level)
__import__(name)
return sys.modules[name]

reload = reload
stefantalpalaru marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ def test_izip_tuple_reuse(self):
ids = map(id, list(izip('abc', 'def')))
self.assertEqual(len(dict.fromkeys(ids)), len(ids))

def test_aliases(self):
self.assertEqual(izip_longest, zip_longest)
self.assertEqual(ifilterfalse, filterfalse)

def test_iziplongest(self):
for args in [
['abc', range(6)],
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def ismethod(oclass, obj, name):
continue
self.assertHasattr(module, name, ignore)
py_item = getattr(module, name)
if isinstance(value, pyclbr.Function):
if name == '__path__':
self.assertIsInstance(py_item, list)
self.assertEqual(py_item, value)
elif isinstance(value, pyclbr.Function):
self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
if py_item.__module__ != moduleName:
continue # skip functions that came from somewhere else
Expand Down
Loading