Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(165981)

Side by Side Diff: Lib/nntplib.py

Issue 19689: ssl.create_default_context()
Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/imaplib.py ('k') | Lib/poplib.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """An NNTP client class based on: 1 """An NNTP client class based on:
2 - RFC 977: Network News Transfer Protocol 2 - RFC 977: Network News Transfer Protocol
3 - RFC 2980: Common NNTP Extensions 3 - RFC 2980: Common NNTP Extensions
4 - RFC 3977: Network News Transfer Protocol (version 2) 4 - RFC 3977: Network News Transfer Protocol (version 2)
5 5
6 Example: 6 Example:
7 7
8 >>> from nntplib import NNTP 8 >>> from nntplib import NNTP
9 >>> s = NNTP('news') 9 >>> s = NNTP('news')
10 >>> resp, count, first, last, name = s.group('comp.lang.python') 10 >>> resp, count, first, last, name = s.group('comp.lang.python')
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 281
282 def _encrypt_on(sock, context): 282 def _encrypt_on(sock, context):
283 """Wrap a socket in SSL/TLS. Arguments: 283 """Wrap a socket in SSL/TLS. Arguments:
284 - sock: Socket to wrap 284 - sock: Socket to wrap
285 - context: SSL context to use for the encrypted connection 285 - context: SSL context to use for the encrypted connection
286 Returns: 286 Returns:
287 - sock: New, encrypted socket. 287 - sock: New, encrypted socket.
288 """ 288 """
289 # Generate a default SSL context if none was passed. 289 # Generate a default SSL context if none was passed.
290 if context is None: 290 if context is None:
291 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) 291 context = ssl.create_default_context()
292 # SSLv2 considered harmful.
293 context.options |= ssl.OP_NO_SSLv2
294 return context.wrap_socket(sock) 292 return context.wrap_socket(sock)
295 293
296 294
297 # The classes themselves 295 # The classes themselves
298 class _NNTPBase: 296 class _NNTPBase:
299 # UTF-8 is the character set for all NNTP commands and responses: they 297 # UTF-8 is the character set for all NNTP commands and responses: they
300 # are automatically encoded (when sending) and decoded (and receiving) 298 # are automatically encoded (when sending) and decoded (and receiving)
301 # by this class. 299 # by this class.
302 # However, some multi-line data blocks can contain arbitrary bytes (for 300 # However, some multi-line data blocks can contain arbitrary bytes (for
303 # example, latin-1 or utf-16 data in the body of a message). Commands 301 # example, latin-1 or utf-16 data in the body of a message). Commands
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 resp, overviews = s.xover(first, last) 1125 resp, overviews = s.xover(first, last)
1128 for artnum, over in overviews: 1126 for artnum, over in overviews:
1129 author = decode_header(over['from']).split('<', 1)[0] 1127 author = decode_header(over['from']).split('<', 1)[0]
1130 subject = decode_header(over['subject']) 1128 subject = decode_header(over['subject'])
1131 lines = int(over[':lines']) 1129 lines = int(over[':lines'])
1132 print("{:7} {:20} {:42} ({})".format( 1130 print("{:7} {:20} {:42} ({})".format(
1133 artnum, cut(author, 20), cut(subject, 42), lines) 1131 artnum, cut(author, 20), cut(subject, 42), lines)
1134 ) 1132 )
1135 1133
1136 s.quit() 1134 s.quit()
OLDNEW
« no previous file with comments | « Lib/imaplib.py ('k') | Lib/poplib.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+