Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib/python3.5/site-packages/cerberus/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/cerberus/__pycache__/errors.cpython-35.opt-1.pyc



L�X�K�@s�dZddlmZddlmZmZmZddlmZmZddl	m
Z
ddlmZddl
mZddlmZmZed	d
�Zedd�Zedd�Zd
Zedd�Zedd�Zedd�Zedd�Zedd�Zedd�ZdZedd�Zedd�Zedd�Zedd�Zed d!�Zed"d#�Z ed$d%�Z!ed&d'�Z"ed(d)�Z#ed*d+�Z$ed,d-�Z%ed.d-�Z&ed/d0�Z'ed1d0�Z(ed2d�Z)ed3d4�Z*ed5d6�Z+ed7d8�Z,ed9d:�Z-ed;d�Z.ed<d�Z/ed=d�Z0ed>d?�Z1ed@dA�Z2edBd!�Z3edCd�Z4edDdE�Z5edFdG�Z6edHdI�Z7edJdK�Z8dLZ9dMZ:GdNdO�dOe;�Z<GdPdQ�dQe=�Z>GdRdS�dSe�Z?GdTdU�dUe?�Z@GdVdW�dWe@�ZAGdXdY�dYe@�ZBGdZd[�d[e;�ZCGd\d]�d]eC�ZDd^d_�ZEGd`da�daeC�ZFGdbdc�dceF�ZGdS)dz? This module contains the error-related constants and classes. �)�absolute_import)�defaultdict�
namedtuple�MutableMapping)�copy�deepcopy)�wraps)�pformat)�PYTHON_VERSION)�compare_paths_lt�quote_stringZcerberus_errorz
code, ruleN�zdocument is missing�Zrequired��Zdependencies��Zexcludes�!z''{0}' is not a document, must be a dict�"�empty�#Znullable�$�type�%�schema�&�items�'Z	minlength�(Z	maxlength�AZregex�B�min�C�max�DZallowed�E�FZ	forbidden�G�`�aZcoerce�bZrename_handler�c�readonly�dZdefault_setter����Z	keyschema�Zvalueschema���Znoneof�Zoneof�Zanyof�Zallofz0schema definition for field '{0}' must be a dictzvalidation schema missingc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dd
��Z
e	dd��Ze	dd��Ze	dd��Z
e	dd��Ze	dd��ZdS)�ValidationErrorz< A simple class to store and query basic error information. cCsC||_||_||_||_||_||_||_dS)N)�
document_path�schema_path�code�rule�
constraint�value�info)�selfr:r;r<r=r>r?r@�rB�@/opt/alt/python35/lib/python3.5/site-packages/cerberus/errors.py�__init__^s							zValidationError.__init__cCst|�t|�kS)z< Assumes the errors relate to the same document and schema. )�hash)rA�otherrBrBrC�__eq__rszValidationError.__eq__cCs't|j�t|j�At|j�AS)z@ Expects that all other properties are transitively determined. )rEr:r;r<)rArBrBrC�__hash__vszValidationError.__hash__cCs<|j|jkr%t|j|j�St|j|j�SdS)N)r:rr;)rArFrBrBrC�__lt__{szValidationError.__lt__cCspdjd|jjdtt|��d|jd|jdt|j�dt|j	�dt|j
�d	|j�S)
Nz�{class_name} @ {memptr} ( document_path={document_path},schema_path={schema_path},code={code},constraint={constraint},value={value},info={info} )Z
class_nameZmemptrr:r;r<r>r?r@)�format�	__class__�__name__�hex�idr:r;r<rr>r?r@)rArBrBrC�__repr__�s			zValidationError.__repr__cCs|jr|jdSdS)zX
        A list that contains the individual errors of a bulk validation error.
        rN)�is_group_errorr@)rArBrBrC�child_errors�szValidationError.child_errorscCsX|js
dStt�}x8|jD]-}|jt|j�}||j|�q#W|S)z� Dictionary with errors of an *of-rule mapped to the index of the
            definition it occurred in. Returns :obj:`None` if not applicable.
            N)�is_logic_errorr�listrQr;�len�append)rA�result�error�irBrBrC�definitions_errors�s	z"ValidationError.definitions_errorscCs|jr|jdSdSdS)z8 Field of the contextual mapping, possibly :obj:`None`. r
N���)r:)rArBrBrC�field�s	zValidationError.fieldcCst|jtj@�S)z* ``True`` for errors of bulk validations. )�boolr<�ERROR_GROUP)rArBrBrCrP�szValidationError.is_group_errorcCst|jtjtj@�S)zV ``True`` for validation errors against different schemas with
            *of-rules. )r\r<�LOGICALr])rArBrBrCrR�szValidationError.is_logic_errorcCst|jtj@�S)z$ ``True`` for normalization errors. )r\r<�
NORMALIZATION)rArBrBrC�is_normalization_error�sz&ValidationError.is_normalization_errorN)rL�
__module__�__qualname__�__doc__rDrGrHrIrO�propertyrQrYr[rPrRr`rBrBrBrCr9\sr9c@s"eZdZdZdd�ZdS)�	ErrorListz� A list for :class:`~cerberus.errrors.ValidationError` instances that
        can be queried with the ``in`` keyword for a particular error code. cCs5x.dd�|D�D]}||jkrdSqWdS)Ncss|]}|jVqdS)N)r<)�.0�xrBrBrC�	<genexpr>�sz)ErrorList.__contains__.<locals>.<genexpr>TF)r<)rAZerror_definitionr<rBrBrC�__contains__�szErrorList.__contains__N)rLrarbrcrirBrBrBrCre�srec@s�eZdZdZdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zdd�Zdd�ZdS) �
