<s> """<STR_LIT>""" <EOL> from suds import * <EOL> from suds . sax import * <EOL> class Text ( unicode ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> @ classmethod <EOL> def __valid ( cls , * args ) : <EOL> return ( len ( args ) and args [ <NUM_LIT:0> ] is not None ) <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> if cls . __valid ( * args ) : <EOL> lang = kwargs . pop ( '<STR_LIT>' , None ) <EOL> escaped = kwargs . pop ( '<STR_LIT>' , False ) <EOL> result = super ( Text , cls ) . __new__ ( cls , * args , ** kwargs ) <EOL> result . lang = lang <EOL> result . escaped = escaped <EOL> else : <EOL> result = None <EOL> return result <EOL> def escape ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . escaped : <EOL> post = sax . encoder . encode ( self ) <EOL> escaped = ( post != self ) <EOL> return Text ( post , lang = self . lang , escaped = escaped ) <EOL> return self <EOL> def unescape ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . escaped : <EOL> post = sax . encoder . decode ( self ) <EOL> return Text ( post , lang = self . lang ) <EOL> return self <EOL> def trim ( self ) : <EOL> post = self . strip ( ) <EOL> return Text ( post , lang = self . lang , escaped = self . escaped ) <EOL> def __add__ ( self , other ) : <EOL> joined = u'<STR_LIT>' . join ( ( self , other ) ) <EOL> result = Text ( joined , lang = self . lang , escaped = self . escaped ) <EOL> if isinstance ( other , Text ) : <EOL> result . escaped = ( self . escaped or other . escaped ) <EOL> return result <EOL> def __repr__ ( self ) : <EOL> s = [ self ] <EOL> if self . lang is not None : <EOL> s . append ( '<STR_LIT>' % self . lang ) <EOL> if self . escaped : <EOL> s . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( s ) <EOL> def __getstate__ ( self ) : <EOL> state = { } <EOL> for k in self . __slots__ : <EOL> state [ k ] = getattr ( self , k ) <EOL> return state <EOL> def __setstate__ ( self , state ) : <EOL> for k in self . __slots__ : <EOL> setattr ( self , k , state [ k ] ) <EOL> class Raw ( Text ) : <EOL> """<STR_LIT>""" <EOL> def escape ( self ) : <EOL> return self <EOL> def unescape ( self ) : <EOL> return self <EOL> def __add__ ( self , other ) : <EOL> joined = u'<STR_LIT>' . join ( ( self , other ) ) <EOL> return Raw ( joined , lang = self . lang ) </s>
