<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import re <EOL> from django . utils import six <EOL> from django . utils . encoding import force_str <EOL> from mongoengine . base import BaseDocument <EOL> from mongoengine . fields import BaseField <EOL> from mongoengine . queryset import QuerySet <EOL> from rest_framework . compat import unicode_repr <EOL> from rest_framework . fields import Field <EOL> def manager_repr ( value ) : <EOL> model = value . _document <EOL> return '<STR_LIT>' % ( model . __name__ , ) <EOL> def mongo_field_repr ( value ) : <EOL> path = '<STR_LIT>' % ( value . __class__ . __module__ , value . __class__ . __name__ ) <EOL> name = getattr ( value , '<STR_LIT:name>' , None ) <EOL> if name is not None : <EOL> return '<STR_LIT>' % ( path , name ) <EOL> return '<STR_LIT>' % path <EOL> def mongo_doc_repr ( value ) : <EOL> try : <EOL> u = six . text_type ( value ) <EOL> except ( UnicodeEncodeError , UnicodeDecodeError ) : <EOL> u = '<STR_LIT>' <EOL> return force_str ( '<STR_LIT>' % ( value . __class__ . __name__ , u ) ) <EOL> uni_lit_re = re . compile ( "<STR_LIT>" ) <EOL> def smart_repr ( value ) : <EOL> if isinstance ( value , QuerySet ) : <EOL> return manager_repr ( value ) <EOL> if isinstance ( value , BaseField ) : <EOL> return mongo_field_repr ( value ) <EOL> if isinstance ( value , BaseDocument ) : <EOL> return mongo_field_repr ( value ) <EOL> if isinstance ( value , Field ) : <EOL> return field_repr ( value ) <EOL> value = unicode_repr ( value ) <EOL> value = uni_lit_re . sub ( "<STR_LIT>" , value ) <EOL> value = re . sub ( '<STR_LIT>' , '<STR_LIT:>>' , value ) <EOL> return value <EOL> def field_repr ( field , force_many = False ) : <EOL> kwargs = field . _kwargs <EOL> if force_many : <EOL> kwargs = kwargs . copy ( ) <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs . pop ( '<STR_LIT>' , None ) <EOL> if kwargs . get ( '<STR_LIT:label>' , None ) is None : <EOL> kwargs . pop ( '<STR_LIT:label>' , None ) <EOL> if kwargs . get ( '<STR_LIT>' , None ) is None : <EOL> kwargs . pop ( '<STR_LIT>' , None ) <EOL> arg_string = '<STR_LIT:U+002CU+0020>' . join ( [ smart_repr ( val ) for val in field . _args ] ) <EOL> kwarg_string = '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> '<STR_LIT>' % ( key , smart_repr ( val ) ) <EOL> for key , val in sorted ( kwargs . items ( ) ) <EOL> ] ) <EOL> if arg_string and kwarg_string : <EOL> arg_string += '<STR_LIT:U+002CU+0020>' <EOL> if force_many : <EOL> class_name = force_many . __class__ . __name__ <EOL> else : <EOL> class_name = field . __class__ . __name__ <EOL> return "<STR_LIT>" % ( class_name , arg_string , kwarg_string ) <EOL> def serializer_repr ( serializer , indent , force_many = None ) : <EOL> ret = field_repr ( serializer , force_many ) + '<STR_LIT::>' <EOL> indent_str = '<STR_LIT:U+0020>' * indent <EOL> if force_many : <EOL> fields = force_many . fields <EOL> else : <EOL> fields = serializer . fields <EOL> for field_name , field in fields . items ( ) : <EOL> ret += '<STR_LIT:\n>' + indent_str + field_name + '<STR_LIT>' <EOL> if hasattr ( field , '<STR_LIT>' ) : <EOL> ret += serializer_repr ( field , indent + <NUM_LIT:1> ) <EOL> elif hasattr ( field , '<STR_LIT>' ) : <EOL> ret += list_repr ( field , indent + <NUM_LIT:1> ) <EOL> else : <EOL> ret += field_repr ( field ) <EOL> if serializer . validators : <EOL> ret += '<STR_LIT:\n>' + indent_str + '<STR_LIT>' <EOL> ret += '<STR_LIT:\n>' + indent_str + '<STR_LIT>' + smart_repr ( serializer . validators ) <EOL> if len ( fields ) == <NUM_LIT:0> : <EOL> ret += "<STR_LIT>" <EOL> return ret <EOL> def list_repr ( serializer , indent ) : <EOL> child = serializer . child <EOL> if hasattr ( child , '<STR_LIT>' ) : <EOL> return serializer_repr ( serializer , indent , force_many = child ) <EOL> return field_repr ( serializer ) </s>
