Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08a95ca

Browse files
committed
merge heads
2 parents 24bd5ad + feeb3a3 commit 08a95ca

25 files changed

Lines changed: 289 additions & 249 deletions

Doc/faq/extending.rst

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -447,34 +447,3 @@ In Python 2.2, you can inherit from built-in classes such as :class:`int`,
447447
The Boost Python Library (BPL, http://www.boost.org/libs/python/doc/index.html)
448448
provides a way of doing this from C++ (i.e. you can inherit from an extension
449449
class written in C++ using the BPL).
450-
451-
452-
When importing module X, why do I get "undefined symbol: PyUnicodeUCS2*"?
453-
-------------------------------------------------------------------------
454-
455-
You are using a version of Python that uses a 4-byte representation for Unicode
456-
characters, but some C extension module you are importing was compiled using a
457-
Python that uses a 2-byte representation for Unicode characters (the default).
458-
459-
If instead the name of the undefined symbol starts with ``PyUnicodeUCS4``, the
460-
problem is the reverse: Python was built using 2-byte Unicode characters, and
461-
the extension module was compiled using a Python with 4-byte Unicode characters.
462-
463-
This can easily occur when using pre-built extension packages. RedHat Linux
464-
7.x, in particular, provided a "python2" binary that is compiled with 4-byte
465-
Unicode. This only causes the link failure if the extension uses any of the
466-
``PyUnicode_*()`` functions. It is also a problem if an extension uses any of
467-
the Unicode-related format specifiers for :c:func:`Py_BuildValue` (or similar) or
468-
parameter specifications for :c:func:`PyArg_ParseTuple`.
469-
470-
You can check the size of the Unicode character a Python interpreter is using by
471-
checking the value of sys.maxunicode:
472-
473-
>>> import sys
474-
>>> if sys.maxunicode > 65535:
475-
... print('UCS4 build')
476-
... else:
477-
... print('UCS2 build')
478-
479-
The only way to solve this problem is to use extension modules compiled with a
480-
Python binary built using the same size for Unicode characters.

Doc/library/2to3.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ and off individually. They are described here in more detail.
123123
.. 2to3fixer:: callable
124124
125125
Converts ``callable(x)`` to ``isinstance(x, collections.Callable)``, adding
126-
an import to :mod:`collections` if needed.
126+
an import to :mod:`collections` if needed. Note ``callable(x)`` has returned
127+
in Python 3.2, so if you do not intend to support Python 3.1, you can disable
128+
this fixer.
127129
128130
.. 2to3fixer:: dict
129131

Doc/library/ftplib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ FTP_TLS Objects
427427

428428
.. method:: FTP_TLS.ccc()
429429

430-
Revert control channel back to plaintex. This can be useful to take
430+
Revert control channel back to plaintext. This can be useful to take
431431
advantage of firewalls that know how to handle NAT with non-secure FTP
432432
without opening fixed ports.
433433

Doc/library/signal.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ The :mod:`signal` module defines the following functions:
353353
signals in *sigset* is already pending for the calling thread, the function
354354
will return immediately with information about that signal. The signal
355355
handler is not called for the delivered signal. The function raises an
356-
:exc:`OSError` with error number set to :const:`errno.EINTR` if it is
357-
interrupted by a signal that is not in *sigset*.
356+
:exc:`InterruptedError` if it is interrupted by a signal that is not in
357+
*sigset*.
358358

359359
The return value is an object representing the data contained in the
360360
:c:type:`siginfo_t` structure, namely: :attr:`si_signo`, :attr:`si_code`,

Doc/library/socketserver.rst

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ This is the server side::
361361
def handle(self):
362362
# self.request is the TCP socket connected to the client
363363
self.data = self.request.recv(1024).strip()
364-
print("%s wrote:" % self.client_address[0])
364+
print("{} wrote:".format(self.client_address[0]))
365365
print(self.data)
366366
# just send back the same data, but upper-cased
367367
self.request.send(self.data.upper())
@@ -385,7 +385,7 @@ objects that simplify communication by providing the standard file interface)::
385385
# self.rfile is a file-like object created by the handler;
386386
# we can now use e.g. readline() instead of raw recv() calls
387387
self.data = self.rfile.readline().strip()
388-
print("%s wrote:" % self.client_address[0])
388+
print("{} wrote:".format(self.client_address[0]))
389389
print(self.data)
390390
# Likewise, self.wfile is a file-like object used to write back
391391
# to the client
@@ -408,16 +408,18 @@ This is the client side::
408408
# Create a socket (SOCK_STREAM means a TCP socket)
409409
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
410410

