<s> import shlex <EOL> from flowables import * <EOL> import rst2pdf . flowables <EOL> from styles import adjustUnits <EOL> from log import log , nodeid <EOL> def parseRaw ( data , node ) : <EOL> """<STR_LIT>""" <EOL> elements = [ ] <EOL> lines = data . splitlines ( ) <EOL> for line in lines : <EOL> lexer = shlex . shlex ( line ) <EOL> lexer . whitespace += '<STR_LIT:U+002C>' <EOL> tokens = list ( lexer ) <EOL> if not tokens : <EOL> continue <EOL> command = tokens [ <NUM_LIT:0> ] <EOL> if command == '<STR_LIT>' : <EOL> if len ( tokens ) == <NUM_LIT:1> : <EOL> elements . append ( MyPageBreak ( ) ) <EOL> else : <EOL> elements . append ( MyPageBreak ( tokens [ <NUM_LIT:1> ] ) ) <EOL> elif command == '<STR_LIT>' : <EOL> if len ( tokens ) == <NUM_LIT:1> : <EOL> elements . append ( MyPageBreak ( breakTo = '<STR_LIT>' ) ) <EOL> else : <EOL> elements . append ( MyPageBreak ( tokens [ <NUM_LIT:1> ] , breakTo = '<STR_LIT>' ) ) <EOL> elif command == '<STR_LIT>' : <EOL> if len ( tokens ) == <NUM_LIT:1> : <EOL> elements . append ( MyPageBreak ( breakTo = '<STR_LIT>' ) ) <EOL> else : <EOL> elements . append ( MyPageBreak ( tokens [ <NUM_LIT:1> ] , breakTo = '<STR_LIT>' ) ) <EOL> elif command == '<STR_LIT>' : <EOL> if len ( tokens ) == <NUM_LIT:1> : <EOL> elements . append ( CondPageBreak ( <NUM_LIT> ) ) <EOL> else : <EOL> elements . append ( CondPageBreak ( float ( tokens [ <NUM_LIT:1> ] ) ) ) <EOL> elif command == '<STR_LIT>' : <EOL> elements . append ( MySpacer ( adjustUnits ( tokens [ <NUM_LIT:1> ] ) , <EOL> adjustUnits ( tokens [ <NUM_LIT:2> ] ) ) ) <EOL> elif command == '<STR_LIT>' : <EOL> elements . append ( Transition ( * tokens [ <NUM_LIT:1> : ] ) ) <EOL> elif command == '<STR_LIT>' : <EOL> elements . append ( flowables . PageCounter ( * tokens [ <NUM_LIT:1> : ] ) ) <EOL> else : <EOL> log . error ( '<STR_LIT>' % ( command , nodeid ( node ) ) ) <EOL> return elements <EOL> from reportlab . lib . colors import Color , CMYKColor , getAllNamedColors , toColor , HexColor <EOL> HAS_XHTML2PDF = True <EOL> try : <EOL> from xhtml2pdf . util import COLOR_BY_NAME <EOL> from xhtml2pdf . util import memoized <EOL> from xhtml2pdf . context import pisaContext <EOL> from xhtml2pdf . default import DEFAULT_CSS <EOL> from xhtml2pdf . parser import pisaParser , pisaGetAttributes <EOL> from xhtml2pdf . document import pisaStory <EOL> from reportlab . platypus . flowables import Spacer <EOL> from reportlab . platypus . frames import Frame <EOL> from xhtml2pdf . xhtml2pdf_reportlab import PmlBaseDoc , PmlPageTemplate <EOL> from xhtml2pdf . util import pisaTempFile , getBox , pyPdf <EOL> import xhtml2pdf . parser as pisa_parser <EOL> except ImportError : <EOL> try : <EOL> from sx . pisa3 . pisa_util import COLOR_BY_NAME <EOL> memoized = lambda * a : a <EOL> from sx . pisa3 . pisa_context import pisaContext <EOL> from sx . pisa3 . pisa_default import DEFAULT_CSS <EOL> from sx . pisa3 . pisa_parser import pisaParser , pisaGetAttributes <EOL> from sx . pisa3 . pisa_document import pisaStory <EOL> from reportlab . platypus . flowables import Spacer <EOL> from reportlab . platypus . frames import Frame <EOL> from sx . pisa3 . pisa_reportlab import PmlBaseDoc , PmlPageTemplate <EOL> from sx . pisa3 . pisa_util import pisaTempFile , getBox , pyPdf <EOL> import sx . pisa3 . pisa_parser as pisa_parser <EOL> except ImportError : <EOL> HAS_XHTML2PDF = False <EOL> if HAS_XHTML2PDF : <EOL> COLOR_BY_NAME [ '<STR_LIT>' ] = Color ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> @ memoized <EOL> def getColor2 ( value , default = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , Color ) : <EOL> return value <EOL> value = str ( value ) . strip ( ) . lower ( ) <EOL> if value == "<STR_LIT>" or value == "<STR_LIT:none>" : <EOL> return default <EOL> if value in COLOR_BY_NAME : <EOL> return COLOR_BY_NAME [ value ] <EOL> if value . startswith ( "<STR_LIT:#>" ) and len ( value ) == <NUM_LIT:4> : <EOL> value = "<STR_LIT:#>" + value [ <NUM_LIT:1> ] + value [ <NUM_LIT:1> ] + value [ <NUM_LIT:2> ] + value [ <NUM_LIT:2> ] + value [ <NUM_LIT:3> ] + value [ <NUM_LIT:3> ] <EOL> elif rgb_re . search ( value ) : <EOL> r , g , b = [ int ( x ) for x in rgb_re . search ( value ) . groups ( ) ] <EOL> value = "<STR_LIT>" % ( r , g , b ) <EOL> else : <EOL> pass <EOL> return toColor ( value , default ) <EOL> import cgi <EOL> import logging <EOL> from xml . dom import Node <EOL> def pisaPreLoop2 ( node , context , collect = False ) : <EOL> """<STR_LIT>""" <EOL> data = u"<STR_LIT>" <EOL> if node . nodeType == Node . TEXT_NODE and collect : <EOL> data = node . data <EOL> elif node . nodeType == Node . ELEMENT_NODE : <EOL> name = node . tagName . lower ( ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> attr = pisaGetAttributes ( context , name , node . attributes ) <EOL> print "<STR_LIT:U+0020>" , attr <EOL> media = [ x . strip ( ) for x in attr . media . lower ( ) . split ( "<STR_LIT:U+002C>" ) if x . strip ( ) ] <EOL> if ( attr . get ( "<STR_LIT:type>" , "<STR_LIT>" ) . lower ( ) in ( "<STR_LIT>" , "<STR_LIT>" ) and ( <EOL> not media or <EOL> "<STR_LIT:all>" in media or <EOL> "<STR_LIT>" in media or <EOL> "<STR_LIT>" in media ) ) : <EOL> if name == "<STR_LIT>" : <EOL> for node in node . childNodes : <EOL> data += pisaPreLoop2 ( node , context , collect = True ) <EOL> return u"<STR_LIT>" <EOL> if name == "<STR_LIT>" and attr . href and attr . rel . lower ( ) == "<STR_LIT>" : <EOL> context . addCSS ( '<STR_LIT>' % ( attr . href , "<STR_LIT:U+002C>" . join ( media ) ) ) <EOL> for node in node . childNodes : <EOL> result = pisaPreLoop2 ( node , context , collect = collect ) <EOL> if collect : <EOL> data += result <EOL> return data <EOL> pisa_parser . pisaPreLoop = pisaPreLoop2 <EOL> HTML_CSS = """<STR_LIT>""" <EOL> def parseHTML ( data , node ) : <EOL> dest = None <EOL> path = None <EOL> link_callback = None <EOL> debug = <NUM_LIT:0> <EOL> default_css = HTML_CSS <EOL> xhtml = False <EOL> encoding = None <EOL> xml_output = None <EOL> raise_exception = True <EOL> capacity = <NUM_LIT:100> * <NUM_LIT> <EOL> context = pisaContext ( path , debug = debug , capacity = capacity ) <EOL> context . pathCallback = link_callback <EOL> context = pisaStory ( data , path , link_callback , debug , default_css , xhtml , <EOL> encoding , context = context , xml_output = xml_output ) <EOL> return context . story <EOL> else : <EOL> def parseHTML ( data , none ) : <EOL> log . error ( "<STR_LIT>" ) <EOL> return [ ] </s>
