3 ;Xt@sddlmZmZddlZddlZddlZddlmZddlm Z m Z e ddgZ e Z ejZGdddeZGd d d eZGd d d eZGd ddeZGdddeZGdddeZGdddeZe e fddZeZefddZdS)) defaultdictdequeN)_utils)PY3 iteritemsZanyOfZoneOfc 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 rrrrrr rerror) __class__ /usr/lib/python3.6/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)rrrr8r9absolute_schema_path)rrr rrrr;hs  z_Error.absolute_schema_pathcKs4x.t|D]"\}}t||tkr t|||q WdS)N)rgetattrrsetattr)rkwargskvrrr_setrsz _Error._setc sd }tfd d |DS)Nr rrrrr r rrrc3s|]}|t|fVqdS)N)r<)r attr)rrrr"|sz#_Error._contents..) r rrrrr r rrr)dict)rattrsr)rrr4wsz_Error._contents)r __module__ __qualname__rr rr0rr3 classmethodr7propertyr:r;rAr4 __classcell__rr)rrrs&  rc@s eZdZdS)ValidationErrorN)rrErFrrrrrJsrJc@s eZdZdS) SchemaErrorN)rrErFrrrrrKsrKc@s eZdZdS)RefResolutionErrorN)rrErFrrrrrLsrLc@s.eZdZddZddZer"eZnddZdS) UnknownTypecCs||_||_||_dS)N)typerr)rrNrrrrrr 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,rNrr-)rr.r/rrrr0s zUnknownType.__unicode__cCst|jdS)Nzutf-8)r1r2)rrrrr3szUnknownType.__str__N)rrErFr r0rr3rrrrrMs  rMcs8eZdZdfdd ZddZer(eZnddZZS) FormatErrorNcs(tt|j||||_||_|_dS)N)rrOr r rr)rr r)rrrr szFormatError.__init__cCs|jS)N)r )rrrrr0szFormatError.__unicode__cCs |jjdS)Nzutf-8)r r2)rrrrr3szFormatError.__str__)N)rrErFr r0rr3rIrr)rrrOs rOc@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)errorsrrr4r rr _instance)rrQrZ containerelementrrrr s     zErrorTree.__init__cCs ||jkS)zD Check whether ``instance[index]`` has any errors. )r4)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`. )rRrr4)rrTrrr __getitem__s  zErrorTree.__getitem__cCs||j|<dS)N)r4)rrTvaluerrr __setitem__szErrorTree.__setitem__cCs t|jS)zZ Iterate (non-recursively) over the indices in the instance with errors. )iterr4)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 _Ztreerrrr"sz)ErrorTree.total_errors..)sumrr4r]rQ)rZ child_errorsrrrr[szErrorTree.total_errorsN)rrErF__doc__rrRr rUrVrXrZr\rrHr[rrrrrPs rPcsfdd}|S)Ncs |j}t|j |k|kfS)N)rr]r )rr)strongweakrr relevanceszby_relevance..relevancer)rbrarcr)rarbr by_relevancesrdcCsRt|}t|d}|dkrdSttj|g||d}x|jrLt|j|d}q6W|S)N)key)rYnextmax itertoolschainrmin)rQreZbestrrr best_match s rk) collectionsrrrhr(r*Z jsonschemarZjsonschema.compatrr frozensetZ WEAK_MATCHESZSTRONG_MATCHESZUnsetr ExceptionrrJrKrLrMrOobjectrPrdrcrkrrrrs$  oL