summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/socket.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index d0f0911..ce72b65 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -122,13 +122,18 @@ def getfqdn(name=''):
# These are not actually used on other platforms.
#
+_socketmethods = (
+ 'bind', 'connect', 'connect_ex', 'fileno', 'listen',
+ 'getpeername', 'getsockname', 'getsockopt', 'setsockopt',
+ 'recv', 'recvfrom', 'send', 'sendto', 'setblocking', 'shutdown')
+
class _socketobject:
def __init__(self, sock):
self._sock = sock
def close(self):
- self._sock = 0
+ self._sock = _closedsocket()
def __del__(self):
self.close()
@@ -143,16 +148,21 @@ class _socketobject:
def makefile(self, mode='r', bufsize=-1):
return _fileobject(self._sock, mode, bufsize)
- _s = "def %s(self, *args): return apply(self._sock.%s, args)\n\n"
- for _m in ('bind', 'connect', 'connect_ex', 'fileno', 'listen',
- 'getpeername', 'getsockname',
- 'getsockopt', 'setsockopt',
- 'recv', 'recvfrom', 'send', 'sendto',
- 'setblocking',
- 'shutdown'):
+ _s = "def %s(self, *args): return self._sock.%s(*args)\n\n"
+ for _m in _socketmethods:
exec _s % (_m, _m)
+class _closedsocket:
+
+ def _bummer(self):
+ raise error(9, 'Bad file descriptor')
+
+ _s = "def %s(self, *args): self._bummer()\n\n"
+ for _m in _socketmethods:
+ exec _s % _m
+
+
class _fileobject:
def __init__(self, sock, mode, bufsize):