<s> from __future__ import absolute_import <EOL> class HeaderFooterItem ( object ) : <EOL> """<STR_LIT>""" <EOL> CENTER = '<STR_LIT:C>' <EOL> LEFT = '<STR_LIT:L>' <EOL> RIGHT = '<STR_LIT:R>' <EOL> REPLACE_LIST = ( <EOL> ( '<STR_LIT:\n>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> __slots__ = ( '<STR_LIT:type>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:text>' ) <EOL> def __init__ ( self , type ) : <EOL> self . type = type <EOL> self . font_name = "<STR_LIT>" <EOL> self . font_size = None <EOL> self . font_color = "<STR_LIT>" <EOL> self . text = None <EOL> def has ( self ) : <EOL> return True if self . text else False <EOL> def get ( self ) : <EOL> t = [ ] <EOL> if self . text : <EOL> t . append ( '<STR_LIT>' % self . type ) <EOL> t . append ( '<STR_LIT>' % self . font_name ) <EOL> if self . font_size : <EOL> t . append ( '<STR_LIT>' % self . font_size ) <EOL> t . append ( '<STR_LIT>' % self . font_color ) <EOL> text = self . text <EOL> for old , new in self . REPLACE_LIST : <EOL> text = text . replace ( old , new ) <EOL> t . append ( text ) <EOL> return '<STR_LIT>' . join ( t ) <EOL> def set ( self , text ) : <EOL> """<STR_LIT>""" <EOL> if text is None : <EOL> return <EOL> m = FONT_REGEX . search ( text ) <EOL> if m : <EOL> self . font_name = m . group ( '<STR_LIT>' ) <EOL> text = FONT_REGEX . sub ( '<STR_LIT>' , text ) <EOL> m = SIZE_REGEX . search ( text ) <EOL> if m : <EOL> self . font_size = int ( m . group ( '<STR_LIT:size>' ) ) <EOL> text = SIZE_REGEX . sub ( '<STR_LIT>' , text ) <EOL> m = COLOR_REGEX . search ( text ) <EOL> if m : <EOL> self . font_color = m . group ( '<STR_LIT>' ) <EOL> text = COLOR_REGEX . sub ( '<STR_LIT>' , text ) <EOL> self . text = text <EOL> class HeaderFooter ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> self . left_header = HeaderFooterItem ( HeaderFooterItem . LEFT ) <EOL> self . center_header = HeaderFooterItem ( HeaderFooterItem . CENTER ) <EOL> self . right_header = HeaderFooterItem ( HeaderFooterItem . RIGHT ) <EOL> self . left_footer = HeaderFooterItem ( HeaderFooterItem . LEFT ) <EOL> self . center_footer = HeaderFooterItem ( HeaderFooterItem . CENTER ) <EOL> self . right_footer = HeaderFooterItem ( HeaderFooterItem . RIGHT ) <EOL> def hasHeader ( self ) : <EOL> return True if self . left_header . has ( ) or self . center_header . has ( ) or self . right_header . has ( ) else False <EOL> def hasFooter ( self ) : <EOL> return True if self . left_footer . has ( ) or self . center_footer . has ( ) or self . right_footer . has ( ) else False <EOL> def getHeader ( self ) : <EOL> t = [ ] <EOL> if self . left_header . has ( ) : <EOL> t . append ( self . left_header . get ( ) ) <EOL> if self . center_header . has ( ) : <EOL> t . append ( self . center_header . get ( ) ) <EOL> if self . right_header . has ( ) : <EOL> t . append ( self . right_header . get ( ) ) <EOL> return '<STR_LIT>' . join ( t ) <EOL> def getFooter ( self ) : <EOL> t = [ ] <EOL> if self . left_footer . has ( ) : <EOL> t . append ( self . left_footer . get ( ) ) <EOL> if self . center_footer . has ( ) : <EOL> t . append ( self . center_footer . get ( ) ) <EOL> if self . right_footer . has ( ) : <EOL> t . append ( self . right_footer . get ( ) ) <EOL> return '<STR_LIT>' . join ( t ) <EOL> def setHeader ( self , item ) : <EOL> matches = _split_string ( item ) <EOL> l = matches [ '<STR_LIT:left>' ] <EOL> c = matches [ '<STR_LIT>' ] <EOL> r = matches [ '<STR_LIT:right>' ] <EOL> self . left_header . set ( l ) <EOL> self . center_header . set ( c ) <EOL> self . right_header . set ( r ) <EOL> def setFooter ( self , item ) : <EOL> matches = _split_string ( item ) <EOL> l = matches [ '<STR_LIT:left>' ] <EOL> c = matches [ '<STR_LIT>' ] <EOL> r = matches [ '<STR_LIT:right>' ] <EOL> self . left_footer . set ( l ) <EOL> self . center_footer . set ( c ) <EOL> self . right_footer . set ( r ) <EOL> import re <EOL> ITEM_REGEX = re . compile ( """<STR_LIT>""" , re . VERBOSE | re . DOTALL ) <EOL> from warnings import warn <EOL> def _split_string ( text ) : <EOL> """<STR_LIT>""" <EOL> m = ITEM_REGEX . match ( text ) <EOL> try : <EOL> parts = m . groupdict ( ) <EOL> except AttributeError : <EOL> warn ( """<STR_LIT>""" ) <EOL> parts = { '<STR_LIT:left>' : '<STR_LIT>' , '<STR_LIT:right>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> return parts <EOL> HEADER_REGEX = re . compile ( r"<STR_LIT>" ) <EOL> FONT_REGEX = re . compile ( '<STR_LIT>' ) <EOL> COLOR_REGEX = re . compile ( "<STR_LIT>" ) <EOL> SIZE_REGEX = re . compile ( r"<STR_LIT>" ) </s>
