mirror of https://github.com/python/cpython
merge
This commit is contained in:
commit
e65753e09e
|
@ -39,7 +39,7 @@ code, it does mean you keep a rapid development process for you, the developer.
|
||||||
Finally, you do have the option of :ref:`using 2to3 <use_2to3>` to translate
|
Finally, you do have the option of :ref:`using 2to3 <use_2to3>` to translate
|
||||||
Python 2 code into Python 3 code (with some manual help). This can take the
|
Python 2 code into Python 3 code (with some manual help). This can take the
|
||||||
form of branching your code and using 2to3 to start a Python 3 branch. You can
|
form of branching your code and using 2to3 to start a Python 3 branch. You can
|
||||||
also have users perform the translation as installation time automatically so
|
also have users perform the translation at installation time automatically so
|
||||||
that you only have to maintain a Python 2 codebase.
|
that you only have to maintain a Python 2 codebase.
|
||||||
|
|
||||||
Regardless of which approach you choose, porting is not as hard or
|
Regardless of which approach you choose, porting is not as hard or
|
||||||
|
@ -234,7 +234,7 @@ You can avoid this disparity by always slicing at the size of a single element:
|
||||||
``b'py'[1:2]`` is ``'y'`` in Python 2 and ``b'y'`` in Python 3 (i.e., close
|
``b'py'[1:2]`` is ``'y'`` in Python 2 and ``b'y'`` in Python 3 (i.e., close
|
||||||
enough).
|
enough).
|
||||||
|
|
||||||
You cannot concatenate bytes and strings in Python 3. But since in Python
|
You cannot concatenate bytes and strings in Python 3. But since Python
|
||||||
2 has bytes aliased to ``str``, it will succeed: ``b'a' + u'b'`` works in
|
2 has bytes aliased to ``str``, it will succeed: ``b'a' + u'b'`` works in
|
||||||
Python 2, but ``b'a' + 'b'`` in Python 3 is a :exc:`TypeError`. A similar issue
|
Python 2, but ``b'a' + 'b'`` in Python 3 is a :exc:`TypeError`. A similar issue
|
||||||
also comes about when doing comparisons between bytes and strings.
|
also comes about when doing comparisons between bytes and strings.
|
||||||
|
@ -328,7 +328,7 @@ the bytes/string dichotomy. Because Python 2 allowed the ``str`` type to hold
|
||||||
textual data, people have over the years been rather loose in their delineation
|
textual data, people have over the years been rather loose in their delineation
|
||||||
of what ``str`` instances held text compared to bytes. In Python 3 you cannot
|
of what ``str`` instances held text compared to bytes. In Python 3 you cannot
|
||||||
be so care-free anymore and need to properly handle the difference. The key
|
be so care-free anymore and need to properly handle the difference. The key
|
||||||
handling this issue to make sure that **every** string literal in your
|
handling this issue is to make sure that **every** string literal in your
|
||||||
Python 2 code is either syntactically of functionally marked as either bytes or
|
Python 2 code is either syntactically of functionally marked as either bytes or
|
||||||
text data. After this is done you then need to make sure your APIs are designed
|
text data. After this is done you then need to make sure your APIs are designed
|
||||||
to either handle a specific type or made to be properly polymorphic.
|
to either handle a specific type or made to be properly polymorphic.
|
||||||
|
@ -343,7 +343,7 @@ newer, this can be accomplished by marking bytes literals with a ``b`` prefix
|
||||||
and then designating textual data with a ``u`` prefix or using the
|
and then designating textual data with a ``u`` prefix or using the
|
||||||
``unicode_literals`` future statement.
|
``unicode_literals`` future statement.
|
||||||
|
|
||||||
If your project supports versions of Python pre-dating 2.6, then you should use
|
If your project supports versions of Python predating 2.6, then you should use
|
||||||
the six_ project and its ``b()`` function to denote bytes literals. For text
|
the six_ project and its ``b()`` function to denote bytes literals. For text
|
||||||
literals you can either use six's ``u()`` function or use a ``u`` prefix.
|
literals you can either use six's ``u()`` function or use a ``u`` prefix.
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ happen to use the ``unicode(self).encode('utf8')`` idiom as the body of your
|
||||||
There are two ways to solve this issue. One is to use a custom 2to3 fixer. The
|
There are two ways to solve this issue. One is to use a custom 2to3 fixer. The
|
||||||
blog post at http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/
|
blog post at http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/
|
||||||
specifies how to do this. That will allow 2to3 to change all instances of ``def
|
specifies how to do this. That will allow 2to3 to change all instances of ``def
|
||||||
__unicode(self): ...`` to ``def __str__(self): ...``. This does require you
|
__unicode(self): ...`` to ``def __str__(self): ...``. This does require that you
|
||||||
define your ``__str__()`` method in Python 2 before your ``__unicode__()``
|
define your ``__str__()`` method in Python 2 before your ``__unicode__()``
|
||||||
method.
|
method.
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ I'm not going to talk about it here, except to warn you that you need to use
|
||||||
there, you may wait forever for the reply, because the request may still be in
|
there, you may wait forever for the reply, because the request may still be in
|
||||||
your output buffer.
|
your output buffer.
|
||||||
|
|
||||||
Now we come the major stumbling block of sockets - ``send`` and ``recv`` operate
|
Now we come to the major stumbling block of sockets - ``send`` and ``recv`` operate
|
||||||
on the network buffers. They do not necessarily handle all the bytes you hand
|
on the network buffers. They do not necessarily handle all the bytes you hand
|
||||||
them (or expect from them), because their major focus is handling the network
|
them (or expect from them), because their major focus is handling the network
|
||||||
buffers. In general, they return when the associated network buffers have been
|
buffers. In general, they return when the associated network buffers have been
|
||||||
|
@ -167,7 +167,7 @@ been completely dealt with.
|
||||||
When a ``recv`` returns 0 bytes, it means the other side has closed (or is in
|
When a ``recv`` returns 0 bytes, it means the other side has closed (or is in
|
||||||
the process of closing) the connection. You will not receive any more data on
|
the process of closing) the connection. You will not receive any more data on
|
||||||
this connection. Ever. You may be able to send data successfully; I'll talk
|
this connection. Ever. You may be able to send data successfully; I'll talk
|
||||||
about that some on the next page.
|
more about this later.
|
||||||
|
|
||||||
A protocol like HTTP uses a socket for only one transfer. The client sends a
|
A protocol like HTTP uses a socket for only one transfer. The client sends a
|
||||||
request, then reads a reply. That's it. The socket is discarded. This means that
|
request, then reads a reply. That's it. The socket is discarded. This means that
|
||||||
|
|
|
@ -748,7 +748,11 @@ class HTTPConnection:
|
||||||
line = response.fp.readline(_MAXLINE + 1)
|
line = response.fp.readline(_MAXLINE + 1)
|
||||||
if len(line) > _MAXLINE:
|
if len(line) > _MAXLINE:
|
||||||
raise LineTooLong("header line")
|
raise LineTooLong("header line")
|
||||||
if line == '\r\n': break
|
if not line:
|
||||||
|
# for sites which EOF without sending trailer
|
||||||
|
break
|
||||||
|
if line == '\r\n':
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
|
@ -1498,7 +1498,8 @@ def resolve(thing, forceload=0):
|
||||||
raise ImportError, 'no Python documentation found for %r' % thing
|
raise ImportError, 'no Python documentation found for %r' % thing
|
||||||
return object, thing
|
return object, thing
|
||||||
else:
|
else:
|
||||||
return thing, getattr(thing, '__name__', None)
|
name = getattr(thing, '__name__', None)
|
||||||
|
return thing, name if isinstance(name, str) else None
|
||||||
|
|
||||||
def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
|
def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
|
||||||
"""Render text documentation, given an object or a path to an object."""
|
"""Render text documentation, given an object or a path to an object."""
|
||||||
|
|
|
@ -249,6 +249,17 @@ class PyDocDocTest(unittest.TestCase):
|
||||||
result, doc_loc = get_pydoc_text(xml.etree)
|
result, doc_loc = get_pydoc_text(xml.etree)
|
||||||
self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
|
self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
|
||||||
|
|
||||||
|
def test_non_str_name(self):
|
||||||
|
# issue14638
|
||||||
|
# Treat illegal (non-str) name like no name
|
||||||
|
class A:
|
||||||
|
__name__ = 42
|
||||||
|
class B:
|
||||||
|
pass
|
||||||
|
adoc = pydoc.render_doc(A())
|
||||||
|
bdoc = pydoc.render_doc(B())
|
||||||
|
self.assertEqual(adoc.replace("A", "B"), bdoc)
|
||||||
|
|
||||||
def test_not_here(self):
|
def test_not_here(self):
|
||||||
missing_module = "test.i_am_not_here"
|
missing_module = "test.i_am_not_here"
|
||||||
result = run_pydoc(missing_module)
|
result = run_pydoc(missing_module)
|
||||||
|
|
|
@ -150,7 +150,7 @@ class ThreadRunningTests(BasicThreadTest):
|
||||||
thread.start_new_thread(task, ())
|
thread.start_new_thread(task, ())
|
||||||
started.acquire()
|
started.acquire()
|
||||||
while thread._count() > c:
|
while thread._count() > c:
|
||||||
pass
|
time.sleep(0.01)
|
||||||
self.assertIn("Traceback", stderr.getvalue())
|
self.assertIn("Traceback", stderr.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -774,6 +774,7 @@ Jerry Seutter
|
||||||
Denis Severson
|
Denis Severson
|
||||||
Ian Seyer
|
Ian Seyer
|
||||||
Ha Shao
|
Ha Shao
|
||||||
|
Mark Shannon
|
||||||
Richard Shapiro
|
Richard Shapiro
|
||||||
Bruce Sherwood
|
Bruce Sherwood
|
||||||
Alexander Shigin
|
Alexander Shigin
|
||||||
|
|
|
@ -50,6 +50,12 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #14638: pydoc now treats non-string __name__ values as if they
|
||||||
|
were missing, instead of raising an error.
|
||||||
|
|
||||||
|
- Issue #13684: Fix httplib tunnel issue of infinite loops for certain sites
|
||||||
|
which send EOF without trailing \r\n.
|
||||||
|
|
||||||
- Issue #14308: Fix an exception when a "dummy" thread is in the threading
|
- Issue #14308: Fix an exception when a "dummy" thread is in the threading
|
||||||
module's active list after a fork().
|
module's active list after a fork().
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue