def parseCSS(self):
        #print repr(self.cssText)
        
        # self.debug(9, self.cssText)
        
        # XXX Must be handled in a better way!
                
        #self.cssText = self.cssText.replace("<!--", "\n")
        #self.cssText = self.cssText.replace("-->", "\n")
        #self.cssText = self.cssText.replace("<![CDATA[", "\n")
        #self.cssText = self.cssText.replace("]]>", "\n")
        
        #self.debug(9, self.cssText)
           
        # print repr(self.cssText)
        # file("pisa.css", "wb").write(self.cssText.encode("utf8"))
        
        # self.cssText = re.compile(r"url\((.*?\))", re.M).sub('"\1"', self.cssText)
        # self.cssText = re.compile(r"\-moz\-.*?([\;\}]+)", re.M).sub(r"\1", self.cssText)

        # XXX Import has to be implemented!
        # self.cssText = re.compile(r"\@import.*;", re.M).sub("", self.cssText)

#        if 0:
#            try:
#                # Sanitize CSS
#                import cssutils
#                import logging            
#                cssutils.log.setlog(logging.getLogger('csslog'))
#                cssutils.log.setloglevel(logging.DEBUG)
#                sheet = cssutils.parseString(self.cssText)
#                self.cssText = sheet.cssText                
#                #err = csslog.getvalue()   
#            except ImportError, e:
#                pass     
#            except Exception, e:
#                log.exception(self.error("Error parsing CSS by cssutils"))
        
        # print self.cssText
        # file("pisa-sanitized.css", "w").write(self.cssText.encode("utf8"))        
        # print self.cssText
        
        
        self.cssBuilder = pisaCSSBuilder(mediumSet=["all", "print", "pdf"])        
        self.cssBuilder.c = self
        self.cssParser = pisaCSSParser(self.cssBuilder)   
        self.cssParser.rootPath = self.pathDirectory
        self.cssParser.c = self
        
        self.css = self.cssParser.parse(self.cssText)
        self.cssCascade = css.CSSCascadeStrategy(self.css)
        self.cssCascade.parser = self.cssParser
Пример #2
0
                pass
            except Exception, e:
                self.error("Error parsing CSS by cssutils: %s" % ErrorMsg(e))

        # print self.cssText
        # file("pisa-sanitized.css", "w").write(self.cssText.encode("utf8"))
        # print self.cssText

        self.cssBuilder = pisaCSSBuilder(mediumSet=["all", "print", "pdf"])
        self.cssBuilder.c = self
        self.cssParser = pisaCSSParser(self.cssBuilder)
        self.cssParser.rootPath = self.pathDirectory
        self.cssParser.c = self

        self.css = self.cssParser.parse(self.cssText)
        self.cssCascade = css.CSSCascadeStrategy(self.css)
        self.cssCascade.parser = self.cssParser

    # METHODS FOR STORY

    def addStory(self, data):
        self.story.append(data)

    def swapStory(self, story=[]):
        self.story, story = copy.copy(story), copy.copy(self.story)
        return story

    def addPara(self, force=False):

        # Cleanup the trail
        for frag in reversed(self.fragList):