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

Skip to content

Commit 873cab2

Browse files
committed
merge heads.
2 parents 12c9d02 + 95e6866 commit 873cab2

25 files changed

Lines changed: 425 additions & 306 deletions

Doc/howto/sockets.rst

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ web server it's talking to uses both "server" sockets and "client" sockets.
4343
History
4444
-------
4545

46-
Of the various forms of IPC (*Inter Process Communication*), sockets are by far
47-
the most popular. On any given platform, there are likely to be other forms of
48-
IPC that are faster, but for cross-platform communication, sockets are about the
49-
only game in town.
46+
Of the various forms of :abbr:`IPC (Inter Process Communication)`,
47+
sockets are by far the most popular. On any given platform, there are
48+
likely to be other forms of IPC that are faster, but for
49+
cross-platform communication, sockets are about the only game in town.
5050

5151
They were invented in Berkeley as part of the BSD flavor of Unix. They spread
5252
like wildfire with the Internet. With good reason --- the combination of sockets
@@ -66,13 +66,14 @@ your browser did something like the following::
6666
# - the normal http port
6767
s.connect(("www.mcmillan-inc.com", 80))
6868

69-
When the ``connect`` completes, the socket ``s`` can now be used to send in a
70-
request for the text of this page. The same socket will read the reply, and then
71-
be destroyed. That's right - destroyed. Client sockets are normally only used
72-
for one exchange (or a small set of sequential exchanges).
69+
When the ``connect`` completes, the socket ``s`` can be used to send
70+
in a request for the text of the page. The same socket will read the
71+
reply, and then be destroyed. That's right, destroyed. Client sockets
72+
are normally only used for one exchange (or a small set of sequential
73+
exchanges).
7374

7475
What happens in the web server is a bit more complex. First, the web server
75-
creates a "server socket". ::
76+
creates a "server socket"::
7677

7778
#create an INET, STREAMing socket
7879
serversocket = socket.socket(
@@ -96,7 +97,7 @@ Finally, the argument to ``listen`` tells the socket library that we want it to
9697
queue up as many as 5 connect requests (the normal max) before refusing outside
9798
connections. If the rest of the code is written properly, that should be plenty.
9899

99-
OK, now we have a "server" socket, listening on port 80. Now we enter the
100+
Now that we have a "server" socket, listening on port 80, we can enter the
100101
mainloop of the web server::
101102

102103
while True:
@@ -145,7 +146,7 @@ perhaps a signon. But that's a design decision - it's not a rule of sockets.
145146

146147
Now there are two sets of verbs to use for communication. You can use ``send``
147148
and ``recv``, or you can transform your client socket into a file-like beast and
148-
use ``read`` and ``write``. The latter is the way Java presents their sockets.
149+
use ``read`` and ``write``. The latter is the way Java presents its sockets.
149150
I'm not going to talk about it here, except to warn you that you need to use
150151
``flush`` on sockets. These are buffered "files", and a common mistake is to
151152
``write`` something, and then ``read`` for a reply. Without a ``flush`` in
@@ -166,11 +167,11 @@ this connection. Ever. You may be able to send data successfully; I'll talk
166167
about that some on the next page.
167168

168169
A protocol like HTTP uses a socket for only one transfer. The client sends a
169-
request, the reads a reply. That's it. The socket is discarded. This means that
170+
request, then reads a reply. That's it. The socket is discarded. This means that
170171
a client can detect the end of the reply by receiving 0 bytes.
171172

172173
But if you plan to reuse your socket for further transfers, you need to realize
173-
that *there is no "EOT" (End of Transfer) on a socket.* I repeat: if a socket
174+
that *there is no* :abbr:`EOT (End of Transfer)` *on a socket.* I repeat: if a socket
174175
``send`` or ``recv`` returns after handling 0 bytes, the connection has been
175176
broken. If the connection has *not* been broken, you may wait on a ``recv``
176177
forever, because the socket will *not* tell you that there's nothing more to
@@ -336,7 +337,7 @@ Use ``select``.
336337

337338
In C, coding ``select`` is fairly complex. In Python, it's a piece of cake, but
338339
it's close enough to the C version that if you understand ``select`` in Python,
339-
you'll have little trouble with it in C. ::
340+
you'll have little trouble with it in C::
340341

341342
ready_to_read, ready_to_write, in_error = \
342343
select.select(
@@ -353,9 +354,9 @@ call is blocking, but you can give it a timeout. This is generally a sensible
353354
thing to do - give it a nice long timeout (say a minute) unless you have good
354355
reason to do otherwise.
355356

356-
In return, you will get three lists. They have the sockets that are actually
357+
In return, you will get three lists. They contain the sockets that are actually
357358
readable, writable and in error. Each of these lists is a subset (possibly
358-
empty) of the corresponding list you passed in. And if you put a socket in more
359+
empty) of the corresponding list you passed in. If you put a socket in more
359360
than one input list, it will only be (at most) in one output list.
360361

361362
If a socket is in the output readable list, you can be

Doc/library/pprint.rst

Lines changed: 99 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -189,37 +189,105 @@ are converted to strings. The default implementation uses the internals of the
189189

190190
.. _pprint-example:
191191

192-
pprint Example
193-
--------------
192+
Example
193+
-------
194194

195-
This example demonstrates several uses of the :func:`pprint` function and its
196-
parameters.
195+
To demonstrate several uses of the :func:`pprint` function and its parameters,
196+
let's fetch information about a package from PyPI::
197197

198+
>>> import json
198199
>>> import pprint
199-
>>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
200-
... ('parrot', ('fresh fruit',))))))))
201-
>>> stuff = ['a' * 10, tup, ['a' * 30, 'b' * 30], ['c' * 20, 'd' * 20]]
202-
>>> pprint.pprint(stuff)
203-
['aaaaaaaaaa',
204-
('spam',
205-
('eggs',
206-
('lumberjack',
207-
('knights', ('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
208-
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
209-
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
210-
>>> pprint.pprint(stuff, depth=3)
211-
['aaaaaaaaaa',
212-
('spam', ('eggs', (...))),
213-
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
214-
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
215-
>>> pprint.pprint(stuff, width=60)
216-
['aaaaaaaaaa',
217-
('spam',
218-
('eggs',
219-
('lumberjack',
220-
('knights',
221-
('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
222-
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
223-
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
224-
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
225-
200+
>>> from urllib.request import urlopen
201+
>>> with urlopen('http://pypi.python.org/pypi/configparser/json') as url:
202+
... http_info = url.info()
203+
... raw_data = url.read().decode(http_info.get_content_charset())
204+
>>> package_data = json.loads(raw_data)
205+
>>> result = {'headers': http_info.items(), 'body': package_data}
206+
207+
In its basic form, :func:`pprint` shows the whole object::
208+
209+
>>> pprint.pprint(result)
210+
{'body': {'info': {'_pypi_hidden': False,
211+
'_pypi_ordering': 12,
212+
'classifiers': ['Development Status :: 4 - Beta',
213+
'Intended Audience :: Developers',
214+
'License :: OSI Approved :: MIT License',
215+
'Natural Language :: English',
216+
'Operating System :: OS Independent',
217+
'Programming Language :: Python',
218+
'Programming Language :: Python :: 2',
219+
'Programming Language :: Python :: 2.6',
220+
'Programming Language :: Python :: 2.7',
221+
'Topic :: Software Development :: Libraries',
222+
'Topic :: Software Development :: Libraries :: Python Modules'],
223+
'download_url': 'UNKNOWN',
224+
'home_page': 'http://docs.python.org/py3k/library/configparser.html',
225+
'keywords': 'configparser ini parsing conf cfg configuration file',
226+
'license': 'MIT',
227+
'name': 'configparser',
228+
'package_url': 'http://pypi.python.org/pypi/configparser',
229+
'platform': 'any',
230+
'release_url': 'http://pypi.python.org/pypi/configparser/3.2.0r3',
231+
'requires_python': None,
232+
'stable_version': None,
233+
'summary': 'This library brings the updated configparser from Python 3.2+ to Python 2.6-2.7.',
234+
'version': '3.2.0r3'},
235+
'urls': [{'comment_text': '',
236+
'downloads': 47,
237+
'filename': 'configparser-3.2.0r3.tar.gz',
238+
'has_sig': False,
239+
'md5_digest': '8500fd87c61ac0de328fc996fce69b96',
240+
'packagetype': 'sdist',
241+
'python_version': 'source',
242+
'size': 32281,
243+
'upload_time': '2011-05-10T16:28:50',
244+
'url': 'http://pypi.python.org/packages/source/c/configparser/configparser-3.2.0r3.tar.gz'}]},
245+
'headers': [('Date', 'Sat, 14 May 2011 12:48:52 GMT'),
246+
('Server', 'Apache/2.2.16 (Debian)'),
247+
('Content-Disposition', 'inline'),
248+
('Connection', 'close'),
249+
('Transfer-Encoding', 'chunked'),
250+
('Content-Type', 'application/json; charset="UTF-8"')]}
251+
252+
The result can be limited to a certain *depth* (ellipsis is used for deeper
253+
contents)::
254+
255+
>>> pprint.pprint(result, depth=3)
256+
{'body': {'info': {'_pypi_hidden': False,
257+
'_pypi_ordering': 12,
258+
'classifiers': [...],
259+
'download_url': 'UNKNOWN',
260+
'home_page': 'http://docs.python.org/py3k/library/configparser.html',
261+
'keywords': 'configparser ini parsing conf cfg configuration file',
262+
'license': 'MIT',
263+
'name': 'configparser',
264+
'package_url': 'http://pypi.python.org/pypi/configparser',
265+
'platform': 'any',
266+
'release_url': 'http://pypi.python.org/pypi/configparser/3.2.0r3',
267+
'requires_python': None,
268+
'stable_version': None,
269+
'summary': 'This library brings the updated configparser from Python 3.2+ to Python 2.6-2.7.',
270+
'version': '3.2.0r3'},
271+
'urls': [{...}]},
272+
'headers': [('Date', 'Sat, 14 May 2011 12:48:52 GMT'),
273+
('Server', 'Apache/2.2.16 (Debian)'),
274+
('Content-Disposition', 'inline'),
275+
('Connection', 'close'),
276+
('Transfer-Encoding', 'chunked'),
277+
('Content-Type', 'application/json; charset="UTF-8"')]}
278+
279+
Additionally, maximum *width* can be suggested. If a long object cannot be
280+
split, the specified width will be exceeded::
281+
282+
>>> pprint.pprint(result['headers'], width=30)
283+
[('Date',
284+
'Sat, 14 May 2011 12:48:52 GMT'),
285+
('Server',
286+
'Apache/2.2.16 (Debian)'),
287+
('Content-Disposition',
288+
'inline'),
289+
('Connection', 'close'),
290+
('Transfer-Encoding',
291+
'chunked'),
292+
('Content-Type',
293+
'application/json; charset="UTF-8"')]

Lib/idlelib/NEWS.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ What's New in IDLE 3.2.1?
33

44
*Release date: 15-May-11*
55

6+
- Issue #6378: Further adjust idle.bat to start associated Python
7+
68
- Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
79

810
- Issue #1028: Ctrl-space binding to show completions was causing IDLE to exit.
@@ -63,7 +65,7 @@ What's New in IDLE 2.7? (UNRELEASED, but merged into 3.1 releases above.)
6365
extract port from command line when warnings are present.
6466

6567
- Tk 8.5 Text widget requires 'wordprocessor' tabstyle attr to handle
66-
mixed space/tab properly. Issue 5120, patch by Guilherme Polo.
68+
mixed space/tab properly. Issue 5129, patch by Guilherme Polo.
6769

6870
- Issue #3549: On MacOS the preferences menu was not present
6971

Lib/idlelib/idle.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@echo off
22
rem Start IDLE using the appropriate Python interpreter
33
set CURRDIR=%~dp0
4-
start "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9
4+
start "IDLE" "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9

Lib/json/decoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import struct
77

8-
from json.scanner import make_scanner
8+
from json import scanner
99
try:
1010
from _json import scanstring as c_scanstring
1111
except ImportError:
@@ -340,7 +340,7 @@ def __init__(self, object_hook=None, parse_float=None,
340340
self.parse_array = JSONArray
341341
self.parse_string = scanstring
342342
self.memo = {}
343-
self.scan_once = make_scanner(self)
343+
self.scan_once = scanner.make_scanner(self)
344344

345345

346346
def decode(self, s, _w=WHITESPACE.match):

Lib/test/json_tests/__init__.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
import os
22
import sys
3-
import unittest
3+
import json
44
import doctest
5+
import unittest
6+
7+
from test import support
8+
9+
# import json with and without accelerations
10+
cjson = support.import_fresh_module('json', fresh=['_json'])
11+
pyjson = support.import_fresh_module('json', blocked=['_json'])
12+
13+
# create two base classes that will be used by the other tests
14+
class PyTest(unittest.TestCase):
15+
json = pyjson
16+
loads = staticmethod(pyjson.loads)
17+
dumps = staticmethod(pyjson.dumps)
18+
19+
@unittest.skipUnless(cjson, 'requires _json')
20+
class CTest(unittest.TestCase):
21+
if cjson is not None:
22+
json = cjson
23+
loads = staticmethod(cjson.loads)
24+
dumps = staticmethod(cjson.dumps)
25+
26+
# test PyTest and CTest checking if the functions come from the right module
27+
class TestPyTest(PyTest):
28+
def test_pyjson(self):
29+
self.assertEqual(self.json.scanner.make_scanner.__module__,
30+
'json.scanner')
31+
self.assertEqual(self.json.decoder.scanstring.__module__,
32+
'json.decoder')
33+
self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
34+
'json.encoder')
35+
36+
class TestCTest(CTest):
37+
def test_cjson(self):
38+
self.assertEqual(self.json.scanner.make_scanner.__module__, '_json')
39+
self.assertEqual(self.json.decoder.scanstring.__module__, '_json')
40+
self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json')
41+
self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
42+
'_json')
43+
544

645
here = os.path.dirname(__file__)
746

@@ -17,12 +56,11 @@ def test_suite():
1756
return suite
1857

1958
def additional_tests():
20-
import json
21-
import json.encoder
22-
import json.decoder
2359
suite = unittest.TestSuite()
2460
for mod in (json, json.encoder, json.decoder):
2561
suite.addTest(doctest.DocTestSuite(mod))
62+
suite.addTest(TestPyTest('test_pyjson'))
63+
suite.addTest(TestCTest('test_cjson'))
2664
return suite
2765

2866
def main():

0 commit comments

Comments
 (0)