[Zope3-checkins] CVS: Packages/ZConfig - loader.py:1.1.2.19

Fred L. Drake, Jr. fred@zope.com
Fri, 20 Dec 2002 16:18:08 -0500


Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv25503

Modified Files:
      Tag: zconfig-schema-devel-branch
	loader.py 
Log Message:
BaseLoader:
- loadURL():  Make sure we close a resource we opened
- loadResource():  Provide a default implementation with a useful
  message for subclass implementors.


=== Packages/ZConfig/loader.py 1.1.2.18 => 1.1.2.19 ===
--- Packages/ZConfig/loader.py:1.1.2.18	Fri Dec 20 16:09:51 2002
+++ Packages/ZConfig/loader.py	Fri Dec 20 16:18:07 2002
@@ -47,7 +47,10 @@
     def loadURL(self, url):
         url = self.normalizeURL(url)
         r = self.openResource(url)
-        return self.loadResource(r)
+        try:
+            return self.loadResource(r)
+        finally:
+            r.close()
 
     def loadFile(self, file, url=None):
         if not url:
@@ -56,6 +59,10 @@
         return self.loadResource(r)
 
     # utilities
+
+    def loadResource(self, resource):
+        raise NotImpementedError(
+            "BaseLoader.loadResource() must be overridden by a subclass")
 
     def openResource(self, url):
         file = urllib2.urlopen(url)