[Checkins]
SVN: zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py
Refactor dependency resolution into a separate method
(because it is buggy and
Marius Gedminas
marius at pov.lt
Mon Oct 23 10:32:05 EDT 2006
Log message for revision 70890:
Refactor dependency resolution into a separate method (because it is buggy and
will be tested and fixed soon).
Changed:
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py
-=-
Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py 2006-10-23 14:18:31 UTC (rev 70889)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py 2006-10-23 14:32:04 UTC (rev 70890)
@@ -70,30 +70,12 @@
if content_type is None:
if isHTML(body):
content_type = 'text/html'
-
+
if content_type == 'text/html' or content_type == 'text/xml':
#act on HTML and XML content only!
-
- # add any libraries that the explicitly referenced
- # libraries require
- libs = list(self.resource_libraries)
- while libs:
- lib = libs.pop()
- try:
- required = zc.resourcelibrary.getRequired(lib)
- except KeyError:
- raise RuntimeError('Unknown resource library: "%s"' % lib)
- for lib in required:
- if lib not in self.resource_libraries:
- self.resource_libraries.append(lib)
- libs.append(lib)
-
- # reverse the order of the libs in order to have the
- # dependencies first. TODO: this does not work if the
- # dependency is needed directly in the page before the
- # dependent lib is needed.
- self.resource_libraries.reverse()
-
+
+ self.resource_libraries = self._addDependencies(self.resource_libraries)
+
# generate the HTML that will be included in the response
html = []
site = getSite()
@@ -125,3 +107,28 @@
return super(Response, self)._implicitResult(body)
+
+ def _addDependencies(self, resource_libraries):
+ # avoid side effects by copying the list before modifying it
+ resource_libraries = list(resource_libraries)
+ # add any libraries that the explicitly referenced
+ # libraries require
+ libs = list(resource_libraries)
+ while libs:
+ lib = libs.pop()
+ try:
+ required = zc.resourcelibrary.getRequired(lib)
+ except KeyError:
+ raise RuntimeError('Unknown resource library: "%s"' % lib)
+ for lib in required:
+ if lib not in resource_libraries:
+ resource_libraries.append(lib)
+ libs.append(lib)
+
+ # reverse the order of the libs in order to have the
+ # dependencies first. TODO: this does not work if the
+ # dependency is needed directly in the page before the
+ # dependent lib is needed.
+ resource_libraries.reverse()
+ return resource_libraries
+
More information about the Checkins
mailing list