summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-02-24 15:55:43 (GMT)
committerGuido van Rossum <guido@python.org>1994-02-24 15:55:43 (GMT)
commit914973a0be23164a936cbdd1c1a3e67c82a13500 (patch)
tree7ce1eb73cde626eb76365f529164f9376d86a18f /Lib
parentd5b9ea1c67d997e7ff24bf70aa96bec6f0bf28d9 (diff)
downloadcpython-914973a0be23164a936cbdd1c1a3e67c82a13500.zip
cpython-914973a0be23164a936cbdd1c1a3e67c82a13500.tar.gz
cpython-914973a0be23164a936cbdd1c1a3e67c82a13500.tar.bz2
Added __repr__ to addbase class; delete more objects
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/urlopen.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/urlopen.py b/Lib/urlopen.py
index 0366bda..bb0c45e 100755
--- a/Lib/urlopen.py
+++ b/Lib/urlopen.py
@@ -48,8 +48,8 @@ class URLopener:
# Constructor
def __init__(self):
self.addheaders = []
- self.ftpcache = ftpcache
self.tempfiles = []
+ self.ftpcache = ftpcache
# Undocumented feature: you can use a different
# ftp cache by assigning to the .ftpcache member;
# in case you want logically independent URL openers
@@ -84,9 +84,8 @@ class URLopener:
name = regsub.gsub('-', '_', name)
if not hasattr(self, name):
raise IOError, ('url error', 'unknown url type', type)
- meth = getattr(self, name)
try:
- return meth(url)
+ return getattr(self, name)(url)
except socket.error, msg:
raise IOError, ('socket error', msg)
@@ -98,6 +97,7 @@ class URLopener:
if not type or type == 'file':
try:
fp = self.open_local_file(url1)
+ del fp
return splithost(url1)[1], None
except IOError, msg:
pass
@@ -112,8 +112,8 @@ class URLopener:
tfp.write(block)
block = fp.read(bs)
headers = fp.info()
- fp.close()
- tfp.close()
+ del fp
+ del tfp
return tfn, headers
# Each method named open_<type> knows how to open that type of URL
@@ -258,6 +258,9 @@ class addbase:
self.readline = self.fp.readline
self.readlines = self.fp.readlines
self.fileno = self.fp.fileno
+ def __repr__(self):
+ return '<%s at %s whose fp = %s>' % (
+ self.__class__.__name__, `id(self)`, `self.fp`)
def __del__(self):
self.close()
def close(self):
@@ -265,7 +268,6 @@ class addbase:
self.readline = None
self.readlines = None
self.fileno = None
- self.fp.close()
self.fp = None
# Class to add a close hook to an open file
@@ -363,7 +365,9 @@ def test():
print '======'
fp = open(fn, 'r')
data = fp.read()
+ del fp
print regsub.gsub('\r', '', data)
+ fn, h = None, None
print '-'*40
finally:
_urlopener.cleanup()