Your IP : 216.73.216.213


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.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_string�cerberus_errorz
code, ruleN�zdocument is missing��required���dependencies���excludes�!z''{0}' is not a document, must be a dict�"�empty�#�nullable�$�type�%�schema�&�items�'�	minlength�(�	maxlength�A�regex�B�min�C�max�D�allowed�E�F�	forbidden�G�`�a�coerce�b�rename_handler�c�readonly�d�default_setter�����	keyschema��valueschema����noneof��oneof��anyof��allofz0schema 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)�selfrMrNrOrPrQrRrS�rU�@/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)rT�otherrUrUrV�__eq__rszValidationError.__eq__cCs't|j�t|j�At|j�AS)z@ Expects that all other properties are transitively determined. )rXrMrNrO)rTrUrUrV�__hash__vszValidationError.__hash__cCs<|j|jkr%t|j|j�St|j|j�SdS)N)rMrrN)rTrYrUrUrV�__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} )�
class_name�memptrrMrNrOrQrRrS)�format�	__class__�__name__�hex�idrMrNrOrrQrRrS)rTrUrUrV�__repr__�s			zValidationError.__repr__cCs|jr|jdSdS)zX
        A list that contains the individual errors of a bulk validation error.
        rN)�is_group_errorrS)rTrUrUrV�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�listrfrN�len�append)rT�result�error�irUrUrV�definitions_errors�s	z"ValidationError.definitions_errorscCs|jr|jdSdSdS)z8 Field of the contextual mapping, possibly :obj:`None`. rN���)rM)rTrUrUrV�field�s	zValidationError.fieldcCst|jtj@�S)z* ``True`` for errors of bulk validations. )�boolrO�ERROR_GROUP)rTrUrUrVre�szValidationError.is_group_errorcCst|jtjtj@�S)zV ``True`` for validation errors against different schemas with
            *of-rules. )rqrO�LOGICALrr)rTrUrUrVrg�szValidationError.is_logic_errorcCst|jtj@�S)z$ ``True`` for normalization errors. )rqrO�
NORMALIZATION)rTrUrUrV�is_normalization_error�sz&ValidationError.is_normalization_errorN)ra�
__module__�__qualname__�__doc__rWrZr[r\rd�propertyrfrnrprergrurUrUrUrVrL\srLc@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)rO)�.0�xrUrUrV�	<genexpr>�sz)ErrorList.__contains__.<locals>.<genexpr>TF)rO)rT�error_definitionrOrUrUrV�__contains__�szErrorList.__contains__N)rarvrwrxrrUrUrUrVrz�srzc@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)r�r��depthr�rzr�r�)rTr�r�rUrUrVrW�s
	zErrorTreeNode.__init__cCs|j|�|S)N)�add)rTrlrUrUrV�__add__�s
zErrorTreeNode.__add__cCs|j|=dS)N)r�)rT�keyrUrUrV�__delitem__�szErrorTreeNode.__delitem__cCs
t|j�S)N)�iterr�)rTrUrUrV�__iter__�szErrorTreeNode.__iter__cCs|jj|�S)N)r��get)rT�itemrUrUrV�__getitem__�szErrorTreeNode.__getitem__cCs
t|j�S)N)rir�)rTrUrUrV�__len__�szErrorTreeNode.__len__cCs||j|<dS)N)r�)rTr�rRrUrUrV�__setitem__�szErrorTreeNode.__setitem__cCst|j�dt|j�S)N�,)�strr�r�)rTrUrUrV�__str__�szErrorTreeNode.__str__cCs
t|j�S)N)rir�)rTrUrUrVr��szErrorTreeNode.depthcCs
|jjS)N)r��	tree_type)rTrUrUrVr��szErrorTreeNode.tree_typecCs�|j|�}||j}||jkr>t||�||<t|�|jdkr�||jj|�||jj�|jr�x1|j	D]}|j
|7_
q�Wn|||7<dS)Nr)�	_path_of_r�r�r�rir�rj�sortrerfr�)rTrl�
error_pathr��child_errorrUrUrVr��s
	zErrorTreeNode.addcCst||jd�S)N�_path)�getattrr�)rTrlrUrUrVr�szErrorTreeNode._path_of_N)r�r�r�r�r�)rarvrw�	__slots__rWr�r�r�r�r�r�r�ryr�r�r�r�rUrUrUrVr��sr�csOeZdZdZgdd�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)r�r�r�rzr�r�)rTr�rlrUrUrVrWs				
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�r�rjr��superr�r�)rTrl)r`rUrVr�sz
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_fromr�rz)rTr��noderUrUrV�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`
        NrU)rTr��contextr�rUrUrVr�(s

zErrorTree.fetch_node_from)rarvrwrxrWr�r�r�rUrU)r`rVr�s
	r�c@seZdZdZdZdS)�DocumentErrorTreezr Implements a dict-like class to query errors by indexes following the
        structure of a validated document. �documentN)rarvrwrxr�rUrUrUrVr�6sr�c@seZdZdZdZdS)�SchemaErrorTreezm Implements a dict-like class to query errors by indexes following the
        structure of the used schema. rN)rarvrwrxr�rUrUrUrVr�<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. NrU)rT�args�kwargsrUrUrVrWEszBaseErrorHandler.__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)rTr�rUrUrV�__call__IszBaseErrorHandler.__call__cCs
