Changeset 2549:7446d4d2cb5a in livinglogic.python.xist

Show
Ignore:
Timestamp:
06/08/06 18:50:37 (14 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Rename TreeLine? to Line.

Use repr() for outputting multiline strings.

Simplified formatting functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/presenters.py

    r2548 r2549  
    4040 
    4141# style to be used for tabs 
    42 s4tab = astyle.Style.fromenv("LL_XIST_REPRANSI_TAB", "black:black:bold") 
     42s4tab = astyle.Style.fromenv("LL_XIST_STYLE_TAB", "black:black:bold") 
    4343 
    4444 
    4545# style to be used for quotes (delimiters for text and attribute nodes) 
    46 s4quote = astyle.Style.fromenv("LL_XIST_REPRANSI_QUOTE", "white:black:bold") 
     46s4quote = astyle.Style.fromenv("LL_XIST_STYLE_QUOTE", "white:black:bold") 
    4747 
    4848 
    4949# style to be used for text 
    50 s4text = astyle.Style.fromenv("LL_XIST_REPRANSI_TEXT", "white:black") 
     50s4text = astyle.Style.fromenv("LL_XIST_STYLE_TEXT", "white:black") 
    5151 
    5252 
    5353# style to be used for namespaces 
    54 s4ns = astyle.Style.fromenv("LL_XIST_REPRANSI_NAMESPACE", "blue:black") 
     54s4ns = astyle.Style.fromenv("LL_XIST_STYLE_NAMESPACE", "blue:black") 
    5555 
    5656 
    5757# style to be used for Null object 
    58 s4null = astyle.Style.fromenv("LL_XIST_REPRANSI_NULL", "white:black:bold") 
     58s4null = astyle.Style.fromenv("LL_XIST_STYLE_NULL", "white:black:bold") 
    5959 
    6060 
    6161# style to be used for Null name 
    62 s4nullname = astyle.Style.fromenv("LL_XIST_REPRANSI_NULLNAME", "white:black:bold") 
     62s4nullname = astyle.Style.fromenv("LL_XIST_STYLE_NULLNAME", "white:black:bold") 
    6363 
    6464 
    6565# style to be used a Frag object 
    66 s4frag = astyle.Style.fromenv("LL_XIST_REPRANSI_FRAG", "white:black:bold") 
     66s4frag = astyle.Style.fromenv("LL_XIST_STYLE_FRAG", "white:black:bold") 
    6767 
    6868 
    6969# style to be used for Frag name 
    70 s4fragname = astyle.Style.fromenv("LL_XIST_REPRANSI_FRAGNAME", "white:black:bold") 
     70s4fragname = astyle.Style.fromenv("LL_XIST_STYLE_FRAGNAME", "white:black:bold") 
    7171 
    7272 
    7373# style to be used for elements (i.e. the <, > and / characters 
    74 s4element = astyle.Style.fromenv("LL_XIST_REPRANSI_ELEMENT", "white:black:bold") 
     74s4element = astyle.Style.fromenv("LL_XIST_STYLE_ELEMENT", "white:black:bold") 
    7575 
    7676 
    7777# style to be used for element names 
    78 s4elementname = astyle.Style.fromenv("LL_XIST_REPRANSI_ELEMENTNAME", "blue:black:bold") 
     78s4elementname = astyle.Style.fromenv("LL_XIST_STYLE_ELEMENTNAME", "blue:black:bold") 
    7979 
    8080 
    8181# style to be used for processing instructions 
    82 s4procinst = astyle.Style.fromenv("LL_XIST_REPRANSI_PROCINST", "red:black:bold") 
     82s4procinst = astyle.Style.fromenv("LL_XIST_STYLE_PROCINST", "red:black:bold") 
    8383 
    8484 
    8585# style to be used for processing instruction targets 
    86 s4procinsttarget = astyle.Style.fromenv("LL_XIST_REPRANSI_PROCINSTTARGET", "red:black:bold") 
     86s4procinsttarget = astyle.Style.fromenv("LL_XIST_STYLE_PROCINSTTARGET", "red:black:bold") 
    8787 
    8888 
    8989# style to be used for processing instruction content 
    90 s4procinstcontent = astyle.Style.fromenv("LL_XIST_REPRANSI_PROCINSTCONTENT", "white:black") 
     90s4procinstcontent = astyle.Style.fromenv("LL_XIST_STYLE_PROCINSTCONTENT", "white:black") 
    9191 
    9292 
    9393# style to be used for attributes (i.e. the quotes around their value) 
    94 s4attr = astyle.Style.fromenv("LL_XIST_REPRANSI_ATTR", "blue:black:bold") 
     94s4attr = astyle.Style.fromenv("LL_XIST_STYLE_ATTR", "blue:black:bold") 
    9595 
    9696 
    9797# style to be used for attribute names 
    98 s4attrname = astyle.Style.fromenv("LL_XIST_REPRANSI_ATTRNAME", "blue:black:bold") 
     98s4attrname = astyle.Style.fromenv("LL_XIST_STYLE_ATTRNAME", "blue:black:bold") 
    9999 
    100100 
    101101# style to be used for attrs class name 
    102 s4attrs = astyle.Style.fromenv("LL_XIST_REPRANSI_ATTRS", "blue:black:bold") 
     102s4attrs = astyle.Style.fromenv("LL_XIST_STYLE_ATTRS", "blue:black:bold") 
    103103 
    104104 
    105105# style to be used for attrs class name 
    106 s4attrsname = astyle.Style.fromenv("LL_XIST_REPRANSI_ATTRSNAME", "blue:black:bold") 
     106s4attrsname = astyle.Style.fromenv("LL_XIST_STYLE_ATTRSNAME", "blue:black:bold") 
    107107 
    108108 
    109109# style to be used for entities 
    110 s4entity = astyle.Style.fromenv("LL_XIST_REPRANSI_ENTITY", "magenta:black") 
     110s4entity = astyle.Style.fromenv("LL_XIST_STYLE_ENTITY", "magenta:black") 
    111111 
    112112 
    113113# style to be used for entity names 
    114 s4entityname = astyle.Style.fromenv("LL_XIST_REPRANSI_ENTITYNAME", "magenta:black") 
     114s4entityname = astyle.Style.fromenv("LL_XIST_STYLE_ENTITYNAME", "magenta:black") 
    115115 
    116116 
    117117# style to be used for charref names or codepoints 
    118 s4charrefname = astyle.Style.fromenv("LL_XIST_REPRANSI_CHARREFNAME", "magenta:black") 
     118s4charrefname = astyle.Style.fromenv("LL_XIST_STYLE_CHARREFNAME", "magenta:black") 
    119119 
    120120 
    121121# style to be used for document types 
    122 s4doctype = astyle.Style.fromenv("LL_XIST_REPRANSI_DOCTYPE", "white:black:bold") 
     122s4doctype = astyle.Style.fromenv("LL_XIST_STYLE_DOCTYPE", "white:black:bold") 
    123123 
    124124 
    125125# style to be used for document types 
    126 s4doctypetext = astyle.Style.fromenv("LL_XIST_REPRANSI_DOCTYPETEXT", "white:black:bold") 
     126s4doctypetext = astyle.Style.fromenv("LL_XIST_STYLE_DOCTYPETEXT", "white:black:bold") 
    127127 
    128128 
    129129# style to be used for comment (i.e. <!-- and -->) 
    130 s4comment = astyle.Style.fromenv("LL_XIST_REPRANSI_COMMENT", "black:black:bold") 
     130s4comment = astyle.Style.fromenv("LL_XIST_STYLE_COMMENT", "black:black:bold") 
    131131 
    132132 
    133133# style to be used for comment text 
    134 s4commenttext = astyle.Style.fromenv("LL_XIST_REPRANSI_COMMENTTEXT", "black:black:bold") 
     134s4commenttext = astyle.Style.fromenv("LL_XIST_STYLE_COMMENTTEXT", "black:black:bold") 
    135135 
    136136 
    137137# style to be used for attribute values 
    138 s4attrvalue = astyle.Style.fromenv("LL_XIST_REPRANSI_ATTRVALUE", "yellow:black") 
     138s4attrvalue = astyle.Style.fromenv("LL_XIST_STYLE_ATTRVALUE", "yellow:black") 
    139139 
    140140 
    141141# style to be used for URLs 
    142 s4url = astyle.Style.fromenv("LL_XIST_REPRANSI_URL", "green:black") 
     142s4url = astyle.Style.fromenv("LL_XIST_STYLE_URL", "green:black") 
    143143 
    144144 
    145145# style to be used for numbers in error messages etc. 
    146 s4number = astyle.Style.fromenv("LL_XIST_REPRANSI_NUMBER", "blue:black") 
     146s4number = astyle.Style.fromenv("LL_XIST_STYLE_NUMBER", "blue:black") 
    147147 
    148148 
    149149# style to be used for variable strings in error messages etc. 
    150 s4string = astyle.Style.fromenv("LL_XIST_REPRANSI_STRING", "magenta:black") 
     150s4string = astyle.Style.fromenv("LL_XIST_STYLE_STRING", "magenta:black") 
    151151 
    152152 
    153153# style to be used for IDs in repr() 
    154 s4id = astyle.Style.fromenv("LL_XIST_REPRANSI_ID", "yellow:black") 
     154s4id = astyle.Style.fromenv("LL_XIST_STYLE_ID", "yellow:black") 
    155155 
    156156 
     
    232232 
    233233 
    234 def strTextInAttr(text): 
    235     return s4attrvalue(text) 
     234def strtext(text): 
     235    return s4text(s4quote(u'"'), text, s4quote(u'"')) 
    236236 
    237237 
     
    384384 
    385385 
    386 class TreeLine(object): 
     386class Line(object): 
    387387    __slots__ = ("loc", "path", "content", "node") 
    388388 
     
    407407    """ 
    408408 
    409     def __init__(self, node, indent="\t"): 
     409    def __init__(self, node, indent=None): 
    410410        Presenter.__init__(self, node) 
     411        if indent is None: 
     412            indent = os.environ.get("LL_XIST_INDENT", "\t") 
    411413        self.indent = indent 
    412414 
     
    417419        indent = self.indent 
    418420        if indent == "\t": 
    419             indent = "|--" 
     421            indent = "   " 
    420422        return s4tab(level*indent) 
    421423 
     
    450452                s = s.lstrip(u"\t") 
    451453                mynest += len(s)-oldlen 
    452             s = formatter(s) 
     454            s = formatter(repr(s)[2:-1]) 
    453455            if i == 0 and head is not None: # prepend head to first line 
    454456                s = head + s 
    455457            if i >= l-1 and tail is not None: # append tail to last line 
    456458                s = s + tail 
    457             yield TreeLine(hereloc, self._currentpath[:], self.strindent(mynest) + s, node) 
    458  
    459     def strTextLineOutsideAttr(self, text): 
    460         return s4text(s4quote(u'"'), text, s4quote(u'"')) 
    461  
    462     def strTextInAttr(self, text): 
    463         return s4attrvalue(text) 
    464  
    465     def strProcInstContentLine(self, text): 
    466         return s4procinstcontent(text) 
    467  
    468     def strCommentTextLine(self, text): 
    469         return s4commenttext(text) 
    470  
    471     def strDocTypeTextLine(self, text): 
    472         return s4doctypetext(text) 
     459            yield Line(hereloc, self._currentpath[:], self.strindent(mynest) + s, node) 
    473460 
    474461    def presentFrag(self, node): 
     
    479466        else: 
    480467            if len(node): 
    481                 yield TreeLine( 
     468                yield Line( 
    482469                    node.startloc, 
    483470                    self._currentpath[:], 
     
    496483                    self._currentpath[-1] += 1 
    497484                self._currentpath.pop(-1) 
    498                 yield TreeLine( 
     485                yield Line( 
    499486                    node.endloc, 
    500487                    self._currentpath[:], 
     
    508495                ) 
    509496            else: 
    510                 yield TreeLine( 
     497                yield Line( 
    511498                    node.startloc, 
    512499                    self._currentpath[:], 
     
    582569            if len(node): 
    583570                self._buffers[-1] += s4element(u">") 
    584                 yield TreeLine( 
     571                yield Line( 
    585572                    node.startloc, 
    586573                    self._currentpath[:], 
     
    598585                    self._currentpath[-1] += 1 
    599586                self._currentpath.pop() 
    600                 yield TreeLine( 
     587                yield Line( 
    601588                    node.endloc, 
    602589                    self._currentpath[:], 
     
    611598            else: 
    612599                self._buffers[-1] += s4element(u"/>") 
    613                 yield TreeLine( 
     600                yield Line( 
    614601                    node.startloc, 
    615602                    self._currentpath[:], 
     
    624611    def presentNull(self, node): 
    625612        if not self._inattr: 
    626             yield TreeLine( 
     613            yield Line( 
    627614                node.startloc, 
    628615                self._currentpath[:], 
     
    636623    def presentText(self, node): 
    637624        if self._inattr: 
    638             self._buffers[-1] += strTextInAttr(node.content) 
     625            self._buffers[-1] += s4attrvalue(node.content) 
    639626        else: 
    640627            lines = node.content.splitlines(True) 
    641             for line in self._domultiline(node, lines, 0, self.strTextLineOutsideAttr): 
     628            for line in self._domultiline(node, lines, 0, strtext): 
    642629                yield line 
    643630 
     
    646633            self._buffers[-1].append(node._str(fullname=True, xml=False, decorate=True)) 
    647634        else: 
    648             yield TreeLine( 
     635            yield Line( 
    649636                node.startloc, 
    650637                self._currentpath[:], 
     
    671658            if len(lines)>1: 
    672659                lines.insert(0, u"") 
    673             for line in self._domultiline(node, lines, 1, self.strProcInstContentLine, head, tail): 
     660            for line in self._domultiline(node, lines, 1, s4procinstcontent, head, tail): 
    674661                yield line 
    675662 
     
    685672            tail = s4comment(u"-->") 
    686673            lines = node.content.splitlines() 
    687             for line in self._domultiline(node, lines, 1, self.strCommentTextLine, head, tail): 
     674            for line in self._domultiline(node, lines, 1, s4commenttext, head, tail): 
    688675                yield line 
    689676 
     
    699686            tail = s4doctype(u">") 
    700687            lines = node.content.splitlines() 
    701             for line in self._domultiline(node, lines, 1, self.strDocTypeTextLine, head, tail): 
     688            for line in self._domultiline(node, lines, 1, s4doctypetext, head, tail): 
    702689                yield line 
    703690 
     
    717704    constructor calls.</par> 
    718705    """ 
    719     def __init__(self, node, indent="\t"): 
     706    def __init__(self, node, indent=None): 
    720707        Presenter.__init__(self, node) 
     708        if indent is None: 
     709            indent = os.environ.get("LL_XIST_INDENT", "\t") 
    721710        self.indent = indent 
    722711