<s> """<STR_LIT>""" <EOL> from twisted . conch . insults import helper , insults <EOL> class _Attribute ( object ) : <EOL> def __init__ ( self ) : <EOL> self . children = [ ] <EOL> def __getitem__ ( self , item ) : <EOL> assert isinstance ( item , ( list , tuple , _Attribute , str ) ) <EOL> if isinstance ( item , ( list , tuple ) ) : <EOL> self . children . extend ( item ) <EOL> else : <EOL> self . children . append ( item ) <EOL> return self <EOL> def serialize ( self , write , attrs = None ) : <EOL> if attrs is None : <EOL> attrs = helper . CharacterAttribute ( ) <EOL> for ch in self . children : <EOL> if isinstance ( ch , _Attribute ) : <EOL> ch . serialize ( write , attrs . copy ( ) ) <EOL> else : <EOL> write ( attrs . toVT102 ( ) ) <EOL> write ( ch ) <EOL> class _NormalAttr ( _Attribute ) : <EOL> def serialize ( self , write , attrs ) : <EOL> attrs . __init__ ( ) <EOL> super ( _NormalAttr , self ) . serialize ( write , attrs ) <EOL> class _OtherAttr ( _Attribute ) : <EOL> def __init__ ( self , attrname , attrvalue ) : <EOL> self . attrname = attrname <EOL> self . attrvalue = attrvalue <EOL> self . children = [ ] <EOL> def __neg__ ( self ) : <EOL> result = _OtherAttr ( self . attrname , not self . attrvalue ) <EOL> result . children . extend ( self . children ) <EOL> return result <EOL> def serialize ( self , write , attrs ) : <EOL> attrs = attrs . wantOne ( ** { self . attrname : self . attrvalue } ) <EOL> super ( _OtherAttr , self ) . serialize ( write , attrs ) <EOL> class _ColorAttr ( _Attribute ) : <EOL> def __init__ ( self , color , ground ) : <EOL> self . color = color <EOL> self . ground = ground <EOL> self . children = [ ] <EOL> def serialize ( self , write , attrs ) : <EOL> attrs = attrs . wantOne ( ** { self . ground : self . color } ) <EOL> super ( _ColorAttr , self ) . serialize ( write , attrs ) <EOL> class _ForegroundColorAttr ( _ColorAttr ) : <EOL> def __init__ ( self , color ) : <EOL> super ( _ForegroundColorAttr , self ) . __init__ ( color , '<STR_LIT>' ) <EOL> class _BackgroundColorAttr ( _ColorAttr ) : <EOL> def __init__ ( self , color ) : <EOL> super ( _BackgroundColorAttr , self ) . __init__ ( color , '<STR_LIT>' ) <EOL> class CharacterAttributes ( object ) : <EOL> class _ColorAttribute ( object ) : <EOL> def __init__ ( self , ground ) : <EOL> self . ground = ground <EOL> attrs = { <EOL> '<STR_LIT>' : helper . BLACK , <EOL> '<STR_LIT>' : helper . RED , <EOL> '<STR_LIT>' : helper . GREEN , <EOL> '<STR_LIT>' : helper . YELLOW , <EOL> '<STR_LIT>' : helper . BLUE , <EOL> '<STR_LIT>' : helper . MAGENTA , <EOL> '<STR_LIT>' : helper . CYAN , <EOL> '<STR_LIT>' : helper . WHITE } <EOL> def __getattr__ ( self , name ) : <EOL> try : <EOL> return self . ground ( self . attrs [ name ] ) <EOL> except KeyError : <EOL> raise AttributeError ( name ) <EOL> fg = _ColorAttribute ( _ForegroundColorAttr ) <EOL> bg = _ColorAttribute ( _BackgroundColorAttr ) <EOL> attrs = { <EOL> '<STR_LIT>' : insults . BOLD , <EOL> '<STR_LIT>' : insults . BLINK , <EOL> '<STR_LIT>' : insults . UNDERLINE , <EOL> '<STR_LIT>' : insults . REVERSE_VIDEO } <EOL> def __getattr__ ( self , name ) : <EOL> if name == '<STR_LIT>' : <EOL> return _NormalAttr ( ) <EOL> if name in self . attrs : <EOL> return _OtherAttr ( name , True ) <EOL> raise AttributeError ( name ) <EOL> def flatten ( output , attrs ) : <EOL> """<STR_LIT>""" <EOL> L = [ ] <EOL> output . serialize ( L . append , attrs ) <EOL> return '<STR_LIT>' . join ( L ) <EOL> attributes = CharacterAttributes ( ) <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] </s>
