<s> """<STR_LIT>""" <EOL> from google . appengine . _internal . django . utils . functional import curry , Promise <EOL> class EscapeData ( object ) : <EOL> pass <EOL> class EscapeString ( str , EscapeData ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class EscapeUnicode ( unicode , EscapeData ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SafeData ( object ) : <EOL> pass <EOL> class SafeString ( str , SafeData ) : <EOL> """<STR_LIT>""" <EOL> def __add__ ( self , rhs ) : <EOL> """<STR_LIT>""" <EOL> t = super ( SafeString , self ) . __add__ ( rhs ) <EOL> if isinstance ( rhs , SafeUnicode ) : <EOL> return SafeUnicode ( t ) <EOL> elif isinstance ( rhs , SafeString ) : <EOL> return SafeString ( t ) <EOL> return t <EOL> def _proxy_method ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> method = kwargs . pop ( '<STR_LIT>' ) <EOL> data = method ( self , * args , ** kwargs ) <EOL> if isinstance ( data , str ) : <EOL> return SafeString ( data ) <EOL> else : <EOL> return SafeUnicode ( data ) <EOL> decode = curry ( _proxy_method , method = str . decode ) <EOL> class SafeUnicode ( unicode , SafeData ) : <EOL> """<STR_LIT>""" <EOL> def __add__ ( self , rhs ) : <EOL> """<STR_LIT>""" <EOL> t = super ( SafeUnicode , self ) . __add__ ( rhs ) <EOL> if isinstance ( rhs , SafeData ) : <EOL> return SafeUnicode ( t ) <EOL> return t <EOL> def _proxy_method ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> method = kwargs . pop ( '<STR_LIT>' ) <EOL> data = method ( self , * args , ** kwargs ) <EOL> if isinstance ( data , str ) : <EOL> return SafeString ( data ) <EOL> else : <EOL> return SafeUnicode ( data ) <EOL> encode = curry ( _proxy_method , method = unicode . encode ) <EOL> def mark_safe ( s ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( s , SafeData ) : <EOL> return s <EOL> if isinstance ( s , str ) or ( isinstance ( s , Promise ) and s . _delegate_str ) : <EOL> return SafeString ( s ) <EOL> if isinstance ( s , ( unicode , Promise ) ) : <EOL> return SafeUnicode ( s ) <EOL> return SafeString ( str ( s ) ) <EOL> def mark_for_escaping ( s ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( s , ( SafeData , EscapeData ) ) : <EOL> return s <EOL> if isinstance ( s , str ) or ( isinstance ( s , Promise ) and s . _delegate_str ) : <EOL> return EscapeString ( s ) <EOL> if isinstance ( s , ( unicode , Promise ) ) : <EOL> return EscapeUnicode ( s ) <EOL> return EscapeString ( str ( s ) ) </s>
