def parseCSS(self): 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
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
def parse_css(self): # This self-reference really should be refactored. But for now # we'll settle for using weak references. This avoids memory # leaks because the garbage collector (at least on cPython # 2.7.3) isn't aggressive enough. import weakref self.CSSBuilder = PisaCSSBuilder(mediumSet=["all", "print", "pdf"]) self.CSSBuilder._c = weakref.ref(self) PisaCSSBuilder.c = property(lambda self: self._c()) self.CSSParser = PisaCSSParser(self.CSSBuilder) self.CSSParser.rootPath = self.pathDirectory self.CSSParser._c = weakref.ref(self) PisaCSSParser.c = property(lambda self: self._c()) self.css = self.CSSParser.parse(self.cssText) self.cssDefault = self.CSSParser.parse(self.cssDefaultText) self.cssCascade = css.CSSCascadeStrategy(userAgent=self.cssDefault, user=self.css) self.cssCascade.parser = self.CSSParser