Mercurial > cpython-lru_cache-weakref
annotate Lib/socket.py @ 25135:0f0016632be4 legacy-trunk
_formatparam(), set_param(): RFC 2231 encoding support by Oleg
Broytmann in SF patch #600096. Specifically, the former function now
encodes the triplets, while the latter adds optional charset and
language arguments.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Fri, 06 Sep 2002 03:55:04 +0000 |
| parents | 54b601d3b2a6 |
| children | 161b8bd8a226 |
| rev | line source |
|---|---|
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 # Wrapper module for _socket, providing some additional facilities |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 # implemented in Python. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 """\ |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 This module provides socket operations and some related functions. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 On Unix, it supports IP (Internet Protocol) and Unix domain sockets. |
|
15872
3685ef2a55a4
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14935
diff
changeset
|
7 On other systems, it only supports IP. Functions specific for a |
|
14935
13488539f02b
Mention in the module's doc string that other functions of the socket API
Martin v. Löwis <martin@v.loewis.de>
parents:
14682
diff
changeset
|
8 socket are available as methods of the socket object. |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 Functions: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 socket() -- create a new socket object |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 fromfd() -- create a socket object from an open file descriptor [*] |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 gethostname() -- return the current hostname |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 gethostbyname() -- map a hostname to its IP number |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 gethostbyaddr() -- map an IP number or hostname to DNS info |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 getservbyname() -- map a service name and a protocol name to a port number |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 htons(), htonl() -- convert 16, 32 bit int from host to network byte order |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89) |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 ssl() -- secure socket layer support (only available if configured) |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23844
diff
changeset
|
24 socket.getdefaulttimeout() -- get the default timeout value |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23844
diff
changeset
|
25 socket.setdefaulttimeout() -- set the default timeout value |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 [*] not available on all platforms! |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 Special objects: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 SocketType -- type object for socket objects |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 error -- exception raised for I/O errors |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 Integer constants: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 AF_INET, AF_UNIX -- socket domains (first argument to socket() call) |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument) |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 Many other constants may be defined; these may be used in calls to |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 the setsockopt() and getsockopt() methods. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 """ |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 |
|
21971
fce7278d46b0
Repair so that importing socket doesn't blow up on platforms that lack
Tim Peters <tim.peters@gmail.com>
parents:
21962
diff
changeset
|
43 import _socket |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 from _socket import * |
|
21971
fce7278d46b0
Repair so that importing socket doesn't blow up on platforms that lack
Tim Peters <tim.peters@gmail.com>
parents:
21962
diff
changeset
|
45 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
46 _have_ssl = False |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21473
diff
changeset
|
47 try: |
|
24663
b265e76bab88
Extend __all__ with the exports list of the _ssl module.
Guido van Rossum <guido@python.org>
parents:
24662
diff
changeset
|
48 import _ssl |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21473
diff
changeset
|
49 from _ssl import * |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
50 _have_ssl = True |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21473
diff
changeset
|
51 except ImportError: |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
52 pass |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
53 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 import os, sys |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
55 |
| 16613 | 56 __all__ = ["getfqdn"] |
| 57 __all__.extend(os._get_exports_list(_socket)) | |
|
24663
b265e76bab88
Extend __all__ with the exports list of the _ssl module.
Guido van Rossum <guido@python.org>
parents:
24662
diff
changeset
|
58 if _have_ssl: |
|
b265e76bab88
Extend __all__ with the exports list of the _ssl module.
Guido van Rossum <guido@python.org>
parents:
24662
diff
changeset
|
59 __all__.extend(os._get_exports_list(_ssl)) |
| 16613 | 60 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
61 _realsocket = socket |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
62 _needwrapper = False |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
63 if (sys.platform.lower().startswith("win") |
|
16949
09ba15ee1961
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16613
diff
changeset
|
64 or (hasattr(os, 'uname') and os.uname()[0] == "BeOS") |
|
21971
fce7278d46b0
Repair so that importing socket doesn't blow up on platforms that lack
Tim Peters <tim.peters@gmail.com>
parents:
21962
diff
changeset
|
65 or sys.platform=="riscos"): |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
67 _needwrapper = True |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
68 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
69 if _have_ssl: |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
70 _realssl = ssl |
|
17156
1be0d1c57834
Add a wrapper function for ssl() on Windows. Inspired by SF patch
Guido van Rossum <guido@python.org>
parents:
17071
diff
changeset
|
71 def ssl(sock, keyfile=None, certfile=None): |
|
1be0d1c57834
Add a wrapper function for ssl() on Windows. Inspired by SF patch
Guido van Rossum <guido@python.org>
parents:
17071
diff
changeset
|
72 if hasattr(sock, "_sock"): |
|
1be0d1c57834
Add a wrapper function for ssl() on Windows. Inspired by SF patch
Guido van Rossum <guido@python.org>
parents:
17071
diff
changeset
|
73 sock = sock._sock |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
74 return _realssl(sock, keyfile, certfile) |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
75 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
76 # WSA error codes |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
77 if sys.platform.lower().startswith("win"): |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
78 errorTab = {} |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 errorTab[10004] = "The operation was interrupted." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
80 errorTab[10009] = "A bad file handle was passed." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
81 errorTab[10013] = "Permission denied." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
82 errorTab[10014] = "A fault occurred on the network??" # WSAEFAULT |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
83 errorTab[10022] = "An invalid operation was attempted." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
84 errorTab[10035] = "The socket operation would block" |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
85 errorTab[10036] = "A blocking operation is already in progress." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
86 errorTab[10048] = "The network address is in use." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
87 errorTab[10054] = "The connection has been reset." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 errorTab[10058] = "The network has been shut down." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 errorTab[10060] = "The operation timed out." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
90 errorTab[10061] = "Connection refused." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
91 errorTab[10063] = "The name is too long." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
92 errorTab[10064] = "The host is down." |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
93 errorTab[10065] = "The host is unreachable." |
|
17071
b45ae8c467aa
add errorTab to __all__ on win*
Skip Montanaro <skip@pobox.com>
parents:
16949
diff
changeset
|
94 __all__.append("errorTab") |
|
24663
b265e76bab88
Extend __all__ with the exports list of the _ssl module.
Guido van Rossum <guido@python.org>
parents:
24662
diff
changeset
|
95 |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
96 del os, sys |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
97 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
98 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
99 def getfqdn(name=''): |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
100 """Get fully qualified domain name from name. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
101 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
102 An empty argument is interpreted as meaning the local host. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
103 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
104 First the hostname returned by gethostbyaddr() is checked, then |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
105 possibly existing aliases. In case no FQDN is available, hostname |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
106 is returned. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
107 """ |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
108 name = name.strip() |
|
14014
3d68d5bccd40
updated occurences of fqdn algorithm (closes patch #101197)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
14007
diff
changeset
|
109 if not name or name == '0.0.0.0': |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
110 name = gethostname() |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
111 try: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
112 hostname, aliases, ipaddrs = gethostbyaddr(name) |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
113 except error: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
114 pass |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
115 else: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
116 aliases.insert(0, hostname) |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
117 for name in aliases: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 if '.' in name: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 break |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 else: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 name = hostname |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 return name |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
124 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
125 # |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
126 # These classes are used by the socket() defined on Windows and BeOS |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
127 # platforms to provide a best-effort implementation of the cleanup |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
128 # semantics needed when sockets can't be dup()ed. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
129 # |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
130 # These are not actually used on other platforms. |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
131 # |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
132 |
|
19364
b738428238f1
When the socket is closed, don't just assign 0 to self._sock.
Guido van Rossum <guido@python.org>
parents:
17245
diff
changeset
|
133 _socketmethods = ( |
|
b738428238f1
When the socket is closed, don't just assign 0 to self._sock.
Guido van Rossum <guido@python.org>
parents:
17245
diff
changeset
|
134 'bind', 'connect', 'connect_ex', 'fileno', 'listen', |
|
b738428238f1
When the socket is closed, don't just assign 0 to self._sock.
Guido van Rossum <guido@python.org>
parents:
17245
diff
changeset
|
135 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
136 'recv', 'recvfrom', 'send', 'sendall', 'sendto', 'setblocking', |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
137 'settimeout', 'gettimeout', 'shutdown') |
|
19364
b738428238f1
When the socket is closed, don't just assign 0 to self._sock.
Guido van Rossum <guido@python.org>
parents:
17245
diff
changeset
|
138 |
|
24666
4fbf534211b9
The _socketobject class has no need for a __del__ method: all it did was
Guido van Rossum <guido@python.org>
parents:
24665
diff
changeset
|
139 class _closedsocket(object): |
|
4fbf534211b9
The _socketobject class has no need for a __del__ method: all it did was
Guido van Rossum <guido@python.org>
parents:
24665
diff
changeset
|
140 __slots__ = [] |
|
4fbf534211b9
The _socketobject class has no need for a __del__ method: all it did was
Guido van Rossum <guido@python.org>
parents:
24665
diff
changeset
|
141 def __getattr__(self, name): |
|
4fbf534211b9
The _socketobject class has no need for a __del__ method: all it did was
Guido van Rossum <guido@python.org>
parents:
24665
diff
changeset
|
142 raise error(9, 'Bad file descriptor') |
|
4fbf534211b9
The _socketobject class has no need for a __del__ method: all it did was
Guido van Rossum <guido@python.org>
parents:
24665
diff
changeset
|
143 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
144 class _socketobject(object): |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
145 |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
146 __doc__ = _realsocket.__doc__ |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
147 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
148 __slots__ = ["_sock"] |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
149 |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
150 def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None): |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
151 if _sock is None: |
|
24662
a61893d7cef2
Oops, stupid tabs. Sorry again.
Guido van Rossum <guido@python.org>
parents:
24661
diff
changeset
|
152 _sock = _realsocket(family, type, proto) |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
153 self._sock = _sock |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
154 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
155 def close(self): |
|
24666
4fbf534211b9
The _socketobject class has no need for a __del__ method: all it did was
Guido van Rossum <guido@python.org>
parents:
24665
diff
changeset
|
156 self._sock = _closedsocket() |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
157 close.__doc__ = _realsocket.close.__doc__ |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
158 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
159 def accept(self): |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
160 sock, addr = self._sock.accept() |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
161 return _socketobject(_sock=sock), addr |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
162 accept.__doc__ = _realsocket.accept.__doc__ |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
163 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
164 def dup(self): |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
165 """dup() -> socket object |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
166 |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
167 Return a new socket object connected to the same system resource.""" |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
168 return _socketobject(_sock=self._sock) |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
169 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
170 def makefile(self, mode='r', bufsize=-1): |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
171 """makefile([mode[, bufsize]]) -> file object |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
172 |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
173 Return a regular file object corresponding to the socket. The mode |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
174 and bufsize arguments are as for the built-in open() function.""" |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
175 return _fileobject(self._sock, mode, bufsize) |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
176 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
177 _s = ("def %s(self, *args): return self._sock.%s(*args)\n\n" |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
178 "%s.__doc__ = _realsocket.%s.__doc__\n") |
|
19364
b738428238f1
When the socket is closed, don't just assign 0 to self._sock.
Guido van Rossum <guido@python.org>
parents:
17245
diff
changeset
|
179 for _m in _socketmethods: |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
180 exec _s % (_m, _m, _m, _m) |
|
24673
3796d39f0b80
Delete junk attributes left behind by _socketobject class construction.
Tim Peters <tim.peters@gmail.com>
parents:
24666
diff
changeset
|
181 del _m, _s |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
182 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
183 if _needwrapper: |
|
24944
54b601d3b2a6
On Windows, make sure SocketType is the same as socket. (SF bug
Guido van Rossum <guido@python.org>
parents:
24673
diff
changeset
|
184 socket = SocketType = _socketobject |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
185 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
186 class _fileobject(object): |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
187 """Faux file object attached to a socket object.""" |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
188 |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
189 default_bufsize = 8192 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
190 name = "<socket>" |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
191 |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
192 __slots__ = ["mode", "bufsize", "softspace", |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
193 # "closed" is a property, see below |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
194 "_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf"] |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
195 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24454
diff
changeset
|
196 def __init__(self, sock, mode='rb', bufsize=-1): |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
197 self._sock = sock |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
198 self.mode = mode # Not actually used in this version |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
199 if bufsize < 0: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
200 bufsize = self.default_bufsize |
|
24662
a61893d7cef2
Oops, stupid tabs. Sorry again.
Guido van Rossum <guido@python.org>
parents:
24661
diff
changeset
|
201 self.bufsize = bufsize |
|
a61893d7cef2
Oops, stupid tabs. Sorry again.
Guido van Rossum <guido@python.org>
parents:
24661
diff
changeset
|
202 self.softspace = False |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
203 if bufsize == 0: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
204 self._rbufsize = 1 |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
205 elif bufsize == 1: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
206 self._rbufsize = self.default_bufsize |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
207 else: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
208 self._rbufsize = bufsize |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
209 self._wbufsize = bufsize |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
210 self._rbuf = "" # A string |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
211 self._wbuf = [] # A list of strings |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
212 |
|
24661
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
213 def _getclosed(self): |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
214 return self._sock is not None |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
215 closed = property(_getclosed, doc="True if the file is closed") |
|
2f411f2d791a
Another refactoring. Changed 'socket' from being a factory function
Guido van Rossum <guido@python.org>
parents:
24656
diff
changeset
|
216 |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
217 def close(self): |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
218 try: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
219 if self._sock: |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
220 self.flush() |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
221 finally: |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
222 self._sock = None |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
223 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
224 def __del__(self): |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
225 self.close() |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
226 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
227 def flush(self): |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
228 if self._wbuf: |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
229 buffer = "".join(self._wbuf) |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
230 self._wbuf = [] |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
231 self._sock.sendall(buffer) |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
232 |
| 23844 | 233 def fileno(self): |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
234 return self._sock.fileno() |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
235 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
236 def write(self, data): |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
237 data = str(data) # XXX Should really reject non-string non-buffers |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
238 if not data: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
239 return |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
240 self._wbuf.append(data) |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
241 if (self._wbufsize == 0 or |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
242 self._wbufsize == 1 and '\n' in data or |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
243 self._get_wbuf_len() >= self._wbufsize): |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
244 self.flush() |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
245 |
|
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
246 def writelines(self, list): |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
247 # XXX We could do better here for very long lists |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
248 # XXX Should really reject non-string non-buffers |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
249 self._wbuf.extend(filter(None, map(str, list))) |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
250 if (self._wbufsize <= 1 or |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
251 self._get_wbuf_len() >= self._wbufsize): |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
252 self.flush() |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
253 |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
254 def _get_wbuf_len(self): |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
255 buf_len = 0 |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
256 for x in self._wbuf: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
257 buf_len += len(x) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
258 return buf_len |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
259 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
260 def read(self, size=-1): |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
261 data = self._rbuf |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
262 if size < 0: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
263 # Read until EOF |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
264 buffers = [] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
265 if data: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
266 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
267 self._rbuf = "" |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
268 if self._rbufsize <= 1: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
269 recv_size = self.default_bufsize |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
270 else: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
271 recv_size = self._rbufsize |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
272 while True: |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
273 data = self._sock.recv(recv_size) |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
274 if not data: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
275 break |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
276 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
277 return "".join(buffers) |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
278 else: |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
279 # Read until size bytes or EOF seen, whichever comes first |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
280 buf_len = len(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
281 if buf_len >= size: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
282 self._rbuf = data[size:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
283 return data[:size] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
284 buffers = [] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
285 if data: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
286 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
287 self._rbuf = "" |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
288 while True: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
289 left = size - buf_len |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
290 recv_size = max(self._rbufsize, left) |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
291 data = self._sock.recv(recv_size) |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
292 if not data: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
293 break |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
294 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
295 n = len(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
296 if n >= left: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
297 self._rbuf = data[left:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
298 buffers[-1] = data[:left] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
299 break |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
300 buf_len += n |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
301 return "".join(buffers) |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
302 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
303 def readline(self, size=-1): |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
304 data = self._rbuf |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
305 if size < 0: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
306 # Read until \n or EOF, whichever comes first |
|
24665
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
307 if self._rbufsize <= 1: |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
308 # Speed up unbuffered case |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
309 assert data == "" |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
310 buffers = [] |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
311 recv = self._sock.recv |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
312 while data != "\n": |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
313 data = recv(1) |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
314 if not data: |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
315 break |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
316 buffers.append(data) |
|
d25cf94d20b1
OK, one more hack: speed up the case of readline() in unbuffered mode.
Guido van Rossum <guido@python.org>
parents:
24664
diff
changeset
|
317 return "".join(buffers) |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
318 nl = data.find('\n') |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
319 if nl >= 0: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
320 nl += 1 |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
321 self._rbuf = data[nl:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
322 return data[:nl] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
323 buffers = [] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
324 if data: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
325 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
326 self._rbuf = "" |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
327 while True: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
328 data = self._sock.recv(self._rbufsize) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
329 if not data: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
330 break |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
331 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
332 nl = data.find('\n') |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
333 if nl >= 0: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
334 nl += 1 |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
335 self._rbuf = data[nl:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
336 buffers[-1] = data[:nl] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
337 break |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
338 return "".join(buffers) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
339 else: |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
340 # Read until size bytes or \n or EOF seen, whichever comes first |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
341 nl = data.find('\n', 0, size) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
342 if nl >= 0: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
343 nl += 1 |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
344 self._rbuf = data[nl:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
345 return data[:nl] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
346 buf_len = len(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
347 if buf_len >= size: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
348 self._rbuf = data[size:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
349 return data[:size] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
350 buffers = [] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
351 if data: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
352 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
353 self._rbuf = "" |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
354 while True: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
355 data = self._sock.recv(self._rbufsize) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
356 if not data: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
357 break |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
358 buffers.append(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
359 left = size - buf_len |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
360 nl = data.find('\n', 0, left) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
361 if nl >= 0: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
362 nl += 1 |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
363 self._rbuf = data[nl:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
364 buffers[-1] = data[:nl] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
365 break |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
366 n = len(data) |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
367 if n >= left: |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
368 self._rbuf = data[left:] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
369 buffers[-1] = data[:left] |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
370 break |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
371 buf_len += n |
|
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
372 return "".join(buffers) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
373 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21971
diff
changeset
|
374 def readlines(self, sizehint=0): |
|
14682
295126433856
Support sizehint in _fileobject.readlines, as documented.
Martin v. Löwis <martin@v.loewis.de>
parents:
14592
diff
changeset
|
375 total = 0 |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
376 list = [] |
|
24664
6a6d02be321c
Another refactoring of read() and readline(), this time based on the
Guido van Rossum <guido@python.org>
parents:
24663
diff
changeset
|
377 while True: |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
378 line = self.readline() |
| 23844 | 379 if not line: |
| 380 break | |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
381 list.append(line) |
|
14682
295126433856
Support sizehint in _fileobject.readlines, as documented.
Martin v. Löwis <martin@v.loewis.de>
parents:
14592
diff
changeset
|
382 total += len(line) |
|
295126433856
Support sizehint in _fileobject.readlines, as documented.
Martin v. Löwis <martin@v.loewis.de>
parents:
14592
diff
changeset
|
383 if sizehint and total >= sizehint: |
|
295126433856
Support sizehint in _fileobject.readlines, as documented.
Martin v. Löwis <martin@v.loewis.de>
parents:
14592
diff
changeset
|
384 break |
|
14007
eda09f824a9f
Revise the wrapper structure for the socket module:
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
385 return list |
|
24656
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
386 |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
387 # Iterator protocols |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
388 |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
389 def __iter__(self): |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
390 return self |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
391 |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
392 def next(self): |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
393 line = self.readline() |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
394 if not line: |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
395 raise StopIteration |
|
e61b118e9cab
Major restructuring of _fileobject. Hopefully several things now work
Guido van Rossum <guido@python.org>
parents:
24649
diff
changeset
|
396 return line |
