<s> """<STR_LIT>""" <EOL> from django . utils import six <EOL> from django . utils . encoding import force_text <EOL> class FieldDoesNotExist ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DjangoRuntimeWarning ( RuntimeWarning ) : <EOL> pass <EOL> class AppRegistryNotReady ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ObjectDoesNotExist ( Exception ) : <EOL> """<STR_LIT>""" <EOL> silent_variable_failure = True <EOL> class MultipleObjectsReturned ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SuspiciousOperation ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class SuspiciousMultipartForm ( SuspiciousOperation ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SuspiciousFileOperation ( SuspiciousOperation ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DisallowedHost ( SuspiciousOperation ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DisallowedRedirect ( SuspiciousOperation ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class PermissionDenied ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ViewDoesNotExist ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class MiddlewareNotUsed ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ImproperlyConfigured ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class FieldError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> NON_FIELD_ERRORS = '<STR_LIT>' <EOL> class ValidationError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , message , code = None , params = None ) : <EOL> """<STR_LIT>""" <EOL> super ( ValidationError , self ) . __init__ ( message , code , params ) <EOL> if isinstance ( message , ValidationError ) : <EOL> if hasattr ( message , '<STR_LIT>' ) : <EOL> message = message . error_dict <EOL> elif not hasattr ( message , '<STR_LIT:message>' if six . PY3 else '<STR_LIT:code>' ) : <EOL> message = message . error_list <EOL> else : <EOL> message , code , params = message . message , message . code , message . params <EOL> if isinstance ( message , dict ) : <EOL> self . error_dict = { } <EOL> for field , messages in message . items ( ) : <EOL> if not isinstance ( messages , ValidationError ) : <EOL> messages = ValidationError ( messages ) <EOL> self . error_dict [ field ] = messages . error_list <EOL> elif isinstance ( message , list ) : <EOL> self . error_list = [ ] <EOL> for message in message : <EOL> if not isinstance ( message , ValidationError ) : <EOL> message = ValidationError ( message ) <EOL> if hasattr ( message , '<STR_LIT>' ) : <EOL> self . error_list . extend ( sum ( message . error_dict . values ( ) , [ ] ) ) <EOL> else : <EOL> self . error_list . extend ( message . error_list ) <EOL> else : <EOL> self . message = message <EOL> self . code = code <EOL> self . params = params <EOL> self . error_list = [ self ] <EOL> @ property <EOL> def message_dict ( self ) : <EOL> getattr ( self , '<STR_LIT>' ) <EOL> return dict ( self ) <EOL> @ property <EOL> def messages ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return sum ( dict ( self ) . values ( ) , [ ] ) <EOL> return list ( self ) <EOL> def update_error_dict ( self , error_dict ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> for field , error_list in self . error_dict . items ( ) : <EOL> error_dict . setdefault ( field , [ ] ) . extend ( error_list ) <EOL> else : <EOL> error_dict . setdefault ( NON_FIELD_ERRORS , [ ] ) . extend ( self . error_list ) <EOL> return error_dict <EOL> def __iter__ ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> for field , errors in self . error_dict . items ( ) : <EOL> yield field , list ( ValidationError ( errors ) ) <EOL> else : <EOL> for error in self . error_list : <EOL> message = error . message <EOL> if error . params : <EOL> message %= error . params <EOL> yield force_text ( message ) <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return repr ( dict ( self ) ) <EOL> return repr ( list ( self ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self </s>