ErrorTreeNode�descendants�errors�parent_node�path�	tree_rootcCsN||_|jj|_|d|jjd�|_t�|_i|_dS)Nr
)rmro�depthrnrerlrk)rArnrmrBrBrCrD�s
	zErrorTreeNode.__init__cCs|j|�|S)N)�add)rArWrBrBrC�__add__�s
zErrorTreeNode.__add__cCs|j|=dS)N)rk)rA�keyrBrBrC�__delitem__�szErrorTreeNode.__delitem__cCs
t|j�S)N)�iterrl)rArBrBrC�__iter__�szErrorTreeNode.__iter__cCs|jj|�S)N)rk�get)rA�itemrBrBrC�__getitem__�szErrorTreeNode.__getitem__cCs
t|j�S)N)rTrl)rArBrBrC�__len__�szErrorTreeNode.__len__cCs||j|<dS)N)rk)rArsr?rBrBrC�__setitem__�szErrorTreeNode.__setitem__cCst|j�dt|j�S)N�,)�strrlrk)rArBrBrC�__str__�szErrorTreeNode.__str__cCs
t|j�S)N)rTrn)rArBrBrCrp�szErrorTreeNode.depthcCs
|jjS)N)ro�	tree_type)rArBrBrCr�szErrorTreeNode.tree_typecCs�|j|�}||j}||jkr>t||�||<t|�|jdkr�||jj|�||jj�|jr�x1|j	D]}|j
|7_
q�Wn|||7<dS)Nr
)�	_path_of_rprkrjrTrlrU�sortrPrQro)rArWZ
error_pathrs�child_errorrBrBrCrq�s
	zErrorTreeNode.addcCst||jd�S)N�_path)�getattrr)rArWrBrBrCr�szErrorTreeNode._path_of_N)rkrlrmrnro)rLrarb�	__slots__rDrrrtrvryrzr{r~rdrprrqr�rBrBrBrCrj�srjcsOeZdZdZgdd�Z�fdd�Zdd�Zdd	�Z�S)
�	ErrorTreezs Base class for :class:`~cerberus.errors.DocumentErrorTree` and
        :class:`~cerberus.errors.SchemaErrorTree`. cCsOd|_||_f|_t�|_i|_x|D]}||7}q7WdS)N)rmrornrerlrk)rArlrWrBrBrCrDs				
zErrorTree.__init__csI|j|�s/|jj|�|jj�ntt|�j|�dS)zd Add an error to the tree.

        :param error: :class:`~cerberus.errors.ValidationError`
        N)r�rlrUr��superr�rq)rArW)rKrBrCrqsz
ErrorTree.addcCs-|j|�}|dk	r"|jSt�SdS)z� Returns all errors for a particular path.

        :param path: :class:`tuple` of :term:`hashable` s.
        :rtype: :class:`~cerberus.errors.ErrorList`
        N)�fetch_node_fromrlre)rArn�noderBrBrC�fetch_errors_fromszErrorTree.fetch_errors_fromcCs2|}x%|D]}||}|dkr
Pq
W|S)z� Returns a node for a path.

        :param path: Tuple of :term:`hashable` s.
        :rtype: :class:`~cerberus.errors.ErrorTreeNode` or :obj:`None`
        NrB)rArn�contextrsrBrBrCr�(s

zErrorTree.fetch_node_from)rLrarbrcrDrqr�r�rBrB)rKrCr�s
	r�c@seZdZdZdZdS)�DocumentErrorTreezr Implements a dict-like class to query errors by indexes following the
        structure of a validated document. ZdocumentN)rLrarbrcrrBrBrBrCr�6sr�c@seZdZdZdZdS)�SchemaErrorTreezm Implements a dict-like class to query errors by indexes following the
        structure of the used schema. rN)rLrarbrcrrBrBrBrCr�<sr�c@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�BaseErrorHandlerzo Base class for all error handlers.
        Subclasses are identified as error-handlers with an instance-test. cOsdS)z' Optionally initialize a new instance. NrB)rA�args�kwargsrBrBrCrDEszBaseErrorHandler.__init__cCs
