<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import sys <EOL> import os <EOL> import re <EOL> import warnings <EOL> import types <EOL> import unicodedata <EOL> class Node ( object ) : <EOL> """<STR_LIT>""" <EOL> parent = None <EOL> """<STR_LIT>""" <EOL> document = None <EOL> """<STR_LIT>""" <EOL> source = None <EOL> """<STR_LIT>""" <EOL> line = None <EOL> """<STR_LIT>""" <EOL> def __bool__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> def __str__ ( self ) : <EOL> return str ( self ) . encode ( '<STR_LIT>' ) <EOL> def asdom ( self , dom = None ) : <EOL> """<STR_LIT>""" <EOL> if dom is None : <EOL> import xml . dom . minidom as dom <EOL> domroot = dom . Document ( ) <EOL> return self . _dom_node ( domroot ) <EOL> def pformat ( self , indent = '<STR_LIT:U+0020>' , level = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def deepcopy ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def setup_child ( self , child ) : <EOL> child . parent = self <EOL> if self . document : <EOL> child . document = self . document <EOL> if child . source is None : <EOL> child . source = self . document . current_source <EOL> if child . line is None : <EOL> child . line = self . document . current_line <EOL> def walk ( self , visitor ) : <EOL> """<STR_LIT>""" <EOL> stop = False <EOL> visitor . document . reporter . debug ( <EOL> '<STR_LIT>' <EOL> % self . __class__ . __name__ ) <EOL> try : <EOL> try : <EOL> visitor . dispatch_visit ( self ) <EOL> except ( SkipChildren , SkipNode ) : <EOL> return stop <EOL> except SkipDeparture : <EOL> pass <EOL> children = self . children <EOL> try : <EOL> for child in children [ : ] : <EOL> if child . walk ( visitor ) : <EOL> stop = True <EOL> break <EOL> except SkipSiblings : <EOL> pass <EOL> except StopTraversal : <EOL> stop = True <EOL> return stop <EOL> def walkabout ( self , visitor ) : <EOL> """<STR_LIT>""" <EOL> call_depart = True <EOL> stop = False <EOL> visitor . document . reporter . debug ( <EOL> '<STR_LIT>' <EOL> % self . __class__ . __name__ ) <EOL> try : <EOL> try : <EOL> visitor . dispatch_visit ( self ) <EOL> except SkipNode : <EOL> return stop <EOL> except SkipDeparture : <EOL> call_depart = False <EOL> children = self . children <EOL> try : <EOL> for child in children [ : ] : <EOL> if child . walkabout ( visitor ) : <EOL> stop = True <EOL> break <EOL> except SkipSiblings : <EOL> pass <EOL> except SkipChildren : <EOL> pass <EOL> except StopTraversal : <EOL> stop = True <EOL> if call_depart : <EOL> visitor . document . reporter . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % self . __class__ . __name__ ) <EOL> visitor . dispatch_departure ( self ) <EOL> return stop <EOL> def _fast_traverse ( self , cls ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> if isinstance ( self , cls ) : <EOL> result . append ( self ) <EOL> for child in self . children : <EOL> result . extend ( child . _fast_traverse ( cls ) ) <EOL> return result <EOL> def _all_traverse ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> result . append ( self ) <EOL> for child in self . children : <EOL> result . extend ( child . _all_traverse ( ) ) <EOL> return result <EOL> def traverse ( self , condition = None , include_self = True , descend = True , <EOL> siblings = False , ascend = False ) : <EOL> """<STR_LIT>""" <EOL> if ascend : <EOL> siblings = True <EOL> if include_self and descend and not siblings : <EOL> if condition is None : <EOL> return self . _all_traverse ( ) <EOL> elif isinstance ( condition , type ) : <EOL> return self . _fast_traverse ( condition ) <EOL> if isinstance ( condition , type ) : <EOL> node_class = condition <EOL> def condition ( node , node_class = node_class ) : <EOL> return isinstance ( node , node_class ) <EOL> r = [ ] <EOL> if include_self and ( condition is None or condition ( self ) ) : <EOL> r . append ( self ) <EOL> if descend and len ( self . children ) : <EOL> for child in self : <EOL> r . extend ( child . traverse ( include_self = True , descend = True , <EOL> siblings = False , ascend = False , <EOL> condition = condition ) ) <EOL> if siblings or ascend : <EOL> node = self <EOL> while node . parent : <EOL> index = node . parent . index ( node ) <EOL> for sibling in node . parent [ index + <NUM_LIT:1> : ] : <EOL> r . extend ( sibling . traverse ( include_self = True , <EOL> descend = descend , <EOL> siblings = False , ascend = False , <EOL> condition = condition ) ) <EOL> if not ascend : <EOL> break <EOL> else : <EOL> node = node . parent <EOL> return r <EOL> def next_node ( self , condition = None , include_self = False , descend = True , <EOL> siblings = False , ascend = False ) : <EOL> """<STR_LIT>""" <EOL> iterable = self . traverse ( condition = condition , <EOL> include_self = include_self , descend = descend , <EOL> siblings = siblings , ascend = ascend ) <EOL> try : <EOL> return iterable [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> return None <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> class reprunicode ( str ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return str . __repr__ ( self ) [ <NUM_LIT:1> : ] <EOL> else : <EOL> reprunicode = str <EOL> def ensure_str ( s ) : <EOL> """<STR_LIT>""" <EOL> if sys . version_info < ( <NUM_LIT:3> , ) and isinstance ( s , str ) : <EOL> return s . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) <EOL> return s <EOL> class Text ( Node , reprunicode ) : <EOL> """<STR_LIT>""" <EOL> tagname = '<STR_LIT>' <EOL> children = ( ) <EOL> """<STR_LIT>""" <EOL> if sys . version_info > ( <NUM_LIT:3> , ) : <EOL> def __new__ ( cls , data , rawsource = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( data , bytes ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return reprunicode . __new__ ( cls , data ) <EOL> else : <EOL> def __new__ ( cls , data , rawsource = None ) : <EOL> """<STR_LIT>""" <EOL> return reprunicode . __new__ ( cls , data ) <EOL> def __init__ ( self , data , rawsource = '<STR_LIT>' ) : <EOL> self . rawsource = rawsource <EOL> """<STR_LIT>""" <EOL> def shortrepr ( self , maxlen = <NUM_LIT> ) : <EOL> data = self <EOL> if len ( data ) > maxlen : <EOL> data = data [ : maxlen - <NUM_LIT:4> ] + '<STR_LIT>' <EOL> return '<STR_LIT>' % ( self . tagname , reprunicode ( data ) ) <EOL> def __repr__ ( self ) : <EOL> return self . shortrepr ( maxlen = <NUM_LIT> ) <EOL> def _dom_node ( self , domroot ) : <EOL> return domroot . createTextNode ( str ( self ) ) <EOL> def astext ( self ) : <EOL> return reprunicode ( self ) <EOL> def copy ( self ) : <EOL> return self . __class__ ( reprunicode ( self ) , rawsource = self . rawsource ) <EOL> def deepcopy ( self ) : <EOL> return self . copy ( ) <EOL> def pformat ( self , indent = '<STR_LIT:U+0020>' , level = <NUM_LIT:0> ) : <EOL> result = [ ] <EOL> indent = indent * level <EOL> for line in self . splitlines ( ) : <EOL> result . append ( indent + line + '<STR_LIT:\n>' ) <EOL> return '<STR_LIT>' . join ( result ) <EOL> def rstrip ( self , chars = None ) : <EOL> return self . __class__ ( reprunicode . rstrip ( self , chars ) ) <EOL> def lstrip ( self , chars = None ) : <EOL> return self . __class__ ( reprunicode . lstrip ( self , chars ) ) <EOL> class Element ( Node ) : <EOL> """<STR_LIT>""" <EOL> basic_attributes = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> local_attributes = ( '<STR_LIT>' , ) <EOL> """<STR_LIT>""" <EOL> list_attributes = basic_attributes + local_attributes <EOL> """<STR_LIT>""" <EOL> known_attributes = list_attributes + ( '<STR_LIT:source>' , ) <EOL> """<STR_LIT>""" <EOL> tagname = None <EOL> """<STR_LIT>""" <EOL> child_text_separator = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rawsource = '<STR_LIT>' , * children , ** attributes ) : <EOL> self . rawsource = rawsource <EOL> """<STR_LIT>""" <EOL> self . children = [ ] <EOL> """<STR_LIT>""" <EOL> self . extend ( children ) <EOL> self . attributes = { } <EOL> """<STR_LIT>""" <EOL> for att in self . list_attributes : <EOL> self . attributes [ att ] = [ ] <EOL> for att , value in list ( attributes . items ( ) ) : <EOL> att = att . lower ( ) <EOL> if att in self . list_attributes : <EOL> self . attributes [ att ] = value [ : ] <EOL> else : <EOL> self . attributes [ att ] = value <EOL> if self . tagname is None : <EOL> self . tagname = self . __class__ . __name__ <EOL> def _dom_node ( self , domroot ) : <EOL> element = domroot . createElement ( self . tagname ) <EOL> for attribute , value in self . attlist ( ) : <EOL> if isinstance ( value , list ) : <EOL> value = '<STR_LIT:U+0020>' . join ( [ serial_escape ( '<STR_LIT:%s>' % ( v , ) ) for v in value ] ) <EOL> element . setAttribute ( attribute , '<STR_LIT:%s>' % value ) <EOL> for child in self . children : <EOL> element . appendChild ( child . _dom_node ( domroot ) ) <EOL> return element <EOL> def __repr__ ( self ) : <EOL> data = '<STR_LIT>' <EOL> for c in self . children : <EOL> data += c . shortrepr ( ) <EOL> if len ( data ) > <NUM_LIT> : <EOL> data = data [ : <NUM_LIT> ] + '<STR_LIT>' <EOL> break <EOL> if self [ '<STR_LIT>' ] : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , <EOL> '<STR_LIT>' . join ( [ ensure_str ( n ) for n in self [ '<STR_LIT>' ] ] ) , data ) <EOL> else : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , data ) <EOL> def shortrepr ( self ) : <EOL> if self [ '<STR_LIT>' ] : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , <EOL> '<STR_LIT>' . join ( [ ensure_str ( n ) for n in self [ '<STR_LIT>' ] ] ) ) <EOL> else : <EOL> return '<STR_LIT>' % self . tagname <EOL> def __unicode__ ( self ) : <EOL> if self . children : <EOL> return '<STR_LIT>' % ( self . starttag ( ) , <EOL> '<STR_LIT>' . join ( [ str ( c ) for c in self . children ] ) , <EOL> self . endtag ( ) ) <EOL> else : <EOL> return self . emptytag ( ) <EOL> if sys . version_info > ( <NUM_LIT:3> , ) : <EOL> __str__ = __unicode__ <EOL> def starttag ( self , quoteattr = None ) : <EOL> if quoteattr is None : <EOL> quoteattr = pseudo_quoteattr <EOL> parts = [ self . tagname ] <EOL> for name , value in self . attlist ( ) : <EOL> if value is None : <EOL> parts . append ( name ) <EOL> continue <EOL> if isinstance ( value , list ) : <EOL> values = [ serial_escape ( '<STR_LIT:%s>' % ( v , ) ) for v in value ] <EOL> value = '<STR_LIT:U+0020>' . join ( values ) <EOL> else : <EOL> value = str ( value ) <EOL> value = quoteattr ( value ) <EOL> parts . append ( '<STR_LIT>' % ( name , value ) ) <EOL> return '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( parts ) <EOL> def endtag ( self ) : <EOL> return '<STR_LIT>' % self . tagname <EOL> def emptytag ( self ) : <EOL> return '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( [ self . tagname ] + <EOL> [ '<STR_LIT>' % ( n , v ) <EOL> for n , v in self . attlist ( ) ] ) <EOL> def __len__ ( self ) : <EOL> return len ( self . children ) <EOL> def __contains__ ( self , key ) : <EOL> if isinstance ( key , str ) : <EOL> return key in self . attributes <EOL> return key in self . children <EOL> def __getitem__ ( self , key ) : <EOL> if isinstance ( key , str ) : <EOL> return self . attributes [ key ] <EOL> elif isinstance ( key , int ) : <EOL> return self . children [ key ] <EOL> elif isinstance ( key , slice ) : <EOL> assert key . step in ( None , <NUM_LIT:1> ) , '<STR_LIT>' <EOL> return self . children [ key . start : key . stop ] <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def __setitem__ ( self , key , item ) : <EOL> if isinstance ( key , str ) : <EOL> self . attributes [ str ( key ) ] = item <EOL> elif isinstance ( key , int ) : <EOL> self . setup_child ( item ) <EOL> self . children [ key ] = item <EOL> elif isinstance ( key , slice ) : <EOL> assert key . step in ( None , <NUM_LIT:1> ) , '<STR_LIT>' <EOL> for node in item : <EOL> self . setup_child ( node ) <EOL> self . children [ key . start : key . stop ] = item <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def __delitem__ ( self , key ) : <EOL> if isinstance ( key , str ) : <EOL> del self . attributes [ key ] <EOL> elif isinstance ( key , int ) : <EOL> del self . children [ key ] <EOL> elif isinstance ( key , slice ) : <EOL> assert key . step in ( None , <NUM_LIT:1> ) , '<STR_LIT>' <EOL> del self . children [ key . start : key . stop ] <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def __add__ ( self , other ) : <EOL> return self . children + other <EOL> def __radd__ ( self , other ) : <EOL> return other + self . children <EOL> def __iadd__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , Node ) : <EOL> self . append ( other ) <EOL> elif other is not None : <EOL> self . extend ( other ) <EOL> return self <EOL> def astext ( self ) : <EOL> return self . child_text_separator . join ( <EOL> [ child . astext ( ) for child in self . children ] ) <EOL> def non_default_attributes ( self ) : <EOL> atts = { } <EOL> for key , value in list ( self . attributes . items ( ) ) : <EOL> if self . is_not_default ( key ) : <EOL> atts [ key ] = value <EOL> return atts <EOL> def attlist ( self ) : <EOL> attlist = list ( self . non_default_attributes ( ) . items ( ) ) <EOL> attlist . sort ( ) <EOL> return attlist <EOL> def get ( self , key , failobj = None ) : <EOL> return self . attributes . get ( key , failobj ) <EOL> def hasattr ( self , attr ) : <EOL> return attr in self . attributes <EOL> def delattr ( self , attr ) : <EOL> if attr in self . attributes : <EOL> del self . attributes [ attr ] <EOL> def setdefault ( self , key , failobj = None ) : <EOL> return self . attributes . setdefault ( key , failobj ) <EOL> has_key = hasattr <EOL> __contains__ = hasattr <EOL> def get_language_code ( self , fallback = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> for cls in self . get ( '<STR_LIT>' , [ ] ) : <EOL> if cls . startswith ( '<STR_LIT>' ) : <EOL> return cls [ <NUM_LIT:9> : ] <EOL> try : <EOL> return self . parent . get_language ( fallback ) <EOL> except AttributeError : <EOL> return fallback <EOL> def append ( self , item ) : <EOL> self . setup_child ( item ) <EOL> self . children . append ( item ) <EOL> def extend ( self , item ) : <EOL> for node in item : <EOL> self . append ( node ) <EOL> def insert ( self , index , item ) : <EOL> if isinstance ( item , Node ) : <EOL> self . setup_child ( item ) <EOL> self . children . insert ( index , item ) <EOL> elif item is not None : <EOL> self [ index : index ] = item <EOL> def pop ( self , i = - <NUM_LIT:1> ) : <EOL> return self . children . pop ( i ) <EOL> def remove ( self , item ) : <EOL> self . children . remove ( item ) <EOL> def index ( self , item ) : <EOL> return self . children . index ( item ) <EOL> def is_not_default ( self , key ) : <EOL> if self [ key ] == [ ] and key in self . list_attributes : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> def update_basic_atts ( self , dict_ ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( dict_ , Node ) : <EOL> dict_ = dict_ . attributes <EOL> for att in self . basic_attributes : <EOL> self . append_attr_list ( att , dict_ . get ( att , [ ] ) ) <EOL> def append_attr_list ( self , attr , values ) : <EOL> """<STR_LIT>""" <EOL> for value in values : <EOL> if not value in self [ attr ] : <EOL> self [ attr ] . append ( value ) <EOL> def coerce_append_attr_list ( self , attr , value ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self . get ( attr ) , list ) : <EOL> self [ attr ] = [ self [ attr ] ] <EOL> if not isinstance ( value , list ) : <EOL> value = [ value ] <EOL> self . append_attr_list ( attr , value ) <EOL> def replace_attr ( self , attr , value , force = True ) : <EOL> """<STR_LIT>""" <EOL> if force or self . get ( attr ) is None : <EOL> self [ attr ] = value <EOL> def copy_attr_convert ( self , attr , value , replace = True ) : <EOL> """<STR_LIT>""" <EOL> if self . get ( attr ) is not value : <EOL> self . coerce_append_attr_list ( attr , value ) <EOL> def copy_attr_coerce ( self , attr , value , replace ) : <EOL> """<STR_LIT>""" <EOL> if self . get ( attr ) is not value : <EOL> if isinstance ( self . get ( attr ) , list ) or isinstance ( value , list ) : <EOL> self . coerce_append_attr_list ( attr , value ) <EOL> else : <EOL> self . replace_attr ( attr , value , replace ) <EOL> def copy_attr_concatenate ( self , attr , value , replace ) : <EOL> """<STR_LIT>""" <EOL> if self . get ( attr ) is not value : <EOL> if isinstance ( self . get ( attr ) , list ) and isinstance ( value , list ) : <EOL> self . append_attr_list ( attr , value ) <EOL> else : <EOL> self . replace_attr ( attr , value , replace ) <EOL> def copy_attr_consistent ( self , attr , value , replace ) : <EOL> """<STR_LIT>""" <EOL> if self . get ( attr ) is not value : <EOL> self . replace_attr ( attr , value , replace ) <EOL> def update_all_atts ( self , dict_ , update_fun = copy_attr_consistent , <EOL> replace = True , and_source = False ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( dict_ , Node ) : <EOL> dict_ = dict_ . attributes <EOL> if and_source : <EOL> filter_fun = self . is_not_list_attribute <EOL> else : <EOL> filter_fun = self . is_not_known_attribute <EOL> self . update_basic_atts ( dict_ ) <EOL> for att in filter ( filter_fun , dict_ ) : <EOL> update_fun ( self , att , dict_ [ att ] , replace ) <EOL> def update_all_atts_consistantly ( self , dict_ , replace = True , <EOL> and_source = False ) : <EOL> """<STR_LIT>""" <EOL> self . update_all_atts ( dict_ , Element . copy_attr_consistent , replace , <EOL> and_source ) <EOL> def update_all_atts_concatenating ( self , dict_ , replace = True , <EOL> and_source = False ) : <EOL> """<STR_LIT>""" <EOL> self . update_all_atts ( dict_ , Element . copy_attr_concatenate , replace , <EOL> and_source ) <EOL> def update_all_atts_coercion ( self , dict_ , replace = True , <EOL> and_source = False ) : <EOL> """<STR_LIT>""" <EOL> self . update_all_atts ( dict_ , Element . copy_attr_coerce , replace , <EOL> and_source ) <EOL> def update_all_atts_convert ( self , dict_ , and_source = False ) : <EOL> """<STR_LIT>""" <EOL> self . update_all_atts ( dict_ , Element . copy_attr_convert , <EOL> and_source = and_source ) <EOL> def clear ( self ) : <EOL> self . children = [ ] <EOL> def replace ( self , old , new ) : <EOL> """<STR_LIT>""" <EOL> index = self . index ( old ) <EOL> if isinstance ( new , Node ) : <EOL> self . setup_child ( new ) <EOL> self [ index ] = new <EOL> elif new is not None : <EOL> self [ index : index + <NUM_LIT:1> ] = new <EOL> def replace_self ( self , new ) : <EOL> """<STR_LIT>""" <EOL> update = new <EOL> if not isinstance ( new , Node ) : <EOL> try : <EOL> update = new [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> update = None <EOL> if isinstance ( update , Element ) : <EOL> update . update_basic_atts ( self ) <EOL> else : <EOL> for att in self . basic_attributes : <EOL> assert not self [ att ] , '<STR_LIT>' % ( att , self [ att ] ) <EOL> self . parent . replace ( self , new ) <EOL> def first_child_matching_class ( self , childclass , start = <NUM_LIT:0> , end = sys . maxsize ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( childclass , tuple ) : <EOL> childclass = ( childclass , ) <EOL> for index in range ( start , min ( len ( self ) , end ) ) : <EOL> for c in childclass : <EOL> if isinstance ( self [ index ] , c ) : <EOL> return index <EOL> return None <EOL> def first_child_not_matching_class ( self , childclass , start = <NUM_LIT:0> , <EOL> end = sys . maxsize ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( childclass , tuple ) : <EOL> childclass = ( childclass , ) <EOL> for index in range ( start , min ( len ( self ) , end ) ) : <EOL> for c in childclass : <EOL> if isinstance ( self . children [ index ] , c ) : <EOL> break <EOL> else : <EOL> return index <EOL> return None <EOL> def pformat ( self , indent = '<STR_LIT:U+0020>' , level = <NUM_LIT:0> ) : <EOL> return '<STR_LIT>' . join ( [ '<STR_LIT>' % ( indent * level , self . starttag ( ) ) ] + <EOL> [ child . pformat ( indent , level + <NUM_LIT:1> ) <EOL> for child in self . children ] ) <EOL> def copy ( self ) : <EOL> return self . __class__ ( rawsource = self . rawsource , ** self . attributes ) <EOL> def deepcopy ( self ) : <EOL> copy = self . copy ( ) <EOL> copy . extend ( [ child . deepcopy ( ) for child in self . children ] ) <EOL> return copy <EOL> def set_class ( self , name ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( '<STR_LIT>' <EOL> "<STR_LIT>" , <EOL> DeprecationWarning , stacklevel = <NUM_LIT:2> ) <EOL> assert '<STR_LIT:U+0020>' not in name <EOL> self [ '<STR_LIT>' ] . append ( name . lower ( ) ) <EOL> def note_referenced_by ( self , name = None , id = None ) : <EOL> """<STR_LIT>""" <EOL> self . referenced = <NUM_LIT:1> <EOL> by_name = getattr ( self , '<STR_LIT>' , { } ) . get ( name ) <EOL> by_id = getattr ( self , '<STR_LIT>' , { } ) . get ( id ) <EOL> if by_name : <EOL> assert name is not None <EOL> by_name . referenced = <NUM_LIT:1> <EOL> if by_id : <EOL> assert id is not None <EOL> by_id . referenced = <NUM_LIT:1> <EOL> @ classmethod <EOL> def is_not_list_attribute ( cls , attr ) : <EOL> """<STR_LIT>""" <EOL> return attr not in cls . list_attributes <EOL> @ classmethod <EOL> def is_not_known_attribute ( cls , attr ) : <EOL> """<STR_LIT>""" <EOL> return attr not in cls . known_attributes <EOL> class TextElement ( Element ) : <EOL> """<STR_LIT>""" <EOL> child_text_separator = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rawsource = '<STR_LIT>' , text = '<STR_LIT>' , * children , ** attributes ) : <EOL> if text != '<STR_LIT>' : <EOL> textnode = Text ( text ) <EOL> Element . __init__ ( self , rawsource , textnode , * children , <EOL> ** attributes ) <EOL> else : <EOL> Element . __init__ ( self , rawsource , * children , ** attributes ) <EOL> class FixedTextElement ( TextElement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rawsource = '<STR_LIT>' , text = '<STR_LIT>' , * children , ** attributes ) : <EOL> TextElement . __init__ ( self , rawsource , text , * children , ** attributes ) <EOL> self . attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> class Resolvable : <EOL> resolved = <NUM_LIT:0> <EOL> class BackLinkable : <EOL> def add_backref ( self , refid ) : <EOL> self [ '<STR_LIT>' ] . append ( refid ) <EOL> class Root : pass <EOL> class Titular : pass <EOL> class PreBibliographic : <EOL> """<STR_LIT>""" <EOL> class Bibliographic : pass <EOL> class Decorative ( PreBibliographic ) : pass <EOL> class Structural : pass <EOL> class Body : pass <EOL> class General ( Body ) : pass <EOL> class Sequential ( Body ) : <EOL> """<STR_LIT>""" <EOL> class Admonition ( Body ) : pass <EOL> class Special ( Body ) : <EOL> """<STR_LIT>""" <EOL> class Invisible ( PreBibliographic ) : <EOL> """<STR_LIT>""" <EOL> class Part : pass <EOL> class Inline : pass <EOL> class Referential ( Resolvable ) : pass <EOL> class Targetable ( Resolvable ) : <EOL> referenced = <NUM_LIT:0> <EOL> indirect_reference_name = None <EOL> """<STR_LIT>""" <EOL> class Labeled : <EOL> """<STR_LIT>""" <EOL> class document ( Root , Structural , Element ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , settings , reporter , * args , ** kwargs ) : <EOL> Element . __init__ ( self , * args , ** kwargs ) <EOL> self . current_source = None <EOL> """<STR_LIT>""" <EOL> self . current_line = None <EOL> """<STR_LIT>""" <EOL> self . settings = settings <EOL> """<STR_LIT>""" <EOL> self . reporter = reporter <EOL> """<STR_LIT>""" <EOL> self . indirect_targets = [ ] <EOL> """<STR_LIT>""" <EOL> self . substitution_defs = { } <EOL> """<STR_LIT>""" <EOL> self . substitution_names = { } <EOL> """<STR_LIT>""" <EOL> self . refnames = { } <EOL> """<STR_LIT>""" <EOL> self . refids = { } <EOL> """<STR_LIT>""" <EOL> self . nameids = { } <EOL> """<STR_LIT>""" <EOL> self . nametypes = { } <EOL> """<STR_LIT>""" <EOL> self . ids = { } <EOL> """<STR_LIT>""" <EOL> self . footnote_refs = { } <EOL> """<STR_LIT>""" <EOL> self . citation_refs = { } <EOL> """<STR_LIT>""" <EOL> self . autofootnotes = [ ] <EOL> """<STR_LIT>""" <EOL> self . autofootnote_refs = [ ] <EOL> """<STR_LIT>""" <EOL> self . symbol_footnotes = [ ] <EOL> """<STR_LIT>""" <EOL> self . symbol_footnote_refs = [ ] <EOL> """<STR_LIT>""" <EOL> self . footnotes = [ ] <EOL> """<STR_LIT>""" <EOL> self . citations = [ ] <EOL> """<STR_LIT>""" <EOL> self . autofootnote_start = <NUM_LIT:1> <EOL> """<STR_LIT>""" <EOL> self . symbol_footnote_start = <NUM_LIT:0> <EOL> """<STR_LIT>""" <EOL> self . id_start = <NUM_LIT:1> <EOL> """<STR_LIT>""" <EOL> self . parse_messages = [ ] <EOL> """<STR_LIT>""" <EOL> self . transform_messages = [ ] <EOL> """<STR_LIT>""" <EOL> import docutils . transforms <EOL> self . transformer = docutils . transforms . Transformer ( self ) <EOL> """<STR_LIT>""" <EOL> self . decoration = None <EOL> """<STR_LIT>""" <EOL> self . document = self <EOL> def __getstate__ ( self ) : <EOL> """<STR_LIT>""" <EOL> state = self . __dict__ . copy ( ) <EOL> state [ '<STR_LIT>' ] = None <EOL> state [ '<STR_LIT>' ] = None <EOL> return state <EOL> def asdom ( self , dom = None ) : <EOL> """<STR_LIT>""" <EOL> if dom is None : <EOL> import xml . dom . minidom as dom <EOL> domroot = dom . Document ( ) <EOL> domroot . appendChild ( self . _dom_node ( domroot ) ) <EOL> return domroot <EOL> def set_id ( self , node , msgnode = None ) : <EOL> for id in node [ '<STR_LIT>' ] : <EOL> if id in self . ids and self . ids [ id ] is not node : <EOL> msg = self . reporter . severe ( '<STR_LIT>' % id ) <EOL> if msgnode != None : <EOL> msgnode += msg <EOL> if not node [ '<STR_LIT>' ] : <EOL> for name in node [ '<STR_LIT>' ] : <EOL> id = self . settings . id_prefix + make_id ( name ) <EOL> if id and id not in self . ids : <EOL> break <EOL> else : <EOL> id = '<STR_LIT>' <EOL> while not id or id in self . ids : <EOL> id = ( self . settings . id_prefix + <EOL> self . settings . auto_id_prefix + str ( self . id_start ) ) <EOL> self . id_start += <NUM_LIT:1> <EOL> node [ '<STR_LIT>' ] . append ( id ) <EOL> self . ids [ id ] = node <EOL> return id <EOL> def set_name_id_map ( self , node , id , msgnode = None , explicit = None ) : <EOL> """<STR_LIT>""" <EOL> for name in node [ '<STR_LIT>' ] : <EOL> if name in self . nameids : <EOL> self . set_duplicate_name_id ( node , id , name , msgnode , explicit ) <EOL> else : <EOL> self . nameids [ name ] = id <EOL> self . nametypes [ name ] = explicit <EOL> def set_duplicate_name_id ( self , node , id , name , msgnode , explicit ) : <EOL> old_id = self . nameids [ name ] <EOL> old_explicit = self . nametypes [ name ] <EOL> self . nametypes [ name ] = old_explicit or explicit <EOL> if explicit : <EOL> if old_explicit : <EOL> level = <NUM_LIT:2> <EOL> if old_id is not None : <EOL> old_node = self . ids [ old_id ] <EOL> if '<STR_LIT>' in node : <EOL> refuri = node [ '<STR_LIT>' ] <EOL> if old_node [ '<STR_LIT>' ] and '<STR_LIT>' in old_node and old_node [ '<STR_LIT>' ] == refuri : <EOL> level = <NUM_LIT:1> <EOL> if level > <NUM_LIT:1> : <EOL> dupname ( old_node , name ) <EOL> self . nameids [ name ] = None <EOL> msg = self . reporter . system_message ( <EOL> level , '<STR_LIT>' % name , <EOL> backrefs = [ id ] , base_node = node ) <EOL> if msgnode != None : <EOL> msgnode += msg <EOL> dupname ( node , name ) <EOL> else : <EOL> self . nameids [ name ] = id <EOL> if old_id is not None : <EOL> old_node = self . ids [ old_id ] <EOL> dupname ( old_node , name ) <EOL> else : <EOL> if old_id is not None and not old_explicit : <EOL> self . nameids [ name ] = None <EOL> old_node = self . ids [ old_id ] <EOL> dupname ( old_node , name ) <EOL> dupname ( node , name ) <EOL> if not explicit or ( not old_explicit and old_id is not None ) : <EOL> msg = self . reporter . info ( <EOL> '<STR_LIT>' % name , <EOL> backrefs = [ id ] , base_node = node ) <EOL> if msgnode != None : <EOL> msgnode += msg <EOL> def has_name ( self , name ) : <EOL> return name in self . nameids <EOL> def note_implicit_target ( self , target , msgnode = None ) : <EOL> id = self . set_id ( target , msgnode ) <EOL> self . set_name_id_map ( target , id , msgnode , explicit = None ) <EOL> def note_explicit_target ( self , target , msgnode = None ) : <EOL> id = self . set_id ( target , msgnode ) <EOL> self . set_name_id_map ( target , id , msgnode , explicit = True ) <EOL> def note_refname ( self , node ) : <EOL> self . refnames . setdefault ( node [ '<STR_LIT>' ] , [ ] ) . append ( node ) <EOL> def note_refid ( self , node ) : <EOL> self . refids . setdefault ( node [ '<STR_LIT>' ] , [ ] ) . append ( node ) <EOL> def note_indirect_target ( self , target ) : <EOL> self . indirect_targets . append ( target ) <EOL> if target [ '<STR_LIT>' ] : <EOL> self . note_refname ( target ) <EOL> def note_anonymous_target ( self , target ) : <EOL> self . set_id ( target ) <EOL> def note_autofootnote ( self , footnote ) : <EOL> self . set_id ( footnote ) <EOL> self . autofootnotes . append ( footnote ) <EOL> def note_autofootnote_ref ( self , ref ) : <EOL> self . set_id ( ref ) <EOL> self . autofootnote_refs . append ( ref ) <EOL> def note_symbol_footnote ( self , footnote ) : <EOL> self . set_id ( footnote ) <EOL> self . symbol_footnotes . append ( footnote ) <EOL> def note_symbol_footnote_ref ( self , ref ) : <EOL> self . set_id ( ref ) <EOL> self . symbol_footnote_refs . append ( ref ) <EOL> def note_footnote ( self , footnote ) : <EOL> self . set_id ( footnote ) <EOL> self . footnotes . append ( footnote ) <EOL> def note_footnote_ref ( self , ref ) : <EOL> self . set_id ( ref ) <EOL> self . footnote_refs . setdefault ( ref [ '<STR_LIT>' ] , [ ] ) . append ( ref ) <EOL> self . note_refname ( ref ) <EOL> def note_citation ( self , citation ) : <EOL> self . citations . append ( citation ) <EOL> def note_citation_ref ( self , ref ) : <EOL> self . set_id ( ref ) <EOL> self . citation_refs . setdefault ( ref [ '<STR_LIT>' ] , [ ] ) . append ( ref ) <EOL> self . note_refname ( ref ) <EOL> def note_substitution_def ( self , subdef , def_name , msgnode = None ) : <EOL> name = whitespace_normalize_name ( def_name ) <EOL> if name in self . substitution_defs : <EOL> msg = self . reporter . error ( <EOL> '<STR_LIT>' % name , <EOL> base_node = subdef ) <EOL> if msgnode != None : <EOL> msgnode += msg <EOL> oldnode = self . substitution_defs [ name ] <EOL> dupname ( oldnode , name ) <EOL> self . substitution_defs [ name ] = subdef <EOL> self . substitution_names [ fully_normalize_name ( name ) ] = name <EOL> def note_substitution_ref ( self , subref , refname ) : <EOL> subref [ '<STR_LIT>' ] = whitespace_normalize_name ( refname ) <EOL> def note_pending ( self , pending , priority = None ) : <EOL> self . transformer . add_pending ( pending , priority ) <EOL> def note_parse_message ( self , message ) : <EOL> self . parse_messages . append ( message ) <EOL> def note_transform_message ( self , message ) : <EOL> self . transform_messages . append ( message ) <EOL> def note_source ( self , source , offset ) : <EOL> self . current_source = source <EOL> if offset is None : <EOL> self . current_line = offset <EOL> else : <EOL> self . current_line = offset + <NUM_LIT:1> <EOL> def copy ( self ) : <EOL> return self . __class__ ( self . settings , self . reporter , <EOL> ** self . attributes ) <EOL> def get_decoration ( self ) : <EOL> if not self . decoration : <EOL> self . decoration = decoration ( ) <EOL> index = self . first_child_not_matching_class ( Titular ) <EOL> if index is None : <EOL> self . append ( self . decoration ) <EOL> else : <EOL> self . insert ( index , self . decoration ) <EOL> return self . decoration <EOL> class title ( Titular , PreBibliographic , TextElement ) : pass <EOL> class subtitle ( Titular , PreBibliographic , TextElement ) : pass <EOL> class rubric ( Titular , TextElement ) : pass <EOL> class docinfo ( Bibliographic , Element ) : pass <EOL> class author ( Bibliographic , TextElement ) : pass <EOL> class authors ( Bibliographic , Element ) : pass <EOL> class organization ( Bibliographic , TextElement ) : pass <EOL> class address ( Bibliographic , FixedTextElement ) : pass <EOL> class contact ( Bibliographic , TextElement ) : pass <EOL> class version ( Bibliographic , TextElement ) : pass <EOL> class revision ( Bibliographic , TextElement ) : pass <EOL> class status ( Bibliographic , TextElement ) : pass <EOL> class date ( Bibliographic , TextElement ) : pass <EOL> class copyright ( Bibliographic , TextElement ) : pass <EOL> class decoration ( Decorative , Element ) : <EOL> def get_header ( self ) : <EOL> if not len ( self . children ) or not isinstance ( self . children [ <NUM_LIT:0> ] , header ) : <EOL> self . insert ( <NUM_LIT:0> , header ( ) ) <EOL> return self . children [ <NUM_LIT:0> ] <EOL> def get_footer ( self ) : <EOL> if not len ( self . children ) or not isinstance ( self . children [ - <NUM_LIT:1> ] , footer ) : <EOL> self . append ( footer ( ) ) <EOL> return self . children [ - <NUM_LIT:1> ] <EOL> class header ( Decorative , Element ) : pass <EOL> class footer ( Decorative , Element ) : pass <EOL> class section ( Structural , Element ) : pass <EOL> class topic ( Structural , Element ) : <EOL> """<STR_LIT>""" <EOL> class sidebar ( Structural , Element ) : <EOL> """<STR_LIT>""" <EOL> class transition ( Structural , Element ) : pass <EOL> class paragraph ( General , TextElement ) : pass <EOL> class compound ( General , Element ) : pass <EOL> class container ( General , Element ) : pass <EOL> class bullet_list ( Sequential , Element ) : pass <EOL> class enumerated_list ( Sequential , Element ) : pass <EOL> class list_item ( Part , Element ) : pass <EOL> class definition_list ( Sequential , Element ) : pass <EOL> class definition_list_item ( Part , Element ) : pass <EOL> class term ( Part , TextElement ) : pass <EOL> class classifier ( Part , TextElement ) : pass <EOL> class definition ( Part , Element ) : pass <EOL> class field_list ( Sequential , Element ) : pass <EOL> class field ( Part , Element ) : pass <EOL> class field_name ( Part , TextElement ) : pass <EOL> class field_body ( Part , Element ) : pass <EOL> class option ( Part , Element ) : <EOL> child_text_separator = '<STR_LIT>' <EOL> class option_argument ( Part , TextElement ) : <EOL> def astext ( self ) : <EOL> return self . get ( '<STR_LIT>' , '<STR_LIT:U+0020>' ) + TextElement . astext ( self ) <EOL> class option_group ( Part , Element ) : <EOL> child_text_separator = '<STR_LIT:U+002CU+0020>' <EOL> class option_list ( Sequential , Element ) : pass <EOL> class option_list_item ( Part , Element ) : <EOL> child_text_separator = '<STR_LIT:U+0020>' <EOL> class option_string ( Part , TextElement ) : pass <EOL> class description ( Part , Element ) : pass <EOL> class literal_block ( General , FixedTextElement ) : pass <EOL> class doctest_block ( General , FixedTextElement ) : pass <EOL> class math_block ( General , FixedTextElement ) : pass <EOL> class line_block ( General , Element ) : pass <EOL> class line ( Part , TextElement ) : <EOL> indent = None <EOL> class block_quote ( General , Element ) : pass <EOL> class attribution ( Part , TextElement ) : pass <EOL> class attention ( Admonition , Element ) : pass <EOL> class caution ( Admonition , Element ) : pass <EOL> class danger ( Admonition , Element ) : pass <EOL> class error ( Admonition , Element ) : pass <EOL> class important ( Admonition , Element ) : pass <EOL> class note ( Admonition , Element ) : pass <EOL> class tip ( Admonition , Element ) : pass <EOL> class hint ( Admonition , Element ) : pass <EOL> class warning ( Admonition , Element ) : pass <EOL> class admonition ( Admonition , Element ) : pass <EOL> class comment ( Special , Invisible , FixedTextElement ) : pass <EOL> class substitution_definition ( Special , Invisible , TextElement ) : pass <EOL> class target ( Special , Invisible , Inline , TextElement , Targetable ) : pass <EOL> class footnote ( General , BackLinkable , Element , Labeled , Targetable ) : pass <EOL> class citation ( General , BackLinkable , Element , Labeled , Targetable ) : pass <EOL> class label ( Part , TextElement ) : pass <EOL> class figure ( General , Element ) : pass <EOL> class caption ( Part , TextElement ) : pass <EOL> class legend ( Part , Element ) : pass <EOL> class table ( General , Element ) : pass <EOL> class tgroup ( Part , Element ) : pass <EOL> class colspec ( Part , Element ) : pass <EOL> class thead ( Part , Element ) : pass <EOL> class tbody ( Part , Element ) : pass <EOL> class row ( Part , Element ) : pass <EOL> class entry ( Part , Element ) : pass <EOL> class system_message ( Special , BackLinkable , PreBibliographic , Element ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , message = None , * children , ** attributes ) : <EOL> if message : <EOL> p = paragraph ( '<STR_LIT>' , message ) <EOL> children = ( p , ) + children <EOL> try : <EOL> Element . __init__ ( self , '<STR_LIT>' , * children , ** attributes ) <EOL> except : <EOL> print ( '<STR_LIT>' % ( children , ) ) <EOL> raise <EOL> def astext ( self ) : <EOL> line = self . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return '<STR_LIT>' % ( self [ '<STR_LIT:source>' ] , line , self [ '<STR_LIT:type>' ] , <EOL> self [ '<STR_LIT>' ] , Element . astext ( self ) ) <EOL> class pending ( Special , Invisible , Element ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , transform , details = None , <EOL> rawsource = '<STR_LIT>' , * children , ** attributes ) : <EOL> Element . __init__ ( self , rawsource , * children , ** attributes ) <EOL> self . transform = transform <EOL> """<STR_LIT>""" <EOL> self . details = details or { } <EOL> """<STR_LIT>""" <EOL> def pformat ( self , indent = '<STR_LIT:U+0020>' , level = <NUM_LIT:0> ) : <EOL> internals = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ( self . transform . __module__ , <EOL> self . transform . __name__ ) , <EOL> '<STR_LIT>' ] <EOL> details = list ( self . details . items ( ) ) <EOL> details . sort ( ) <EOL> for key , value in details : <EOL> if isinstance ( value , Node ) : <EOL> internals . append ( '<STR_LIT>' % ( '<STR_LIT>' , key ) ) <EOL> internals . extend ( [ '<STR_LIT>' % ( '<STR_LIT>' , line ) <EOL> for line in value . pformat ( ) . splitlines ( ) ] ) <EOL> elif value and isinstance ( value , list ) and isinstance ( value [ <NUM_LIT:0> ] , Node ) : <EOL> internals . append ( '<STR_LIT>' % ( '<STR_LIT>' , key ) ) <EOL> for v in value : <EOL> internals . extend ( [ '<STR_LIT>' % ( '<STR_LIT>' , line ) <EOL> for line in v . pformat ( ) . splitlines ( ) ] ) <EOL> else : <EOL> internals . append ( '<STR_LIT>' % ( '<STR_LIT>' , key , value ) ) <EOL> return ( Element . pformat ( self , indent , level ) <EOL> + '<STR_LIT>' . join ( [ ( '<STR_LIT>' % ( indent * level , line ) ) <EOL> for line in internals ] ) ) <EOL> def copy ( self ) : <EOL> return self . __class__ ( self . transform , self . details , self . rawsource , <EOL> ** self . attributes ) <EOL> class raw ( Special , Inline , PreBibliographic , FixedTextElement ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class emphasis ( Inline , TextElement ) : pass <EOL> class strong ( Inline , TextElement ) : pass <EOL> class literal ( Inline , TextElement ) : pass <EOL> class reference ( General , Inline , Referential , TextElement ) : pass <EOL> class footnote_reference ( Inline , Referential , TextElement ) : pass <EOL> class citation_reference ( Inline , Referential , TextElement ) : pass <EOL> class substitution_reference ( Inline , TextElement ) : pass <EOL> class title_reference ( Inline , TextElement ) : pass <EOL> class abbreviation ( Inline , TextElement ) : pass <EOL> class acronym ( Inline , TextElement ) : pass <EOL> class superscript ( Inline , TextElement ) : pass <EOL> class subscript ( Inline , TextElement ) : pass <EOL> class math ( Inline , TextElement ) : pass <EOL> class image ( General , Inline , Element ) : <EOL> def astext ( self ) : <EOL> return self . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class inline ( Inline , TextElement ) : pass <EOL> class problematic ( Inline , TextElement ) : pass <EOL> class generated ( Inline , TextElement ) : pass <EOL> node_class_names = """<STR_LIT>""" . split ( ) <EOL> """<STR_LIT>""" <EOL> class NodeVisitor : <EOL> """<STR_LIT>""" <EOL> optional = ( ) <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , document ) : <EOL> self . document = document <EOL> def dispatch_visit ( self , node ) : <EOL> """<STR_LIT>""" <EOL> node_name = node . __class__ . __name__ <EOL> method = getattr ( self , '<STR_LIT>' + node_name , self . unknown_visit ) <EOL> self . document . reporter . debug ( <EOL> '<STR_LIT>' <EOL> % ( method . __name__ , node_name ) ) <EOL> return method ( node ) <EOL> def dispatch_departure ( self , node ) : <EOL> """<STR_LIT>""" <EOL> node_name = node . __class__ . __name__ <EOL> method = getattr ( self , '<STR_LIT>' + node_name , self . unknown_departure ) <EOL> self . document . reporter . debug ( <EOL> '<STR_LIT>' <EOL> % ( method . __name__ , node_name ) ) <EOL> return method ( node ) <EOL> def unknown_visit ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if ( self . document . settings . strict_visitor <EOL> or node . __class__ . __name__ not in self . optional ) : <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' <EOL> % ( self . __class__ , node . __class__ . __name__ ) ) <EOL> def unknown_departure ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if ( self . document . settings . strict_visitor <EOL> or node . __class__ . __name__ not in self . optional ) : <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' <EOL> % ( self . __class__ , node . __class__ . __name__ ) ) <EOL> class SparseNodeVisitor ( NodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> class GenericNodeVisitor ( NodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> def default_visit ( self , node ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def default_departure ( self , node ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _call_default_visit ( self , node ) : <EOL> self . default_visit ( node ) <EOL> def _call_default_departure ( self , node ) : <EOL> self . default_departure ( node ) <EOL> def _nop ( self , node ) : <EOL> pass <EOL> def _add_node_class_names ( names ) : <EOL> """<STR_LIT>""" <EOL> for _name in names : <EOL> setattr ( GenericNodeVisitor , "<STR_LIT>" + _name , _call_default_visit ) <EOL> setattr ( GenericNodeVisitor , "<STR_LIT>" + _name , _call_default_departure ) <EOL> setattr ( SparseNodeVisitor , '<STR_LIT>' + _name , _nop ) <EOL> setattr ( SparseNodeVisitor , '<STR_LIT>' + _name , _nop ) <EOL> _add_node_class_names ( node_class_names ) <EOL> class TreeCopyVisitor ( GenericNodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , document ) : <EOL> GenericNodeVisitor . __init__ ( self , document ) <EOL> self . parent_stack = [ ] <EOL> self . parent = [ ] <EOL> def get_tree_copy ( self ) : <EOL> return self . parent [ <NUM_LIT:0> ] <EOL> def default_visit ( self , node ) : <EOL> """<STR_LIT>""" <EOL> newnode = node . copy ( ) <EOL> self . parent . append ( newnode ) <EOL> self . parent_stack . append ( self . parent ) <EOL> self . parent = newnode <EOL> def default_departure ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . parent = self . parent_stack . pop ( ) <EOL> class TreePruningException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SkipChildren ( TreePruningException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SkipSiblings ( TreePruningException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SkipNode ( TreePruningException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SkipDeparture ( TreePruningException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class NodeFound ( TreePruningException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class StopTraversal ( TreePruningException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def make_id ( string ) : <EOL> """<STR_LIT>""" <EOL> id = string . lower ( ) <EOL> if not isinstance ( id , str ) : <EOL> id = id . decode ( ) <EOL> id = id . translate ( _non_id_translate_digraphs ) <EOL> id = id . translate ( _non_id_translate ) <EOL> id = unicodedata . normalize ( '<STR_LIT>' , id ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) . decode ( '<STR_LIT:ascii>' ) <EOL> id = _non_id_chars . sub ( '<STR_LIT:->' , '<STR_LIT:U+0020>' . join ( id . split ( ) ) ) <EOL> id = _non_id_at_ends . sub ( '<STR_LIT>' , id ) <EOL> return str ( id ) <EOL> _non_id_chars = re . compile ( '<STR_LIT>' ) <EOL> _non_id_at_ends = re . compile ( '<STR_LIT>' ) <EOL> _non_id_translate = { <EOL> <NUM_LIT> : '<STR_LIT:o>' , <EOL> <NUM_LIT> : '<STR_LIT:d>' , <EOL> <NUM_LIT> : '<STR_LIT:h>' , <EOL> <NUM_LIT> : '<STR_LIT:i>' , <EOL> <NUM_LIT> : '<STR_LIT:l>' , <EOL> <NUM_LIT> : '<STR_LIT:t>' , <EOL> <NUM_LIT> : '<STR_LIT:b>' , <EOL> <NUM_LIT> : '<STR_LIT:b>' , <EOL> <NUM_LIT> : '<STR_LIT:c>' , <EOL> <NUM_LIT> : '<STR_LIT:d>' , <EOL> <NUM_LIT> : '<STR_LIT:f>' , <EOL> <NUM_LIT> : '<STR_LIT:k>' , <EOL> <NUM_LIT> : '<STR_LIT:l>' , <EOL> <NUM_LIT> : '<STR_LIT:n>' , <EOL> <NUM_LIT> : '<STR_LIT:p>' , <EOL> <NUM_LIT> : '<STR_LIT:t>' , <EOL> <NUM_LIT> : '<STR_LIT:t>' , <EOL> <NUM_LIT> : '<STR_LIT:y>' , <EOL> <NUM_LIT> : '<STR_LIT:z>' , <EOL> <NUM_LIT> : '<STR_LIT:g>' , <EOL> <NUM_LIT> : '<STR_LIT:z>' , <EOL> <NUM_LIT> : '<STR_LIT:l>' , <EOL> <NUM_LIT> : '<STR_LIT:n>' , <EOL> <NUM_LIT> : '<STR_LIT:t>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT:c>' , <EOL> <NUM_LIT> : '<STR_LIT:s>' , <EOL> <NUM_LIT> : '<STR_LIT:z>' , <EOL> <NUM_LIT> : '<STR_LIT:e>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT:q>' , <EOL> <NUM_LIT> : '<STR_LIT:r>' , <EOL> <NUM_LIT> : '<STR_LIT:y>' , <EOL> } <EOL> _non_id_translate_digraphs = { <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> } <EOL> def dupname ( node , name ) : <EOL> node [ '<STR_LIT>' ] . append ( name ) <EOL> node [ '<STR_LIT>' ] . remove ( name ) <EOL> node . referenced = <NUM_LIT:1> <EOL> def fully_normalize_name ( name ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:U+0020>' . join ( name . lower ( ) . split ( ) ) <EOL> def whitespace_normalize_name ( name ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:U+0020>' . join ( name . split ( ) ) <EOL> def serial_escape ( value ) : <EOL> """<STR_LIT>""" <EOL> return value . replace ( '<STR_LIT:\\>' , r'<STR_LIT:\\>' ) . replace ( '<STR_LIT:U+0020>' , r'<STR_LIT>' ) <EOL> def pseudo_quoteattr ( value ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % value </s>
