B e]t@sddlmZmZddlZddlZddlZddlmZddlm Z m Z e ddgZ e Z eZGdddeZGd d d eZGd d d eZGd ddeZGdddeZGdddeZGdddeZe e fddZeZefddZdS)) defaultdictdequeN)_utils)PY3 iteritemsZanyOfoneOfc seZdZedddeeeddf fdd ZddZddZerBeZnd d Ze d d Z e d dZ e ddZ ddZddZZS)_ErrorNc stt|||||||||| | ||_t||_|_t| |_|_t ||_ ||_ |_ ||_ ||_||_||_| |_x|D] } || _qWdS)N)superr__init__messagerpath relative_path schema_pathrelative_schema_pathlistcontextcause __cause__ validatorvalidator_valueinstanceschemaparent) selfr rr rrrrrrrerror) __class__r =/tmp/pip-install-b8evvk6i/jsonschema/jsonschema/exceptions.pyr s.    z_Error.__init__cCsd|jj|jfS)Nz<%s: %r>)r__name__r )rr r r__repr__8sz_Error.__repr__c Cs|j|j|j|jf}tdd|Dr,|jStj|jdd}tj|jdd}|jt d |jt t |jddt |t |jt |fS)Ncss|]}|tkVqdS)N)_unset).0mr r r ?sz%_Error.__unicode__..H)widthzv Failed validating %r in schema%s: %s On instance%s: %s )rrrranyr pprintpformattextwrapdedentrstriprZformat_as_indexrrindentr)rZessential_for_verbosepschema pinstancer r r __unicode__;s z_Error.__unicode__cCst|dS)Nzutf-8)unicodeencode)rr r r__str__Wsz_Error.__str__cCs|f|S)N) _contents)clsotherr r r create_fromZsz_Error.create_fromcCs2|j}|dkr|jSt|j}|t|j|S)N)rrr extendleftreversed absolute_path)rrr r r rr:^s  z_Error.absolute_pathcCs2|j}|dkr|jSt|j}|t|j|S)N)rrrr8r9absolute_schema_path)rrr r r rr;hs  z_Error.absolute_schema_pathcKs4x.t|D]"\}}t||tkr t|||q WdS)N)rgetattrr setattr)rkwargskvr r r_setrsz _Error._setcsd}tfdd|DS)N) r rrrrr rrrrc3s|]}|t|fVqdS)N)r<)r!attr)rr rr#|sz#_Error._contents..)dict)rattrsr )rrr4wsz_Error._contents)r __module__ __qualname__r r rr0rr3 classmethodr7propertyr:r;rAr4 __classcell__r r )rrrs&  rc@s eZdZdS)ValidationErrorN)rrErFr r r rrJsrJc@s eZdZdS) SchemaErrorN)rrErFr r r rrKsrKc@s eZdZdS)RefResolutionErrorN)rrErFr r r rrLsrLc@s.eZdZddZddZer"eZnddZdS) UnknownTypecCs||_||_||_dS)N)typerr)rrNrrr r rr szUnknownType.__init__cCsFtj|jdd}tj|jdd}td|jt |t |fS)Nr$)r%z Unknown type %r for validator with schema: %s While checking instance: %s ) r(r)rrr*r+r,rNrr-)rr.r/r r rr0s zUnknownType.__unicode__cCst|dS)Nzutf-8)r1r2)rr r rr3szUnknownType.__str__N)rrErFr r0rr3r r r rrMs  rMcs8eZdZdfdd ZddZer(eZnddZZS) FormatErrorNcs(tt|||||_||_|_dS)N)r rOr r rr)rr r)rr rr szFormatError.__init__cCs|jS)N)r )rr r rr0szFormatError.__unicode__cCs |jdS)Nzutf-8)r r2)rr r rr3szFormatError.__str__)N)rrErFr r0rr3rIr r )rrrOs rOc@sZeZdZdZeZdddZddZddZd d Z d d Z d dZ ddZ e ddZdS) ErrorTreezG ErrorTrees make it easier to check which validations failed. r cCsTi|_t|j|_x<|D]4}|}x|jD] }||}q(W||j|j<|j|_qWdS)N)errorsrrr4r rr _instance)rrQr containerelementr r rr s     zErrorTree.__init__cCs ||jkS)zD Check whether ``instance[index]`` has any errors. )r4)rindexr r r __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`. )rRr r4)rrUr r r __getitem__s  zErrorTree.__getitem__cCs||j|<dS)N)r4)rrUvaluer r r __setitem__szErrorTree.__setitem__cCs t|jS)zZ Iterate (non-recursively) over the indices in the instance with errors. )iterr4)rr r r__iter__szErrorTree.__iter__cCs|jS)z0 Same as :attr:`total_errors`. ) total_errors)rr r r__len__szErrorTree.__len__cCsd|jjt|fS)Nz<%s (%s total errors)>)rrlen)rr r rrszErrorTree.__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!_treer r rr#sz)ErrorTree.total_errors..)sumrr4r^rQ)rZ child_errorsr r rr\szErrorTree.total_errorsN)r )rrErF__doc__r rRr rVrWrYr[r]rrHr\r r r rrPs rPcsfdd}|S)Ncs |j}t|j |k|kfS)N)rr^r )rr)strongweakr r relevanceszby_relevance..relevancer )rdrcrer )rcrdr by_relevancesrfcCsRt|}t|d}|dkrdStt|g||d}x|jrLt|j|d}q6W|S)N)key)rZnextmax itertoolschainrmin)rQrgbestr r r best_match s rn) collectionsrrrjr(r*Z jsonschemarZjsonschema.compatrr frozensetZ WEAK_MATCHESZSTRONG_MATCHESZUnsetr ExceptionrrJrKrLrMrOobjectrPrfrernr r r rs$  oL