]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added __repr__ to addbase class; delete more objects
authorGuido van Rossum <guido@python.org>
Thu, 24 Feb 1994 15:55:43 +0000 (15:55 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 24 Feb 1994 15:55:43 +0000 (15:55 +0000)
Lib/urlopen.py

index 0366bda4534c8db38948a5f4611a8aaa3ab914a4..bb0c45ecc94f2ddf1fd4e928132a91799a148012 100755 (executable)
@@ -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()