<s> from django . core . serializers . xml_serializer import Serializer as XmlSerializer <EOL> from django . core . serializers . json import DjangoJSONEncoder <EOL> from django . utils . encoding import smart_unicode , force_unicode <EOL> from django . utils . functional import Promise <EOL> class Serializer ( XmlSerializer ) : <EOL> """<STR_LIT>""" <EOL> def start_object ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> model_name = smart_unicode ( obj . _meta ) <EOL> if model_name == '<STR_LIT>' : <EOL> obj . set_unusable_password ( ) <EOL> super ( Serializer , self ) . start_object ( obj ) <EOL> def handle_field ( self , obj , field ) : <EOL> """<STR_LIT>""" <EOL> model_name = smart_unicode ( obj . _meta ) <EOL> field_name = field . name <EOL> value = field . _get_val_from_obj ( obj ) <EOL> if model_name == u'<STR_LIT>' and field_name in ( '<STR_LIT:username>' , '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> uid = '<STR_LIT>' % obj . pk <EOL> if field_name == '<STR_LIT:email>' : <EOL> value = '<STR_LIT>' % uid <EOL> else : <EOL> value = uid <EOL> else : <EOL> if field_name . find ( '<STR_LIT:email>' ) > - <NUM_LIT:1> : <EOL> value = '<STR_LIT>' <EOL> setattr ( obj , field_name , value ) <EOL> super ( Serializer , self ) . handle_field ( obj , field ) <EOL> class PromiseAwareJSONEncoder ( DjangoJSONEncoder ) : <EOL> def default ( self , o ) : <EOL> if isinstance ( o , Promise ) : <EOL> return force_unicode ( o ) <EOL> return super ( PromiseAwareJSONEncoder , self ) . default ( o ) </s>
