Example #1
0
    def _saveCSS(self, cssHref):
        # Try to do css files only once.
        if cssHref in self.downloadedHrefs:
            return

        fileName = self._generateResourceName(self.cssDir, cssHref,
                                              IZResourceDependencyTypes.CSS)
        download = ZSimpleTextHTTPRequest(cssHref, cookieReg=self.cookieReg)
        self.listener.onWebpageGetterResourceStarted(
            cssHref, IZResourceDependencyTypes.CSS)
        if download.send(None):
            cssContent = download.getResponse()
            self._saveFileContent(fileName, cssContent)
            self.listener.onWebpageGetterResourceComplete(cssHref)
            finder = ZCSSDependencyFinder(cssContent)
            dependencies = finder.findDependencies()
            self.listener.onWebpageGetterFoundDependencies(
                cssHref, dependencies)
            for dependency in dependencies:
                href = urlparse.urljoin(cssHref, dependency.getHref())
                resourceFile = None
                if dependency.getType() == IZResourceDependencyTypes.IMAGE:
                    resourceFile = self._saveImage(href)
                elif dependency.getType == IZResourceDependencyTypes.CSS:
                    resourceFile = self._saveCSS(href)
                    self._addResourceToFixup(resourceFile)
                if resourceFile:
                    self.downloadedHrefs.add(href)
                    self.resourceMap[dependency.getHref()] = resourceFile
        else:
            return None
#            raise ZException(_extstr(u"httpdownload.FailedToDownloadCSS") % cssHref) #$NON-NLS-1$
        return fileName
Example #2
0
 def analyseElement(self, elementNode):
     if elementNode.localName.lower() == u"style":  #$NON-NLS-1$
         css = elementNode.getText()
         cssFinder = ZCSSDependencyFinder(css)
         for dep in cssFinder.findDependencies():
             self.dependencies.append(dep)