t�dS)z7 Be a superhero and implement an iterator over errors. N)r�)rTrUrUrVr�SszBaseErrorHandler.__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�)rTrlrUrUrVr�WszBaseErrorHandler.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`
        NrU)rTrlrUrUrV�emit_szBaseErrorHandler.emitcCsdS)z� Gets called when a validation ends.

        :param validator: The calling validator.
        :type validator: :class:`~cerberus.Validator` NrU)rT�	validatorrUrUrV�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)r�)rTr�rlrUrUrV�extendos
zBaseErrorHandler.extendcCsdS)z� Gets called when a validation starts.

        :param validator: The calling validator.
        :type validator: :class:`~cerberus.Validator`
        NrU)rTr�rUrUrV�startyszBaseErrorHandler.startN)rarvrwrxrWr�r�r�r�r�r�r�rUrUrUrVr�Bs
	
r�c@s(eZdZdd�Zdd�ZdS)�ToyErrorHandlercOstd��dS)NzThis is not supposed to happen.)�RuntimeError)rTr�r�rUrUrVr��szToyErrorHandler.__call__cCsdS)NrU)rTrUrUrV�clear�szToyErrorHandler.clearN)rarvrwr�r�rUrUrUrVr��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)�
isinstance�unicode�encode)rRrUrUrV�_encode�s
z0encode_unicode.<locals>.wrapped.<locals>._encode)rrMrNrQrRrS)�objrlr�)�frUrV�wrapped�szencode_unicode.<locals>.wrappedr)rr
)r�r�rU)r�rV�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}rzdocument 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 typer z0length of list should be {constraint}, it is {0}r"zmin length is {constraint}r$zmax length is {constraint}r&z)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/r1r3z&field '{field}' cannot be coerced: {0}r5z&field '{field}' cannot be renamed: {0}r7zfield is read-onlyr9z.default value for '{field}' cannot be set: {0}r<z'mapping doesn't validate subschema: {0}r=z.one or more sequence-items don't validate: {0}r>z2one or more keys of a mapping  don't validate: {0}r@z3one or more values in a mapping don't validate: {0}�rDz one or more definitions validaterFz#none or more than one rule validaterHzno definitions validaterJz&one or more definitions don't validateNcCs|dkrin||_dS)N)�tree)rTr�rUrUrVrW�szBasicErrorHandler.__init__cCs*|dk	r#|j�|j|�|jS)N)r�r��pretty_tree)rTr�rUrUrVr��s

zBasicErrorHandler.__call__cCs
t|j�S)N)r	r�)rTrUrUrVr��szBasicErrorHandler.__str__cCsj|jr|j|�nM|jr2|j|�n4|j|jkrf|j|j|j|j	|��dS)N)
rg�insert_logic_errorre�insert_group_errorrO�messages�insert_errorrM�format_messagerp)rTrlrUrUrVr��s		zBasicErrorHandler.addcCs
i|_dS)N)r�)rTrUrUrVr��szBasicErrorHandler.clearcCs2|j|jj|jd|jd|d|j�S)NrQrprR)r�rOr_rSrQrR)rTrprlrUrUrVr��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.
        rrr�Nro)rir��popr`rr��update)rTr�r�rp�subtree�newrUrUrVr��s
zBasicErrorHandler.insert_errorcCslxe|jD]Z}|jr)|j|�q
|jrB|j|�q
|j|j|j|j|��q
WdS)N)	rfrgr�rer�r�rMr�rp)rTrlrUrUrVr�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)	rMrPrpr�r�rnrgr�re)rTrlr�rprmrf�nodenamer�rUrUrVr�s	

				z$BasicErrorHandler.insert_logic_errorcCs5t|j�}x|D]}|j||�qW|S)N)rr��_purge_empty_dicts)rT�prettyrprUrUrVr�*s
zBasicErrorHandler.pretty_treecCsG|d}|ds!|j�n"x|D]}|j||�q(WdS)Nrroro)r�r�)rT�
error_listr�r�rUrUrVr�1s




z$BasicErrorHandler._purge_empty_dictscCs|j�dS)N)r�)rTr�rUrUrVr�9szBasicErrorHandler.start)rarvrwrxr�rWr�r�r�r�r�r�r�r�r�ryr�r�r�rUrUrUrVr��s`

r�c@s)eZdZejj�Zded<dS)�SchemaErrorHandlerzunknown rulerN)rarvrwr�r�rrUrUrUrVr�=sr�)Hrx�
__future__r�collectionsrrrrr�	functoolsr�pprintr	�cerberus.platformr
�cerberus.utilsrr�ErrorDefinition�CUSTOM�DOCUMENT_MISSING�REQUIRED_FIELD�
UNKNOWN_FIELD�DEPENDENCIES_FIELD�DEPENDENCIES_FIELD_VALUE�EXCLUDES_FIELD�DOCUMENT_FORMAT�EMPTY_NOT_ALLOWED�NOT_NULLABLE�BAD_TYPE�BAD_TYPE_FOR_SCHEMA�ITEMS_LENGTH�
MIN_LENGTH�
MAX_LENGTH�REGEX_MISMATCH�	MIN_VALUE�	MAX_VALUE�UNALLOWED_VALUE�UNALLOWED_VALUES�FORBIDDEN_VALUE�FORBIDDEN_VALUESrt�COERCION_FAILED�RENAMING_FAILED�READONLY_FIELD�SETTING_DEFAULT_FAILEDrr�MAPPING_SCHEMA�SEQUENCE_SCHEMA�	KEYSCHEMA�VALUESCHEMA�	BAD_ITEMSrs�NONEOF�ONEOF�ANYOF�ALLOF�SCHEMA_ERROR_DEFINITION_TYPE�SCHEMA_ERROR_MISSING�objectrLrhrzr�r�r�r�r�r�r�r�r�rUrUrUrV�<module>sz
c
<1@