<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , unicode_literals <EOL> import warnings <EOL> from raven . _compat import integer_types , text_type , binary_type , string_types , PY2 <EOL> def is_protected_type ( obj ) : <EOL> """<STR_LIT>""" <EOL> import Decimal <EOL> import datetime <EOL> return isinstance ( obj , integer_types + ( type ( None ) , float , Decimal , <EOL> datetime . datetime , datetime . date , datetime . time ) ) <EOL> def force_text ( s , encoding = '<STR_LIT:utf-8>' , strings_only = False , errors = '<STR_LIT:strict>' ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( s , text_type ) : <EOL> return s <EOL> if strings_only and is_protected_type ( s ) : <EOL> return s <EOL> try : <EOL> if not isinstance ( s , string_types ) : <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> s = s . __unicode__ ( ) <EOL> else : <EOL> if not PY2 : <EOL> if isinstance ( s , bytes ) : <EOL> s = text_type ( s , encoding , errors ) <EOL> else : <EOL> s = text_type ( s ) <EOL> else : <EOL> s = text_type ( bytes ( s ) , encoding , errors ) <EOL> else : <EOL> s = s . decode ( encoding , errors ) <EOL> except UnicodeDecodeError as e : <EOL> if not isinstance ( s , Exception ) : <EOL> raise UnicodeDecodeError ( * e . args ) <EOL> else : <EOL> s = '<STR_LIT:U+0020>' . join ( [ force_text ( arg , encoding , strings_only , <EOL> errors ) for arg in s ] ) <EOL> return s <EOL> def transform ( value ) : <EOL> from raven . utils . serializer import transform <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' , DeprecationWarning ) <EOL> return transform ( value ) <EOL> def to_unicode ( value ) : <EOL> try : <EOL> value = text_type ( force_text ( value ) ) <EOL> except ( UnicodeEncodeError , UnicodeDecodeError ) : <EOL> value = '<STR_LIT>' <EOL> except Exception : <EOL> try : <EOL> value = binary_type ( repr ( type ( value ) ) ) <EOL> except Exception : <EOL> value = '<STR_LIT>' <EOL> return value <EOL> def to_string ( value ) : <EOL> try : <EOL> return binary_type ( value . decode ( '<STR_LIT:utf-8>' ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> except : <EOL> return to_unicode ( value ) . encode ( '<STR_LIT:utf-8>' ) </s>
