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

Delta Between Two Patch Sets: Lib/socketserver.py

Issue 26404: socketserver context manager
Left Patch Set: Created 3 years, 12 months ago
Right Patch Set: Created 3 years, 12 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 """Generic socket server classes. 1 """Generic socket server classes.
2 2
3 This module tries to capture the various aspects of defining a server: 3 This module tries to capture the various aspects of defining a server:
4 4
5 For socket-based servers: 5 For socket-based servers:
6 6
7 - address family: 7 - address family:
8 - AF_INET{,6}: IP (Internet Protocol) sockets (default) 8 - AF_INET{,6}: IP (Internet Protocol) sockets (default)
9 - AF_UNIX: Unix domain sockets 9 - AF_UNIX: Unix domain sockets
10 - others, e.g. AF_DECNET are conceivable (see <socket.h> 10 - others, e.g. AF_DECNET are conceivable (see <socket.h>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 - split generic "request" functionality out into BaseServer class. 112 - split generic "request" functionality out into BaseServer class.
113 Copyright (C) 2000 Luke Kenneth Casson Leighton <lkcl@samba.org> 113 Copyright (C) 2000 Luke Kenneth Casson Leighton <lkcl@samba.org>
114 114
115 example: read entries from a SQL database (requires overriding 115 example: read entries from a SQL database (requires overriding
116 get_request() to return a table entry from the database). 116 get_request() to return a table entry from the database).
117 entry is processed by a RequestHandlerClass. 117 entry is processed by a RequestHandlerClass.
118 118
119 """ 119 """
120 120
121 # Author of the BaseServer patch: Luke Kenneth Casson Leighton 121 # Author of the BaseServer patch: Luke Kenneth Casson Leighton
122
123 # XXX Warning!
124 # There is a test suite for this module, but it cannot be run by the
125 # standard regression test.
126 # To run it manually, run Lib/test/test_socketserver.py.
127 122
128 __version__ = "0.4" 123 __version__ = "0.4"
129 124
130 125
131 import socket 126 import socket
132 import selectors 127 import selectors
133 import os 128 import os
134 import errno 129 import errno
135 import sys 130 import sys
136 try: 131 try:
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 except socket.error: 749 except socket.error:
755 # An final socket error may have occurred here, such as 750 # An final socket error may have occurred here, such as
756 # the local error ECONNABORTED. 751 # the local error ECONNABORTED.
757 pass 752 pass
758 self.wfile.close() 753 self.wfile.close()
759 self.rfile.close() 754 self.rfile.close()
760 755
761 756
762 class DatagramRequestHandler(BaseRequestHandler): 757 class DatagramRequestHandler(BaseRequestHandler):
763 758
764 # XXX Regrettably, I cannot get this working on Linux;
765 # s.recvfrom() doesn't return a meaningful client address.
766
767 """Define self.rfile and self.wfile for datagram sockets.""" 759 """Define self.rfile and self.wfile for datagram sockets."""
768 760
769 def setup(self): 761 def setup(self):
770 from io import BytesIO 762 from io import BytesIO
771 self.packet, self.socket = self.request 763 self.packet, self.socket = self.request
772 self.rfile = BytesIO(self.packet) 764 self.rfile = BytesIO(self.packet)
773 self.wfile = BytesIO() 765 self.wfile = BytesIO()
774 766
775 def finish(self): 767 def finish(self):
776 self.socket.sendto(self.wfile.getvalue(), self.client_address) 768 self.socket.sendto(self.wfile.getvalue(), self.client_address)
LEFTRIGHT

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