3 F\t@sddlmZmZddlZddlZddlZddlmZddlm Z m Z e ddgZ e Z ejZGdddeZGd d d eZGd d d eZGd ddeZGdddeZGdddeZGdddeZe e fddZeZefddZdS)) defaultdictdequeN)_utils)PY3 iteritemsZanyOfoneOfc seZdZefdfeeefdf fdd ZddZddZerBeZndd Ze d d Z e d d Z e ddZ ddZddZZS)_ErrorNc stt|j||||||||| | ||_t||_|_t| |_|_t ||_ ||_ |_ ||_ ||_||_||_| |_x|D] } || _qWdS)N)superr__init__messagerpath relative_path schema_pathrelative_schema_pathlistcontextcause __cause__ validatorvalidator_valueinstanceschemaparent) selfr rr rrrrrrrerror) __class__q/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/jsonschema/jsonschema/exceptions.pyr s.    z_Error.__init__cCsd|jj|jfS)Nz<%s: %r>)r__name__r )rrrr__repr__8sz_Error.__repr__cCs|j|j|j|jf}tdd|Dr,|jStj|jdd}tj|jdd}|jtj dj |jt j t |jddt j|t j |jt j|fS)Ncss|]}|tkVqdS)N)_unset).0mrrr ?sz%_Error.__unicode__..H)widthzv Failed validating %r in schema%s: %s On instance%s: %s )rrrranyr pprintpformattextwrapdedentrstriprZformat_as_indexrrindentr )rZessential_for_verbosepschema pinstancerrr __unicode__;s z_Error.__unicode__cCst|jdS)Nzutf-8)unicodeencode)rrrr__str__Wsz_Error.__str__cCs|f|jS)N) _contents)clsotherrrr create_fromZsz_Error.create_fromcCs2|j}|dkr|jSt|j}|jt|j|S)N)rr r extendleftreversed absolute_path)rrr rrrr;^s  z_Error.absolute_pathcCs2|j}|dkr|jSt|j}|jt|j|S)N)rrrr9r:absolute_schema_path)rrr rrrr<hs  z_Error.absolute_schema_pathcKs4x.t|D]"\}}t||tkr t|||q WdS)N)rgetattrr setattr)rkwargskvrrr_setrsz _Error._setc sd }tfd d |DS)Nr rrrrr rrrrc3s|]}|t|fVqdS)N)r=)r!attr)rrrr#|sz#_Error._contents..) r rrrrr rrrr)dict)rattrsr)rrr5wsz_Error._contents)r __module__ __qualname__r r rr1rr4 classmethodr8propertyr;r<rBr5 __classcell__rr)rrrs&  rc@s eZdZdS)ValidationErrorN)rrFrGrrrrrKsrKc@s eZdZdS) SchemaErrorN)rrFrGrrrrrLsrLc@s eZdZdS)RefResolutionErrorN)rrFrGrrrrrMsrMc@s.eZdZddZddZer"eZnddZdS) UnknownTypecCs||_||_||_dS)N)typerr)rrOrrrrrr szUnknownType.__init__cCsFtj|jdd}tj|jdd}tjdj|jtj |tj |fS)Nr$)r%z Unknown type %r for validator with schema: %s While checking instance: %s ) r)r*rrr+r,r-rOrr.)rr/r0rrrr1s zUnknownType.__unicode__cCst|jdS)Nzutf-8)r2r3)rrrrr4szUnknownType.__str__N)rrFrGr r1rr4rrrrrNs  rNcs8eZdZdfdd ZddZer(eZnddZZS) FormatErrorNcs(tt|j||||_||_|_dS)N)r rPr r rr)rr r)rrrr szFormatError.__init__cCs|jS)N)r )rrrrr1szFormatError.__unicode__cCs |jjdS)Nzutf-8)r r3)rrrrr4szFormatError.__str__)N)rrFrGr r1rr4rJrr)rrrPs rPc@s\eZdZdZeZffddZddZddZdd Z d d Z d d Z ddZ e ddZdS) ErrorTreezG ErrorTrees make it easier to check which validations failed. cCsTi|_t|j|_x<|D]4}|}x|jD] }||}q(W||j|j<|j|_qWdS)N)errorsrrr5r rr _instance)rrRr containerelementrrrr s     zErrorTree.__init__cCs ||jkS)zD Check whether ``instance[index]`` has any errors. )r5)rindexrrr __contains__szErrorTree.__contains__cCs&|jtk r||kr|j||j|S)aY Retrieve the child tree one level down at the given ``index``. If the index is not in the instance that this tree corresponds to and is not known by this tree, whatever error would be raised by ``instance.__getitem__`` will be propagated (usually this is some subclass of :class:`LookupError`. )rSr r5)rrVrrr __getitem__s  zErrorTree.__getitem__cCs||j|<dS)N)r5)rrVvaluerrr __setitem__szErrorTree.__setitem__cCs t|jS)zZ Iterate (non-recursively) over the indices in the instance with errors. )iterr5)rrrr__iter__szErrorTree.__iter__cCs|jS)z0 Same as :attr:`total_errors`. ) total_errors)rrrr__len__szErrorTree.__len__cCsd|jjt|fS)Nz<%s (%s total errors)>)rrlen)rrrrrszErrorTree.__repr__cCs&tddt|jD}t|j|S)zU The total number of errors in the entire tree, including children. css|]\}}t|VqdS)N)r_)r!_treerrrr#sz)ErrorTree.total_errors..)sumrr5r_rR)rZ child_errorsrrrr]szErrorTree.total_errorsN)rrFrG__doc__r rSr rWrXrZr\r^rrIr]rrrrrQs rQcsfdd}|S)Ncs |j}t|j |k|kfS)N)rr_r )rr)strongweakrr relevanceszby_relevance..relevancer)rerdrfr)rdrer by_relevancesrgcCsRt|}t|d}|dkrdSttj|g||d}x|jrLt|j|d}q6W|S)N)key)r[nextmax itertoolschainrmin)rRrhbestrrr best_match s ro) collectionsrrrkr)r+Z jsonschemarZjsonschema.compatrr frozensetZ WEAK_MATCHESZSTRONG_MATCHESZUnsetr ExceptionrrKrLrMrNrPobjectrQrgrfrorrrrs$  oL