L iS@dZddlmZddlZddlmZmZddlmZmZddl m Z ddl m Z ddl mZdd lmZmZed d Z eddZed dZd ZeddZeddZeddZeddZeddZeddZdZeddZeddZeddZeddZed d!Zed"d#Z ed$d%Z!ed&d'Z"ed(d)Z#ed*d+Z$ed,d-Z%ed.d-Z&ed/d0Z'ed1d0Z(ed2d3Z)ed4dZ*ed5d6Z+ed7d8Z,ed9d:Z-ed;d<Z.ed=dZ/ed>dZ0ed?dZ1ed@dAxZ2Z3edBdCxZ4Z5edDd!Z6edEdZ7edFdGZ8edHdIZ9edJdKZ:edLdMZ; dNZZ?GdRdSe@ZAGdTdUeZBGdVdWeBZCGdXdYeCZDGdZd[eCZEGd\d]e>ZFGd^d_eFZGd`ZHGdadbeFZIGdcddeIZJy)ez=This module contains the error-related constants and classes.)absolute_importN) defaultdict namedtuple)copydeepcopy)wraps)pformat)MutableMapping)compare_paths_lt quote_stringErrorDefinitionz code, ruledocument is missingrequired dependenciesexcludes!''{0}' is not a document, must be a dict"empty#nullable$type%schema&items' minlength( maxlengthAregexBminCmaxDallowedEF forbiddenGHcontains`acoercebrename_handlercreadonlyddefault_setter keysrules valuesrulesnoneofoneofanyofallofz0schema definition for field '{0}' must be a dictzvalidation schema missingceZdZdZdZdZdZdZdZe dZ e dZ e d Z e d Z e d Ze d Zy )ValidationErrorz:A simple class to store and query basic error information.cr||_ ||_ ||_ ||_ ||_ ||_ ||_yN) document_path schema_pathcoderule constraintvalueinfo)selfrTrUrVrWrXrYrZs U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/cerberus/errors.py__init__zValidationError.__init___sP* %& % ? 4$+ &  %c0t|t|k(S)z:Assumes the errors relate to the same document and schema.)hashr[others r\__eq__zValidationError.__eq__rsDzT%[((r^ct|jt|jz t|jz S)z>Expects that all other properties are transitively determined.)r`rTrUrVr[s r\__hash__zValidationError.__hash__vs0D&&'$t/?/?*@@4 ?RRr^c|j|jk7r t|j|jSt|j|jSrS)rTr rUras r\__lt__zValidationError.__lt__zsH   !4!4 4#D$6$68K8KL L#D$4$4e6G6GH Hr^c .dj|jjtt ||j |j t|jt|jt|j|jS)Nz{class_name} @ {memptr} ( document_path={document_path},schema_path={schema_path},code={code},constraint={constraint},value={value},info={info} )) class_namememptrrTrUrVrXrYrZ) format __class____name__hexidrTrUrVr rXrYrZres r\__repr__zValidationError.__repr__sq  #F>>222d8}"00 ,,^'8"4::.YY#  r^c<|jr|jdSdS)zX A list that contains the individual errors of a bulk validation error. rN)is_group_errorrZres r\ child_errorszValidationError.child_errorss $22tyy|<z)ErrorList.__contains__..s7Q166[(7s) isinstancer TypeErrorrVany)r[error_definitionrs @r\ __contains__zErrorList.__contains__s/*O<O&++ 7$777r^N)rnrrrrrr^r\rrs  8r^rcreZdZdZdZdZdZdZdZdZ dZ d Z d Z e d Ze d Zd ZdZy) ErrorTreeNode) descendantserrors parent_nodepath tree_rootc||_|jj|_|d|jjdz|_t |_i|_yNr)rrdepthrrrr)r[rrs r\r]zErrorTreeNode.__init__sN&))3354++11A56 k r^cZt|tr||jvS||jvSrS)rr rr)r[items r\rzErrorTreeNode.__contains__s, dO ,4;;& &4+++ +r^c|j|=yrSr)r[keys r\ __delitem__zErrorTreeNode.__delitem__s   S !r^c,t|jSrS)iterrres r\__iter__zErrorTreeNode.__iter__sDKK  r^ct|tr/|jD]}|j|jk(s|cSy|jj |SrS)rr rrVrget)r[rr{s r\ __getitem__zErrorTreeNode.__getitem__sP dO , !99 * L !##''- -r^c,t|jSrS)rxrres r\__len__zErrorTreeNode.__len__s4;;r^c"|jSrS)__str__res r\rqzErrorTreeNode.__repr__s||~r^c"||j|<yrSr)r[rrYs r\ __setitem__zErrorTreeNode.__setitem__s %r^c^t|jdzt|jzS)N,)strrrres r\rzErrorTreeNode.__str__s&4;;#%D,<,<(===r^c,t|jSrS)rxrres r\rzErrorTreeNode.depths499~r^c.|jjSrS)r tree_typeres r\rzErrorTreeNode.tree_types~~'''r^c|j|}||j}||jvrt||||<||}t ||jdzk(ro|j j ||j j|jr-|jD]}|jj|yy|j|yr) _path_of_rrrrxrrysortrsrtradd)r[r{ error_pathrnode child_errors r\rzErrorTreeNode.adds^^E* $ d&& &%j$7DICy z?djj1n , KK  u % KK   ###(#5#54KNN&&{34$ HHUOr^c4t||jdzS)N_path)getattrrr[r{s r\rzErrorTreeNode._path_of_sudnnw677r^N)rnrr __slots__r]rrrrrrqrrrrrrrrr^r\rrsfMI, "!. &>(($8r^rc6eZdZdZddZfdZdZdZxZS) ErrorTreezw Base class for :class:`~cerberus.errors.DocumentErrorTree` and :class:`~cerberus.errors.SchemaErrorTree`. cd|_||_d|_t|_i|_|D]}|j |y)Nr)rrrrrrrr[rr{s r\r]zErrorTree.__init__!sC k  E HHUO r^c|j|s6|jj||jjytt ||y)zl Add an error to the tree. :param error: :class:`~cerberus.errors.ValidationError` N)rrryrsuperrr)r[r{rms r\rz ErrorTree.add*sB ~~e$ KK  u % KK    )T &u -r^cT|j|}| |jStS)z Returns all errors for a particular path. :param path: :class:`tuple` of :term:`hashable` s. :rtype: :class:`~cerberus.errors.ErrorList` )fetch_node_fromrr)r[rrs r\fetch_errors_fromzErrorTree.fetch_errors_from6s,##D)  ;; ; r^c,|}|D] }||}| |S|S)z Returns a node for a path. :param path: Tuple of :term:`hashable` s. :rtype: :class:`~cerberus.errors.ErrorTreeNode` or :obj:`None` r)r[rcontextrs r\rzErrorTree.fetch_node_fromCs5 CclG  r^)r) rnrrrr]rrr __classcell__)rms@r\rrs  .  r^rceZdZdZdZy)DocumentErrorTreezv Implements a dict-like class to query errors by indexes following the structure of a validated document. documentNrnrrrrrr^r\rrRs Ir^rceZdZdZdZy)SchemaErrorTreezq Implements a dict-like class to query errors by indexes following the structure of the used schema. r!Nrrr^r\rr[s Ir^rc@eZdZdZdZdZdZdZdZdZ dZ d Z y ) BaseErrorHandlerziBase class for all error handlers. Subclasses are identified as error-handlers with an instance-test.cy)z%Optionally initialize a new instance.Nrr[argskwargss r\r]zBaseErrorHandler.__init__hs r^ct)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 NotImplementedErrorr[rs r\__call__zBaseErrorHandler.__call__ls "!r^ct)z5Be a superhero and implement an iterator over errors.rres r\rzBaseErrorHandler.__iter__ws!!r^ct)z Add an error to the errors' container object of a handler. :param error: The error to add. :type error: :class:`~cerberus.errors.ValidationError` rrs r\rzBaseErrorHandler.add{s "!r^cy)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` Nrrs r\emitzBaseErrorHandler.emits r^cy)z Gets called when a validation ends. :param validator: The calling validator. :type validator: :class:`~cerberus.Validator` Nrr[ validators r\endzBaseErrorHandler.end r^c4|D]}|j|y)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)rrs r\extendzBaseErrorHandler.extends E HHUO r^cy)z Gets called when a validation starts. :param validator: The calling validator. :type validator: :class:`~cerberus.Validator` Nrrs r\startzBaseErrorHandler.startrr^N) rnrrrr]rrrrrrrrr^r\rrds0J  """    r^rceZdZdZdZy)ToyErrorHandlerctd)NzThis is not supposed to happen.) RuntimeErrorrs r\rzToyErrorHandler.__call__s<==r^cyrSrres r\clearzToyErrorHandler.clears r^N)rnrrrrrr^r\rrs > r^rcXtfd}tjdkr|SS)zCerberus 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. cd}t|}||j|_||j|_||j|_||j|_||j |_||S)NcHt|tr|jdS|S)z1Helper encoding unicode strings into binary utf-8zutf-8)runicodeencode)rYs r\_encodez0encode_unicode..wrapped.._encodes %)||G,,Lr^)rrTrUrXrYrZ)objr{rfs r\wrappedzencode_unicode..wrappedsx  U %e&9&9:#E$5$56"5#3#34ekk* UZZ( e}r^)r)rsys version_info)rrs` r\encode_unicoders5 1X  &&-7414r^cdeZdZdZidddddddd d d d d ddddddddddddddddddd d!d"d#id$d%d&d'd(d)d*d'd+d)d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd9d?d@dAdBdCdDdEZdVdGZdHZdIZedJZ e dKZ dLZ dMZ dNZdOZdPZdQZdRZdWdSZdWdTZdWdUZyF)XBasicErrorHandlerz Models cerberus' legacy. Returns a :class:`dict`. When mangled through :class:`str` a pretty-formatted representation of that tree is returned. rz{0}rrrzrequired fieldrz unknown fieldrzfield '{0}' is requiredrz%depends on these values: {constraint}rz&{0} must not be present with '{field}'rrrzempty values not allowedrznull value not allowedrzmust be of {constraint} typer zmust be of dict typer"z'length of list should be {0}, it is {1}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}r0zunallowed values {0}r1r3r4zmissing members {0}r7z&field '{field}' cannot be coerced: {0}r9z&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}rAz.one or more sequence-items don't validate: {0}rBz2one or more keys of a mapping don't validate: {0}rDz3one or more values in a mapping don't validate: {0}rHz one or more definitions validaterJz#none or more than one rule validatezno definitions validatez&one or more definitions don't validate)rLrNNc&|i|_y||_yrStree)r[r s r\r]zBasicErrorHandler.__init__s,B D r^c\|j|j||jSrS)rr pretty_treers r\rzBasicErrorHandler.__call__s#  Fr^c,t|jSrS)r r res r\rzBasicErrorHandler.__str__st''((r^cft|j}|D]}|j|||SrS)rr _purge_empty_dicts)r[prettyrs r\r zBasicErrorHandler.pretty_trees6$))$ 3E  # #F5M 2 3 r^cRt|}|j||jr|j|y|jr|j |y|j |jvr7|j|j|j|j|yyrS) r_rewrite_error_pathrv_insert_logic_errorrs_insert_group_errorrVmessages _insert_errorrT_format_messagerrs r\rzBasicErrorHandler.adds   '     $ $U +  ! !  $ $U + ZZ4== (   ##T%9%9%++u%M )r^ci|_yrSr res r\rzBasicErrorHandler.clears  r^c$|jyrS)rrs r\rzBasicErrorHandler.start"s  r^c|j|jj|j|j||j dS)N)rXrrY)rrVrlrZrXrY)r[rr{s r\rz!BasicErrorHandler._format_message%s;/t}}UZZ(// ZZE$4$4E  r^c|d}t|dk(rW||jvr7|j|j}|j|xx||gz cc<y|ig|j|<yt|dk\r||jvrig|j|<|j|d}|r|jt |}n|j}|j |dd||j |jyy)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. rrrr N)rxr poprmrrupdate)r[rrrsubtreenews r\rzBasicErrorHandler._insert_error*sQ t9> !))E*..0 % T7O3 $(": % Y!^DII%$&4 % ii&r*Gnn$w-n8nn&   d12h - NN388 $r^c |jD]t}|jr|j|!|jr|j |?|j |j |j|j|vyrS) rtrvrrsrrrTrr)r[r{rs r\rz%BasicErrorHandler._insert_group_errorFsr -- K))((5++((5""--(():):KH r^c |j}|j|j|j|||jj D]q}|D]j}|j r|j|!|jr|j|?|j|j|j||lsyrS) rrrTrr}valuesrvrrsr)r[r{rdefinition_errorsrs r\rz%BasicErrorHandler._insert_logic_errorRs  5..0D0DUE0RS!&!9!9!@!@!B  0  --,,[9 //,,[9&&#11,,UK@  r^cp|d}|ds|jy|D]}|j||y)Nr)rr)r[ error_listrrs r\rz$BasicErrorHandler._purge_empty_dictsbs=R."~ NN  6'' 5 6r^c|jr|j||y|jr|j||yy)zY Recursively rewrites the error path to correctly represent logic errors N)rv_rewrite_logic_error_pathrs_rewrite_group_error_path)r[r{offsets r\rz%BasicErrorHandler._rewrite_error_pathjs;     * *5& 9  ! !  * *5& 9"r^ct|j|z }|jD]7}|j|d}|j|z|_|j||9yrS)rxrTrtr)r[r{r) child_startr relative_paths r\r(z+BasicErrorHandler._rewrite_group_error_pathssa%--.7  -- :K'55klCM(-(;(;m(KK %  $ $[& 9  :r^c*t|j|z }|jjD]^\}}|s |jd|}|j|fz}|D]0}|j|d} || z|_|j ||dz2`y)Nz definition r)rxrTr}r#rWr) r[r{r)r+r|r#nodenamerrrel_paths r\r'z+BasicErrorHandler._rewrite_logic_error_path|s%--.7 $)$<$<$B$B$D B A $-2ZZ;H&&(4D0 B &44[\B,08O )((fqjA  B Br^rS)r)rnrrrrr]rrrr rrrrrrrrrrr(r'rr^r\rrsB % e% #% % o % ' % 5 % 6% 7% (% &% ,% $% 7% *% *% 9!%" )#%$ )%%& ''%( $)%* '+%, $-%. #/%0 61%2 63%4 "5%6 >7%8 79%: >;%< B=%> C?%@ >A%B 0C%D 3E%F(6I%HN1 )   %8  6::Br^rcJeZdZejj Zded<y)SchemaErrorHandlerz unknown rulerN)rnrrrrrrr^r\r1r1s ))..0H#HTNr^r1)Kr __future__rr collectionsrrrr functoolsrpprintr cerberus.platformr cerberus.utilsr r r CUSTOMDOCUMENT_MISSINGREQUIRED_FIELD UNKNOWN_FIELDDEPENDENCIES_FIELDDEPENDENCIES_FIELD_VALUEEXCLUDES_FIELDDOCUMENT_FORMATEMPTY_NOT_ALLOWED NOT_NULLABLEBAD_TYPEBAD_TYPE_FOR_SCHEMA ITEMS_LENGTH MIN_LENGTH MAX_LENGTHREGEX_MISMATCH MIN_VALUE MAX_VALUEUNALLOWED_VALUEUNALLOWED_VALUESFORBIDDEN_VALUEFORBIDDEN_VALUESMISSING_MEMBERSrCOERCION_FAILEDRENAMING_FAILEDREADONLY_FIELDSETTING_DEFAULT_FAILEDrMAPPING_SCHEMASEQUENCE_SCHEMA KEYSRULES KEYSCHEMA VALUESRULES VALUESCHEMA BAD_ITEMSrNONEOFONEOFANYOFALLOFSCHEMA_ERROR_DEFINITION_TYPESCHEMA_ERROR_MISSINGobjectrQrwrrrrrrrrrr1rr^r\rasC& /,9. = t $#4.( z2d+ $T>:*4@ z2"$-;#D'2tZ0 4 (%dH5tW- T; / T; / !w/ D% ( D% ( !$ 2"43!$ 4"45!$ 3 d+ !$1!$(89 z2(/?@dD)  x0!$1'k:: I+D-@@ k D' * $ % x (g&g&g&Q2e4fe4P 8 8F8NF8R4 4n iE vE P & 56{B({B|$*$r^