t�dS)a$ Returns errors in a handler-specific format.

        :param errors: An object containing the errors.
        :type errors: :term:`iterable` of
                      :class:`~cerberus.errors.ValidationError` instances or a
                      :class:`~cerberus.Validator` instance
        N)�NotImplementedError)rArlrBrBrC�__call__IszBaseErrorHandler.__call__cCs
t�dS)z7 Be a superhero and implement an iterator over errors. N)r�)rArBrBrCrvSszBaseErrorHandler.__iter__cCs
t�dS)z� Add an error to the errors' container object of a handler.

        :param error: The error to add.
        :type error: :class:`~cerberus.errors.ValidationError`
        N)r�)rArWrBrBrCrqWszBaseErrorHandler.addcCsdS)z� Optionally emits an error in the handler's format to a stream.
            Or light a LED, or even shut down a power plant.

        :param error: The error to emit.
        :type error: :class:`~cerberus.errors.ValidationError`
        NrB)rArWrBrBrC�emit_szBaseErrorHandler.emitcCsdS)z� Gets called when a validation ends.

        :param validator: The calling validator.
        :type validator: :class:`~cerberus.Validator` NrB)rA�	validatorrBrBrC�endhszBaseErrorHandler.endcCs"x|D]}|j|�qWdS)z� Adds all errors to the handler's container object.

        :param errors: The errors to add.
        :type errors: :term:`iterable` of
                      :class:`~cerberus.errors.ValidationError` instances
        N)rq)rArlrWrBrBrC�extendos
zBaseErrorHandler.extendcCsdS)z� Gets called when a validation starts.

        :param validator: The calling validator.
        :type validator: :class:`~cerberus.Validator`
        NrB)rAr�rBrBrC�startyszBaseErrorHandler.startN)rLrarbrcrDr�rvrqr�r�r�r�rBrBrBrCr�Bs
	
r�c@s(eZdZdd�Zdd�ZdS)�ToyErrorHandlercOstd��dS)NzThis is not supposed to happen.)�RuntimeError)rAr�r�rBrBrCr��szToyErrorHandler.__call__cCsdS)NrB)rArBrBrC�clear�szToyErrorHandler.clearN)rLrarbr�r�rBrBrBrCr��sr�cs2t���fdd��}tdkr.|S�S)z�Cerberus error messages expect regular binary strings.
    If unicode is used in a ValidationError message can't be printed.

    This decorator ensures that if legacy Python is used unicode
    strings are encoded before passing to a function.
    csdd�}t|�}||j�|_||j�|_||j�|_||j�|_||j�|_�||�S)NcSs t|t�r|jd�S|S)z1Helper encoding unicode strings into binary utf-8zutf-8)�
isinstanceZunicode�encode)r?rBrBrC�_encode�s
z0encode_unicode.<locals>.wrapped.<locals>._encode)rr:r;r>r?r@)�objrWr�)�frBrC�wrapped�szencode_unicode.<locals>.wrappedr)rr
)r�r�rB)r�rC�encode_unicode�sr�cF@s�eZdZdZdddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d'd+d)d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d7d=d>d?d@dAdBdCdDi#ZdEdFdG�ZdEdHdI�ZdJdK�ZedLdM��Z	dNdO�Z
dPdQ�ZdRdS�ZdTdU�Z
dVdW�ZedXdY��ZdZd[�Zd\d]�ZdES)^�BasicErrorHandlerz3 Models cerberus' legacy. Returns a :class:`dict`. rz{0}r
zdocument is missingrzrequired fieldrz
unknown fieldrzfield '{0}' is requiredrz%depends on these values: {constraint}rz&{0} must not be present with '{field}'rz''{0}' is not a document, must be a dictrzempty values not allowedrznull value not allowedrzmust be of {constraint} typerzmust be of dict typerz0length of list should be {constraint}, it is {0}rzmin length is {constraint}rzmax length is {constraint}rz)value does not match regex '{constraint}'r zmin value is {constraint}r"zmax value is {constraint}r$zunallowed value {value}r%zunallowed values {0}r&r'r)z&field '{field}' cannot be coerced: {0}r*z&field '{field}' cannot be renamed: {0}r+zfield is read-onlyr-z.default value for '{field}' cannot be set: {0}r/z'mapping doesn't validate subschema: {0}r0z.one or more sequence-items don't validate: {0}r1z2one or more keys of a mapping  don't validate: {0}r2z3one or more values in a mapping don't validate: {0}�r5z one or more definitions validater6z#none or more than one rule validater7zno definitions validater8z&one or more definitions don't validateNcCs|dkrin||_dS)N)�tree)rAr�rBrBrCrD�szBasicErrorHandler.__init__cCs*|dk	r#|j�|j|�|jS)N)r�r��pretty_tree)rArlrBrBrCr��s