411-
# Connect to server and send data
412-
sock.connect((HOST, PORT))
413-
sock.send(bytes(data + "\n","utf8"))
411+
try:
412+
# Connect to server and send data
413+
sock.connect((HOST, PORT))
414+
sock.send(bytes(data + "\n", "utf-8"))
414415

415-
# Receive data from the server and shut down
416-
received = sock.recv(1024)
417-
sock.close()
416+
# Receive data from the server and shut down
417+
received = str(sock.recv(1024), "utf-8")
418+
finally:
419+
sock.close()
418420

419-
print("Sent: %s" % data)
420-
print("Received: %s" % received)
421+
print("Sent: {}".format(data))
422+
print("Received: {}".format(received))
421423

422424

423425
The output of the example should look something like this:
@@ -434,10 +436,10 @@ Client::
434436

435437
$ python TCPClient.py hello world with TCP
436438
Sent: hello world with TCP
437-
Received: b'HELLO WORLD WITH TCP'
439+
Received: HELLO WORLD WITH TCP
438440
$ python TCPClient.py python is nice
439441
Sent: python is nice
440-
Received: b'PYTHON IS NICE'
442+
Received: PYTHON IS NICE
441443

442444

443445
:class:`socketserver.UDPServer` Example
@@ -458,7 +460,7 @@ This is the server side::
458460
def handle(self):
459461
data = self.request[0].strip()
460462
socket = self.request[1]
461-
print("%s wrote:" % self.client_address[0])
463+
print("{} wrote:".format(self.client_address[0]))
462464
print(data)
463465
socket.sendto(data.upper(), self.client_address)
464466

@@ -480,11 +482,11 @@ This is the client side::
480482

481483
# As you can see, there is no connect() call; UDP has no connections.
482484
# Instead, data is directly sent to the recipient via sendto().
483-
sock.sendto(bytes(data + "\n","utf8"), (HOST, PORT))
484-
received = sock.recv(1024)
485+
sock.sendto(bytes(data + "\n", "utf-8"), (HOST, PORT))
486+
received = str(sock.recv(1024), "utf-8")
485487

486-
print("Sent: %s" % data)
487-
print("Received: %s" % received)
488+
print("Sent: {}".format(data))
489+
print("Received: {}".format(received))
488490

489491
The output of the example should look exactly like for the TCP server example.
490492

@@ -504,9 +506,9 @@ An example for the :class:`ThreadingMixIn` class::
504506
class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
505507

506508
def handle(self):
507-
data = self.request.recv(1024)
509+
data = str(self.request.recv(1024), 'ascii')
508510
cur_thread = threading.current_thread()
509-
response = bytes("%s: %s" % (cur_thread.getName(), data),'ascii')
511+
response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
510512
self.request.send(response)
511513

512514
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
@@ -515,10 +517,12 @@ An example for the :class:`ThreadingMixIn` class::
515517
def client(ip, port, message):
516518
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
517519
sock.connect((ip, port))
518-
sock.send(message)
519-
response = sock.recv(1024)
520-
print("Received: %s" % response)
521-
sock.close()
520+
try:
521+
sock.send(bytes(message, 'ascii'))
522+
response = str(sock.recv(1024), 'ascii')
523+
print("Received: {}".format(response))
524+
finally:
525+
sock.close()
522526

523527
if __name__ == "__main__":
524528
# Port 0 means to select an arbitrary unused port
@@ -531,13 +535,13 @@ An example for the :class:`ThreadingMixIn` class::
531535
# more thread for each request
532536
server_thread = threading.Thread(target=server.serve_forever)
533537
# Exit the server thread when the main thread terminates
534-
server_thread.setDaemon(True)
538+
server_thread.daemon = True
535539
server_thread.start()
536540
print("Server loop running in thread:", server_thread.name)
537541

538-
client(ip, port, b"Hello World 1")
539-
client(ip, port, b"Hello World 2")
540-
client(ip, port, b"Hello World 3")
542+
client(ip, port, "Hello World 1")
543+
client(ip, port, "Hello World 2")
544+
client(ip, port, "Hello World 3")
541545

542546
server.shutdown()
543547

@@ -546,9 +550,9 @@ The output of the example should look something like this::
546550

547551
$ python ThreadedTCPServer.py
548552
Server loop running in thread: Thread-1
549-
Received: b"Thread-2: b'Hello World 1'"
550-
Received: b"Thread-3: b'Hello World 2'"
551-
Received: b"Thread-4: b'Hello World 3'"
553+
Received: Thread-2: Hello World 1
554+
Received: Thread-3: Hello World 2
555+
Received: Thread-4: Hello World 3
552556

553557

554558
The :class:`ForkingMixIn` class is used in the same way, except that the server

0 commit comments

Comments
 (0)