U
    Lk7g                     @   s   d dl mZ dZG dd deZG dd deZG dd deZG d	d
 d
eZG dd deZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )     )defaultdict)NotRegisteredInvalidDocumentErrorLookUpErrorDoesNotExistMultipleObjectsReturnedInvalidQueryErrorOperationErrorNotUniqueErrorBulkWriteErrorFieldDoesNotExistValidationErrorSaveConditionErrorDeprecatedErrorc                   @   s   e Zd ZdS )MongoEngineExceptionN__name__
__module____qualname__ r   r   6/tmp/pip-unpacked-wheel-n1etwkgt/mongoengine/errors.pyr      s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r       s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r   $   s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r   (   s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r   ,   s   r   c                   @   s   e Zd ZdS )r	   Nr   r   r   r   r   r	   0   s   r	   c                   @   s   e Zd ZdS )r
   Nr   r   r   r   r   r
   4   s   r
   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r   8   s   r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r   <   s   r   c                   @   s   e Zd ZdZdS )r   a  Raised when trying to set a field
    not declared in a :class:`~mongoengine.Document`
    or an :class:`~mongoengine.EmbeddedDocument`.

    To avoid this behavior on data loading,
    you should set the :attr:`strict` to ``False``
    in the :attr:`meta` dictionary.
    Nr   r   r   __doc__r   r   r   r   r   @   s   r   c                       st   e Zd ZdZi ZdZdZd fdd	Zdd Zdd	 Z	 fd
dZ
dd Zdd ZeeeZdd Zdd Z  ZS )r   a  Validation exception.

    May represent an error validating a field or a
    document containing fields with validation errors.

    :ivar errors: A dictionary of errors for fields within this
        document or list, or None if the error is for an
        individual field.
    N c                    s0   t  | |di | _|d| _|| _d S )Nerrors
field_name)super__init__getr   r   message)selfr   kwargs	__class__r   r   r   Z   s    zValidationError.__init__c                 C   s
   t | jS N)strr   r    r   r   r   __str__`   s    zValidationError.__str__c                 C   s   | j j d| j dS )N(z,))r#   r   r   r&   r   r   r   __repr__c   s    zValidationError.__repr__c                    s@   t  |}|dkr<| jr"d| }| jr<| d|   d}|S )Nr   z%sr(   ))r   __getattribute__r   r   _format_errors)r    namer   r"   r   r   r+   f   s    z ValidationError.__getattribute__c                 C   s   | j S r$   _messager&   r   r   r   _get_messageo   s    zValidationError._get_messagec                 C   s
   || _ d S r$   r.   )r    r   r   r   r   _set_messager   s    zValidationError._set_messagec                    s     fdd | j si S  | j S )zReturns a dictionary of all errors within a document

        Keys are field names or list indices and values are the
        validation error messages, or a nested dictionary of
        errors for an embedded document or list.
        c                    sT   i }t | tr.|  D ]\}} |||< qn"t | trH| jrH | jS t| S |S r$   )
isinstancedictitemsr   r   r%   )sourceZerrors_dictr   error
build_dictr   r   r8      s    

z+ValidationError.to_dict.<locals>.build_dict)r   r&   r   r7   r   to_dictw   s    zValidationError.to_dictc                    sV   d fdd	 t t}|   D ]\}}| | | q"ddd | D S )z5Returns a string listing all errors within a documentr   c                    sd   t | tr$d fdd| D } n&t | trJd fdd|  D } |r\| d|  n| }|S )N c                    s   g | ]} |qS r   r   ).0kgenerate_keyr   r   
<listcomp>   s     zHValidationError._format_errors.<locals>.generate_key.<locals>.<listcomp>c                    s   g | ]\}} ||qS r   r   r;   r<   vr=   r   r   r?      s     .)r2   listjoinr3   r4   )valueprefixresultsr=   r   r   r>      s    

z4ValidationError._format_errors.<locals>.generate_keyr:   c                 S   s   g | ]\}}| d | qS )z: r   r@   r   r   r   r?      s     z2ValidationError._format_errors.<locals>.<listcomp>)r   )r   rC   r9   r4   appendrD   )r    Z
error_dictr<   rA   r   r=   r   r,      s
    	zValidationError._format_errors)r   )r   r   r   r   r   r   r/   r   r'   r)   r+   r0   r1   propertyr   r9   r,   __classcell__r   r   r"   r   r   K   s   
	
r   c                   @   s   e Zd ZdZdS )r   z9Raise when a user uses a feature that has been DeprecatedNr   r   r   r   r   r      s   r   N)collectionsr   __all__	Exceptionr   r   r   AttributeErrorr   r   r   r   r	   r
   r   r   r   AssertionErrorr   r   r   r   r   r   <module>   s   W