zBasicErrorHandler.__call__cCs
t|j�S)N)r	r�)rArBrBrCr~�szBasicErrorHandler.__str__cCsj|jr|j|�nM|jr2|j|�n4|j|jkrf|j|j|j|j	|��dS)N)
rR�insert_logic_errorrP�insert_group_errorr<�messages�insert_errorr:�format_messager[)rArWrBrBrCrq�s		zBasicErrorHandler.addcCs
i|_dS)N)r�)rArBrBrCr��szBasicErrorHandler.clearcCs2|j|jj|jd|jd|d|j�S)Nr>r[r?)r�r<rJr@r>r?)rAr[rWrBrBrCr��sz BasicErrorHandler.format_messagecCs|d}t|�dkrn||jkrX|j|j�}|j|||g7<q|ig|j|<n�t|�dkr||jkr�ig|j|<|j|d}|r�|jdt|��}n|j�}|j|dd�|�|j|j�dS)z� Adds an error or sub-tree to :attr:tree.

        :param path: Path to the error.
        :type path: Tuple of strings and integers.
        :param node: An error message or a sub-tree.
        :type node: String or dictionary.
        rr
r�NrZ)rTr��poprKrr��update)rArnr�r[�subtree�newrBrBrCr��s
zBasicErrorHandler.insert_errorcCslxe|jD]Z}|jr)|j|�q
|jrB|j|�q
|j|j|j|j|��q
WdS)N)	rQrRr�rPr�r�r:r�r[)rArWrBrBrCr�s		z$BasicErrorHandler.insert_group_errorcCs�|j|jf}|j}|j||j||��x�|jD]�}|j|}|s^qBd|j|f}xU|D]M}|jr�t�qx|jr�t�qx|j||f|j||��qxWqBWdS)Nz%s definition %s)	r:r=r[r�r�rYrRr�rP)rArWrnr[rXrQ�nodenamer�rBrBrCr�s	

				z$BasicErrorHandler.insert_logic_errorcCs5t|j�}x|D]}|j||�qW|S)N)rr��_purge_empty_dicts)rAZprettyr[rBrBrCr�*s
zBasicErrorHandler.pretty_treecCsG|d}|ds!|j�n"x|D]}|j||�q(WdS)Nr
rZrZ)r�r�)rAZ
error_listr�rsrBrBrCr�1s




z$BasicErrorHandler._purge_empty_dictscCs|j�dS)N)r�)rAr�rBrBrCr�9szBasicErrorHandler.start)rLrarbrcr�rDr�r~r�rqr�r�r�r�r�rdr�r�r�rBrBrBrCr��s`

r�c@s)eZdZejj�Zded<dS)�SchemaErrorHandlerzunknown rulerN)rLrarbr�r�rrBrBrBrCr�=sr�)HrcZ
__future__r�collectionsrrrrr�	functoolsr�pprintr	Zcerberus.platformr
Zcerberus.utilsrrZErrorDefinitionZCUSTOMZDOCUMENT_MISSINGZREQUIRED_FIELDZ
UNKNOWN_FIELDZDEPENDENCIES_FIELDZDEPENDENCIES_FIELD_VALUEZEXCLUDES_FIELDZDOCUMENT_FORMATZEMPTY_NOT_ALLOWEDZNOT_NULLABLEZBAD_TYPEZBAD_TYPE_FOR_SCHEMAZITEMS_LENGTHZ
MIN_LENGTHZ
MAX_LENGTHZREGEX_MISMATCHZ	MIN_VALUEZ	MAX_VALUEZUNALLOWED_VALUEZUNALLOWED_VALUESZFORBIDDEN_VALUEZFORBIDDEN_VALUESr_ZCOERCION_FAILEDZRENAMING_FAILEDZREADONLY_FIELDZSETTING_DEFAULT_FAILEDr]ZMAPPING_SCHEMAZSEQUENCE_SCHEMAZ	KEYSCHEMAZVALUESCHEMAZ	BAD_ITEMSr^ZNONEOFZONEOFZANYOFZALLOFZSCHEMA_ERROR_DEFINITION_TYPEZSCHEMA_ERROR_MISSING�objectr9rSrerjr�r�r�r�r�r�r�r�rBrBrBrC�<module>sz
c
<1@