Ë Ô+¨j6œ²Dã ó0—dZdZdZddlZddlZddlmZej dkreZne Zd„Z e Z ejdejejz«Zejd ejejz«Zd Zd ezZ ed „Zd„ZGd„de«ZGd„de«ZGd„de«ZGd„de«ZGd„de«ZGd„de«ZGd„de«Z Gd„de«Z!Gd„d e«Z"Gd!„d"e«Z#Gd#„d$e$«Z%d@d&„Z&dAd'„Z'dAd(„Z(d)d)d)d)d)d%d%d%d%d%d*œ Z)d+„Z*d,„Z+dAd-„Z,dAd.„Z-dAd/„Z.dAd0„Z/dAd1„Z0dAd2„Z1dAd3„Z2dAd4„Z3dAd5„Z4e'e(e+e.e*d6œZ5d7„Z6d8„Z7d9„Z8d:„Z9d;„Z:e;d«\ZGZHeGrJd?j“eGeH««‚yy#e$rd „ZY�ŒˆwxYw)Ba The Validator object is used to check that supplied values conform to a specification. The value can be supplied as a string - e.g. from a config file. In this case the check will also *convert* the value to the required type. This allows you to add validation as a transparent layer to access data stored as strings. The validation checks that the data is correct *and* converts it to the expected type. Some standard checks are provided for basic data types. Additional checks are easy to write. They can be provided when the ``Validator`` is instantiated or added afterwards. The standard functions work with the following basic data types : * integers * floats * booleans * strings * ip_addr plus lists of these datatypes Adding additional checks is done through coding simple functions. The full set of standard checks are : * 'integer': matches integer values (including negative) Takes optional 'min' and 'max' arguments : :: integer() integer(3, 9) # any value from 3 to 9 integer(min=0) # any positive value integer(max=9) * 'float': matches float values Has the same parameters as the integer check. * 'boolean': matches boolean values - ``True`` or ``False`` Acceptable string values for True are : true, on, yes, 1 Acceptable string values for False are : false, off, no, 0 Any other value raises an error. * 'ip_addr': matches an Internet Protocol address, v.4, represented by a dotted-quad string, i.e. '1.2.3.4'. * 'string': matches any string. Takes optional keyword args 'min' and 'max' to specify min and max lengths of the string. * 'list': matches any list. Takes optional keyword args 'min', and 'max' to specify min and max sizes of the list. (Always returns a list.) * 'tuple': matches any tuple. Takes optional keyword args 'min', and 'max' to specify min and max sizes of the tuple. (Always returns a tuple.) * 'int_list': Matches a list of integers. Takes the same arguments as list. * 'float_list': Matches a list of floats. Takes the same arguments as list. * 'bool_list': Matches a list of boolean values. Takes the same arguments as list. * 'ip_addr_list': Matches a list of IP addresses. Takes the same arguments as list. * 'string_list': Matches a list of strings. Takes the same arguments as list. * 'mixed_list': Matches a list with different types in specific positions. List size must match the number of arguments. Each position can be one of : 'integer', 'float', 'ip_addr', 'string', 'boolean' So to specify a list with two strings followed by two integers, you write the check as : :: mixed_list('string', 'string', 'integer', 'integer') * 'pass': This check matches everything ! It never fails and the value is unchanged. It is also the default if no check is specified. * 'option': This check matches any from a list of options. You specify this check with : :: option('option 1', 'option 2', 'option 3') You can supply a default value (returned if no value is supplied) using the default keyword argument. You specify a list argument for default using a list constructor syntax in the check : :: checkname(arg1, arg2, default=list('val 1', 'val 2', 'val 3')) A badly formatted set of arguments will raise a ``VdtParamError``. z1.0.1)Ú __version__ÚdottedQuadToNumÚnumToDottedQuadÚ ValidateErrorÚVdtUnknownCheckErrorÚ VdtParamErrorÚ VdtTypeErrorÚ VdtValueErrorÚVdtValueTooSmallErrorÚVdtValueTooBigErrorÚVdtValueTooShortErrorÚVdtValueTooLongErrorÚVdtMissingValueÚ ValidatorÚ is_integerÚis_floatÚ is_booleanÚis_listÚis_tupleÚ is_ip_addrÚ is_stringÚ is_int_listÚ is_bool_listÚ is_float_listÚis_string_listÚis_ip_addr_listÚ is_mixed_listÚ is_optionéN)Úpprint)écó—|S©N©)Úxs ú7/usr/lib/python3.12/site-packages/configobj/validate.pyÚr&³s€™óa¢ (?: ([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*list\( ( (?: \s* (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s\)][^,\)]*?) # unquoted ) \s*,\s* )* (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s\)][^,\)]*?) # unquoted )? # last one ) \) ) zÕ ( (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s=][^,=]*?) # unquoted ) (?: (?:\s*,\s*)|(?:\s*$) # comma ) a� (?: ( (?: [a-zA-Z_][a-zA-Z0-9_]*\s*=\s*list\( (?: \s* (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s\)][^,\)]*?) # unquoted ) \s*,\s* )* (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s\)][^,\)]*?) # unquoted )? # last one \) )| (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s=][^,=]*?)| # unquoted (?: # keyword argument [a-zA-Z_][a-zA-Z0-9_]*\s*=\s* (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\s=][^,=]*?) # unquoted ) ) ) ) (?: (?:\s*,\s*)|(?:\s*$) # comma ) ) z^%s*có —|ryy)z$Simple boolean equivalent function. érr#)Úvals r%Úboolr+ s €á Øàr'cóº—ddl}ddl} |jd|j|j «««dS#|j $rt d|z«‚wxYw)aÍ Convert decimal dotted quad string to long integer >>> int(dottedQuadToNum('1 ')) 1 >>> int(dottedQuadToNum(' 1.2')) 16777218 >>> int(dottedQuadToNum(' 1.2.3 ')) 16908291 >>> int(dottedQuadToNum('1.2.3.4')) 16909060 >>> dottedQuadToNum('255.255.255.255') 4294967295 >>> dottedQuadToNum('255.255.255.256') Traceback (most recent call last): ValueError: Not a good dotted-quad IP: 255.255.255.256 rNú!LzNot a good dotted-quad IP: %s)ÚsocketÚstructÚunpackÚ inet_atonÚstripÚerrorÚ ValueError)Úipr.r/s r%rrs_€÷(ð?Ø�}‰}˜TØ × Ñ ˜RŸX™X›ZÓ (ó*Ø*+ñ-ð -øà �<‰<ò?ÜÐ8¸2Ñ=Ó>Ð>ð?ús Š1<¼Acó—ddl}ddl}|td«kDs|dkrtd|z«‚ |j |j dt|«««S#|j |j tf$rtd|z«‚wxYw)a! Convert int or long int to dotted quad string >>> numToDottedQuad(long(-1)) Traceback (most recent call last): ValueError: Not a good numeric IP: -1 >>> numToDottedQuad(long(1)) '0.0.0.1' >>> numToDottedQuad(long(16777218)) '1.0.0.2' >>> numToDottedQuad(long(16908291)) '1.2.0.3' >>> numToDottedQuad(long(16909060)) '1.2.3.4' >>> numToDottedQuad(long(4294967295)) '255.255.255.255' >>> numToDottedQuad(long(4294967296)) Traceback (most recent call last): ValueError: Not a good numeric IP: 4294967296 >>> numToDottedQuad(-1) Traceback (most recent call last): ValueError: Not a good numeric IP: -1 >>> numToDottedQuad(1) '0.0.0.1' >>> numToDottedQuad(16777218) '1.0.0.2' >>> numToDottedQuad(16908291) '1.2.0.3' >>> numToDottedQuad(16909060) '1.2.3.4' >>> numToDottedQuad(4294967295) '255.255.255.255' >>> numToDottedQuad(4294967296) Traceback (most recent call last): ValueError: Not a good numeric IP: 4294967296 rNlÿÿzNot a good numeric IP: %sr-)r.r/Úlongr4Ú inet_ntoaÚpackr3Ú OverflowError)Únumr.r/s r%rr/s‡€÷Pð ŒT�*Ó Ò  q¢ÜÐ4°sÑ:Ó;Ð;ð<Ø×ÑØ �K‰K˜œd 3›iÓ (ó*ð *øà �L‰L˜&Ÿ,™,¬ Ð 6ò<ÜÐ4°sÑ:Ó;Ð;ð<ús «)AÁ/Bcó—eZdZdZy)ra This error indicates that the check failed. It can be the base class for more specific errors. Any check function that fails ought to raise this error. (or a subclass) >>> raise ValidateError Traceback (most recent call last): ValidateError N©Ú__name__Ú __module__Ú __qualname__Ú__doc__r#r'r%rrcs„ò r'rcó—eZdZdZy)rz1No value was supplied to a check that needed one.Nr=r#r'r%rrqs„Ú;r'rcó—eZdZdZd„Zy)rz'An unknown check function was requestedcó8—tj|d|›d�«y)zž >>> raise VdtUnknownCheckError('yoda') Traceback (most recent call last): VdtUnknownCheckError: the check "yoda" is unknown. z the check "z " is unknown.N©rÚ__init__©ÚselfÚvalues r%rFzVdtUnknownCheckError.__init__xó€ô ×Ñ™tÂUÐ%LÕMr'N©r>r?r@rArFr#r'r%rrus „Ù1óNr'rcó—eZdZdZd„Zy)rz!An incorrect parameter was passedcó>—tj|d|›d|›d�«y)z² >>> raise VdtParamError('yoda', 'jedi') Traceback (most recent call last): VdtParamError: passed an incorrect value "jedi" for parameter "yoda". zpassed an incorrect value "z" for parameter "z".N)Ú SyntaxErrorrF)rHÚnamerIs r%rFzVdtParamError.__init__„s€ô ×Ñ™TÒ[`ÒbfÐ#gÕhr'NrKr#r'r%rr�s „Ù+óir'rcó—eZdZdZd„Zy)rz(The value supplied was of the wrong typecó8—tj|d|›d�«y)z˜ >>> raise VdtTypeError('jedi') Traceback (most recent call last): VdtTypeError: the value "jedi" is of the wrong type. ú the value "z" is of the wrong type.NrErGs r%rFzVdtTypeError.__init__�s€ô ×Ñ™tÊuÐ%VÕWr'NrKr#r'r%rr�s „Ù2óXr'rcó—eZdZdZd„Zy)r zIThe value supplied was of the correct type, but was not an allowed value.có8—tj|d|›d�«y)z• >>> raise VdtValueError('jedi') Traceback (most recent call last): VdtValueError: the value "jedi" is unacceptable. rRz" is unacceptable.NrErGs r%rFzVdtValueError.__init__œs€ô ×Ñ™tÊ%Ð%QÕRr'NrKr#r'r%r r ™s „ÙSóSr'r có—eZdZdZd„Zy)r z>The value supplied was of the correct type, but was too small.có8—tj|d|›d�«y)zœ >>> raise VdtValueTooSmallError('0') Traceback (most recent call last): VdtValueTooSmallError: the value "0" is too small. rRz" is too small.NrErGs r%rFzVdtValueTooSmallError.__init__¨s€ô ×Ñ™tÂuÐ%NÕOr'NrKr#r'r%r r ¥s „ÙHóPr'r có—eZdZdZd„Zy)r z>> raise VdtValueTooBigError('1') Traceback (most recent call last): VdtValueTooBigError: the value "1" is too big. rRz " is too big.NrErGs r%rFzVdtValueTooBigError.__init__´rJr'NrKr#r'r%r r ±s „ÙFóNr'r có—eZdZdZd„Zy)r z>The value supplied was of the correct type, but was too short.có8—tj|d|›d�«y)z  >>> raise VdtValueTooShortError('jed') Traceback (most recent call last): VdtValueTooShortError: the value "jed" is too short. rRz" is too short.NrErGs r%rFzVdtValueTooShortError.__init__Às€ô ×ÑÙ Ú.3Ð 5õ 7r'NrKr#r'r%r r ½s „ÙHó7r'r có—eZdZdZd„Zy)r z=The value supplied was of the correct type, but was too long.có8—tj|d|›d�«y)z¡ >>> raise VdtValueTooLongError('jedie') Traceback (most recent call last): VdtValueTooLongError: the value "jedie" is too long. rRz" is too long.NrErGs r%rFzVdtValueTooLongError.__init__Îs€ô ×Ñ™tÂeÐ%MÕNr'NrKr#r'r%r r Ës „ÙGóOr'r cót—eZdZdZej dej «Zej dej «Ze Z e Z ej e ejej z«Z ej eejej z«Zdd„Zdd„Zd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zy)ra3 Validator is an object that allows you to register a set of 'checks'. These checks take input and test that it conforms to the check. This can also involve converting the value from a string into the correct datatype. The ``check`` method takes an input string which configures which check is to be used and applies that check to a supplied value. An example input string would be: 'int_range(param1, param2)' You would then provide something like: >>> def int_range_check(value, min, max): ... # turn min and max from strings to integers ... min = int(min) ... max = int(max) ... # check that value is of the correct type. ... # possible valid inputs are integers or strings ... # that represent integers ... if not isinstance(value, (int, long, string_type)): ... raise VdtTypeError(value) ... elif isinstance(value, string_type): ... # if we are given a string ... # attempt to convert to an integer ... try: ... value = int(value) ... except ValueError: ... raise VdtValueError(value) ... # check the value is between our constraints ... if not min <= value: ... raise VdtValueTooSmallError(value) ... if not value <= max: ... raise VdtValueTooBigError(value) ... return value >>> fdict = {'int_range': int_range_check} >>> vtr1 = Validator(fdict) >>> vtr1.check('int_range(20, 40)', '30') 30 >>> vtr1.check('int_range(20, 40)', '60') Traceback (most recent call last): VdtValueTooBigError: the value "60" is too big. New functions can be added with : :: >>> vtr2 = Validator() >>> vtr2.functions['int_range'] = int_range_check Or by passing in a dictionary of functions when Validator is instantiated. Your functions *can* use keyword arguments, but the first argument should always be 'value'. If the function doesn't take additional arguments, the parentheses are optional in the check. It can be written with either of : :: keyword = function_name keyword = function_name() The first program to utilise Validator() was Michael Foord's ConfigObj, an alternative to ConfigParser which supports lists and can validate a config file using a config schema. For more details on using Validator with ConfigObj see: https://configobj.readthedocs.org/en/latest/configobj.html z([^\(\)]+?)\((.*)\)z%^([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.*)$Ncóv—id|j“dt“dt“dt“dt“dt “dt “dt“d t“d t“d t“d t“d t“dt“d|j“dt“dt“|_|�|j j#|«t$|_i|_y)z( >>> vtri = Validator() ÚÚintegerÚfloatÚbooleanÚip_addrÚstringÚlistÚtupleÚint_listÚ float_listÚ bool_listÚ ip_addr_listÚ string_listÚ mixed_listÚpassÚoptionÚ force_listN)Ú_passrrrrrrrrrrrrrrroÚ functionsÚupdaterÚbaseErrorClassÚ_cache)rHrqs r%rFzValidator.__init__2s€ð Ø �— ‘ ð à ”zð ð ”Xð ð ”zð  ð ”zð  ð ”ið  ð ”Gð ð ”Xð ð œ ð ð œ-ð ð œð ð œOð ð œ>ð ð œ-ð ð �D—J‘Jð ð ”ið! ð" œ*ð# ˆŒð& Ð Ø �N‰N× !Ñ ! )Ô ,ä+ˆÔ؈� r'cóš—|j|«\}}}}|r|€ t«‚|j|«}|€y|j||||«S)a´ Usage: check(check, value) Arguments: check: string representing check to apply (including arguments) value: object to be checked Returns value, converted to correct type if necessary If the check fails, raises a ``ValidateError`` subclass. >>> vtor.check('yoda', '') Traceback (most recent call last): VdtUnknownCheckError: the check "yoda" is unknown. >>> vtor.check('yoda()', '') Traceback (most recent call last): VdtUnknownCheckError: the check "yoda" is unknown. >>> vtor.check('string(default="")', '', missing=True) '' N)Ú_parse_with_cachingrÚ _handle_noneÚ _check_value)rHÚcheckrIÚmissingÚfun_nameÚfun_argsÚ fun_kwargsÚdefaults r%ryzValidator.checkPs]€ð*37×2JÑ2JÈ5Ó2QÑ/ˆ�(˜J¨á ؈ä%Ó'Ð'Ø×%Ñ% gÓ.ˆEà ˆ=Øà× Ñ  ¨°(¸JÓGÐGr'có<—|dk(ry|dvr|j|«}|S)NÚNone©z'None'z"None")Ú_unquoterGs r%rwzValidator._handle_noness(€Ø �FŠ?ØØ Ð*Ñ *à—M‘M %Ó(ˆE؈ r'c ó‚—||jvr+|j|\}}}}t|«}t|«}n{|j|«\}}}}tt|j ««D��cgc]\}}t |«|f‘Œc}}«}|t|«t|«|f|j|<||||fScc}}wr")rtreÚdictÚ _parse_checkÚitemsÚstr)rHryr{r|r}r~ÚkeyrIs r%rvzValidator._parse_with_caching|s¾€Ø �D—K‘KÑ Ø6:·k±kÀ%Ñ6HÑ 3ˆH�h  ¨Gô˜H“~ˆHܘjÓ)‰Jà6:×6GÑ6GÈÓ6NÑ 3ˆH�h  ¨GÜÄTÈ*×JZÑJZÓJ\ÔE]Ô^ÑE]±\°c¸5¤ C£¨%Ò0ÐE]Ò^Ó_ˆJØ!)¬4°«>¼4À Ó;KÈWÐ!TˆD�K‰K˜Ñ ؘ :¨wÐ6Ð6ùó_sÁ1B; cój— |j|}||g|¢­i|¤ŽS#t$r t|«‚wxYwr")rqÚKeyErrorr)rHrIr{r|r}Úfuns r%rxzValidator._check_valueŠsH€ð 7Ø—.‘. Ñ*ˆCñ�uÐ6˜xÒ6¨:Ñ6Ð 6øôò 1Ü& xÓ0Ð 0ð 1ús‚�2cóÜ—|jj|«}|�r1|jd«}|jd«}|jj|«}|€t d|z«‚g}i}|j j |«D]Á}|j«}|jj|«} | r|j| «\} } | || <ŒJ|jj|«} | r;| jd«} | dvr|j| «} | || jd«<Œ¢|j|j|««ŒÃn|didfS|jdd«} |||| fS)Nr)ézBad syntax in check "%s".r�r#r~)Ú_func_reÚmatchÚgroupÚ _matchfinderrÚ _paramfinderÚfindallr2Ú _list_argÚ _list_handleÚ_key_argr‚ÚappendÚpop)rHryÚ fun_matchr{Ú arg_stringÚ arg_matchr|r}ÚargÚ listmatchrˆr*Úkeymatchr~s r%r…zValidator._parse_check“sb€Ø—M‘M×'Ñ'¨Ó.ˆ Ú Ø —‘ qÓ)ˆHØ"Ÿ™¨Ó+ˆJØ×)Ñ)×/Ñ/° Ó;ˆIØÐ ä#Ð$?À%Ñ$GÓHÐH؈H؈Jà×(Ñ(×0Ñ0°Ö<�à—i‘i“k�Ø ŸN™N×0Ñ0°Ó5� ÙØ#×0Ñ0°Ó;‘H�C˜Ø&)�J˜s‘OØØŸ=™=×.Ñ.¨sÓ3�ÙØ"Ÿ.™.¨Ó+�CØÐ"6Ñ6à"Ÿm™m¨CÓ0˜Ø47�J˜xŸ~™~¨aÓ0Ñ1Øà—‘ § ¡ ¨cÓ 2Õ3ñ#=ð(˜"˜b $Ð&Ð &ð—.‘. ¨DÓ1ˆØ˜ :¨wÐ6Ð6r'cóP—t|«dk\r|ddvr|d|dk(r|dd}|S)zUnquote a value if necessary.r�r)Ú'Ú"éÿÿÿÿr))Úlen)rHr*s r%r‚zValidator._unquote»s7€ä �‹H˜ŠM  A¡¨*Ñ 4¸3¸q¹6ÀSÈÁWÒ;LØ�a˜�)ˆC؈ r'cóÒ—g}|jd«}|jd«}|jj|«D]"}|j|j |««Œ$||fS)z7Take apart a ``keyword=list('val, 'val')`` type string.r)r�)r�Ú _list_membersr“r—r‚)rHr�ÚoutrOÚargsrœs r%r•zValidator._list_handleÂs]€àˆØ�‰˜qÓ!ˆØ�‰˜qÓ!ˆØ×%Ñ%×-Ñ-¨dÖ3ˆCØ �J‰J�t—}‘} SÓ)Õ *ð4à�SˆyÐr'có—|S)z� Dummy check that always passes >>> vtor.check('', 0) 0 >>> vtor.check('', '0') '0' r#rGs r%rpzValidator._passÌs €ðˆ r'có —|j|«\}}}}|€td|z«‚|j|«}|€|S|j||||«S)zØ Given a check, return the default value for the check (converted to the right type). If the check doesn't specify a default value then a ``KeyError`` will be raised. z Check "%s" has no default value.)rvrŠrwrx)rHryr{r|r}r~rIs r%Úget_default_valuezValidator.get_default_valueØsd€ð37×2JÑ2JÈ5Ó2QÑ/ˆ�(˜J¨Ø ˆ?ÜÐ=ÀÑEÓFÐ FØ×!Ñ! 'Ó*ˆØ ˆ=؈LØ× Ñ  ¨°(¸JÓGÐGr'r"©F)r>r?r@rAÚreÚcompileÚDOTALLrŽr–r”r¥Ú _paramstringÚVERBOSEr’Ú _matchstringr‘rFryrwrvrxr…r‚r•rprªr#r'r%rr×s¿„ñEðPˆr�z‰zÐ0°"·)±)Ó<€Hðˆr�z‰zÐBÀRÇYÁYÓO€Hð€Ið"€Mð�2—:‘:˜l¨B¯J©J¸¿¹Ñ,BÓC€LØ�2—:‘:˜l¨B¯J©J¸¿¹Ñ,BÓC€Lóó< HòFò 7ò7ò%7òPòò óHr'rFcó@—|xrtxst}g}t||«D]]\}}|€|j|«Œt |tt tt f«r |j||««ŒSt||«‚|S#t$r}t||«‚d}~wwxYw)aÖ Return numbers from inputs or raise VdtParamError. Lets ``None`` pass through. Pass in keyword argument ``to_float=True`` to use float for the conversion rather than int. >>> _is_num_param(('', ''), (0, 1.0)) [0, 1] >>> _is_num_param(('', ''), (0, 1.0), to_float=True) [0.0, 1.0] >>> _is_num_param(('a'), ('a')) Traceback (most recent call last): VdtParamError: passed an incorrect value "a" for parameter "a". N) raÚintÚzipr—Ú isinstancer7Ú string_typer4r)ÚnamesÚvaluesÚto_floatr‹Ú out_paramsrOr*Úes r%Ú _is_num_paramr¼és €ð Ò ”uÒ #¤€CØ€Jܘ5 &Ö)‰ ˆˆsØ ˆ;Ø × Ñ ˜cÕ "Ü ˜œc¤4¬´ Ð<Ô =ð /Ø×!Ñ!¡# c£(Õ+ô   cÓ*Ð *ð*ð Ðøô ò /Ü# D¨#Ó.Ð.ûð /úsÁB B BÂBcó$—td||f«\}}t|tttf«s t |«‚t|t«r t|«}|�||kr t|«‚|�||kDr t|«‚|S#t $r t |«‚wxYw)aH A check that tests that a given value is an integer (int, or long) and optionally, between bounds. A negative value is accepted, while a float will fail. If the value is a string, then the conversion is done - if possible. Otherwise a VdtError is raised. >>> vtor.check('integer', '-1') -1 >>> vtor.check('integer', '0') 0 >>> vtor.check('integer', 9) 9 >>> vtor.check('integer', 'a') Traceback (most recent call last): VdtTypeError: the value "a" is of the wrong type. >>> vtor.check('integer', '2.2') Traceback (most recent call last): VdtTypeError: the value "2.2" is of the wrong type. >>> vtor.check('integer(10)', '20') 20 >>> vtor.check('integer(max=20)', '15') 15 >>> vtor.check('integer(10)', '9') Traceback (most recent call last): VdtValueTooSmallError: the value "9" is too small. >>> vtor.check('integer(10)', 9) Traceback (most recent call last): VdtValueTooSmallError: the value "9" is too small. >>> vtor.check('integer(max=20)', '35') Traceback (most recent call last): VdtValueTooBigError: the value "35" is too big. >>> vtor.check('integer(max=20)', 35) Traceback (most recent call last): VdtValueTooBigError: the value "35" is too big. >>> vtor.check('integer(0, 9)', False) 0 ©ÚminÚmax) r¼rµr³r7r¶rr4r r ©rIr¿rÀÚmin_valÚmax_vals r%rrsŸ€ôP' ~¸¸S°zÓBÑ€WˆgÜ �eœc¤4¬Ð5Ô 6ܘ5Ó!Ð!Ü�%œÔ%ð &ܘ“JˆEð Р%¨'¢/Ü# EÓ*Ð*ØÐ %¨'¢/Ü! %Ó(Ð(Ø €Løô ò &ܘuÓ%Ð %ð &ús Á A:Á:Bcó2—td||fd¬«\}}t|tttt f«s t |«‚t|t«s t |«}|�||kr t|«‚|�||kDr t|«‚|S#t$r t |«‚wxYw)a< A check that tests that a given value is a float (an integer will be accepted), and optionally - that it is between bounds. If the value is a string, then the conversion is done - if possible. Otherwise a VdtError is raised. This can accept negative values. >>> vtor.check('float', '2') 2.0 From now on we multiply the value to avoid comparing decimals >>> vtor.check('float', '-6.8') * 10 -68.0 >>> vtor.check('float', '12.2') * 10 122.0 >>> vtor.check('float', 8.4) * 10 84.0 >>> vtor.check('float', 'a') Traceback (most recent call last): VdtTypeError: the value "a" is of the wrong type. >>> vtor.check('float(10.1)', '10.2') * 10 102.0 >>> vtor.check('float(max=20.2)', '15.1') * 10 151.0 >>> vtor.check('float(10.0)', '9.0') Traceback (most recent call last): VdtValueTooSmallError: the value "9.0" is too small. >>> vtor.check('float(max=20.0)', '35.0') Traceback (most recent call last): VdtValueTooBigError: the value "35.0" is too big. r¾T)r¹) r¼rµr³r7rar¶rr4r r rÁs r%rrFs¦€ôF'ؘ˜c˜ ¨Tô3Ñ€Wˆgä �eœc¤4¬´ Ð<Ô =ܘ5Ó!Ð!Ü �eœUÔ #ð &ܘ%“LˆEð Р%¨'¢/Ü# EÓ*Ð*ØÐ %¨'¢/Ü! %Ó(Ð(Ø €Løô ò &ܘuÓ%Ð %ð &ús Á BÂBT) TÚonÚ1ÚtrueÚyesFÚoffÚ0ÚfalseÚnocó°—t|t«r t|j«S|dk(ry|dk(ryt |«‚#t$r t |«‚wxYw)aÞ Check if the value represents a boolean. >>> vtor.check('boolean', 0) 0 >>> vtor.check('boolean', False) 0 >>> vtor.check('boolean', '0') 0 >>> vtor.check('boolean', 'off') 0 >>> vtor.check('boolean', 'false') 0 >>> vtor.check('boolean', 'no') 0 >>> vtor.check('boolean', 'nO') 0 >>> vtor.check('boolean', 'NO') 0 >>> vtor.check('boolean', 1) 1 >>> vtor.check('boolean', True) 1 >>> vtor.check('boolean', '1') 1 >>> vtor.check('boolean', 'on') 1 >>> vtor.check('boolean', 'true') 1 >>> vtor.check('boolean', 'yes') 1 >>> vtor.check('boolean', 'Yes') 1 >>> vtor.check('boolean', 'YES') 1 >>> vtor.check('boolean', '') Traceback (most recent call last): VdtTypeError: the value "" is of the wrong type. >>> vtor.check('boolean', 'up') Traceback (most recent call last): VdtTypeError: the value "up" is of the wrong type. FT)rµr¶Ú bool_dictÚlowerrŠr©rIs r%rr€sb€ôX�%œÔ%ð &ܘUŸ[™[›]Ñ+Ð +ð  �‚~ØØ �$ŠØä˜5Ó!Ð!øôò &ܘuÓ%Ð %ð &ús ’AÁAcó¤—t|t«s t|«‚|j«} t |«|S#t $r t |«‚wxYw)as Check that the supplied value is an Internet Protocol address, v.4, represented by a dotted-quad string, i.e. '1.2.3.4'. >>> vtor.check('ip_addr', '1 ') '1' >>> vtor.check('ip_addr', ' 1.2') '1.2' >>> vtor.check('ip_addr', ' 1.2.3 ') '1.2.3' >>> vtor.check('ip_addr', '1.2.3.4') '1.2.3.4' >>> vtor.check('ip_addr', '0.0.0.0') '0.0.0.0' >>> vtor.check('ip_addr', '255.255.255.255') '255.255.255.255' >>> vtor.check('ip_addr', '255.255.255.256') Traceback (most recent call last): VdtValueError: the value "255.255.255.256" is unacceptable. >>> vtor.check('ip_addr', '1.2.3.4.5') Traceback (most recent call last): VdtValueError: the value "1.2.3.4.5" is unacceptable. >>> vtor.check('ip_addr', 0) Traceback (most recent call last): VdtTypeError: the value "0" is of the wrong type. )rµr¶rr2rr4r rÐs r%rr¼sT€ô6 �eœ[Ô )ܘ5Ó!Ð!Ø �K‰K‹M€Eð#ܘÔð €Løô ò#ܘEÓ"Ð"ð#ús ­ :ºAcó—td||f«\}}t|t«r t|«‚ t |«}|�||kr t |«‚|�||kDr t|«‚t|«S#t $r t|«‚wxYw)aÈ Check that the value is a list of values. You can optionally specify the minimum and maximum number of members. It does no check on list members. >>> vtor.check('list', ()) [] >>> vtor.check('list', []) [] >>> vtor.check('list', (1, 2)) [1, 2] >>> vtor.check('list', [1, 2]) [1, 2] >>> vtor.check('list(3)', (1, 2)) Traceback (most recent call last): VdtValueTooShortError: the value "(1, 2)" is too short. >>> vtor.check('list(max=5)', (1, 2, 3, 4, 5, 6)) Traceback (most recent call last): VdtValueTooLongError: the value "(1, 2, 3, 4, 5, 6)" is too long. >>> vtor.check('list(min=3, max=5)', (1, 2, 3, 4)) [1, 2, 3, 4] >>> vtor.check('list', 0) Traceback (most recent call last): VdtTypeError: the value "0" is of the wrong type. >>> vtor.check('list', '12') Traceback (most recent call last): VdtTypeError: the value "12" is of the wrong type. r¾) r¼rµr¶rr£Ú TypeErrorr r re©rIr¿rÀÚmin_lenÚmax_lenÚ num_memberss r%rrás”€ô>' ~¸¸S°zÓBÑ€WˆgÜ�%œÔ%ܘ5Ó!Ð!ð"ܘ%“jˆ ðИ{¨WÒ4Ü# EÓ*Ð*ØÐ˜{¨WÒ4Ü" 5Ó)Ð)Ü �‹;Ðøô ò"ܘ5Ó!Ð!ð"ús ® A(Á(A=có.—tt|||««S)aÍ Check that the value is a tuple of values. You can optionally specify the minimum and maximum number of members. It does no check on members. >>> vtor.check('tuple', ()) () >>> vtor.check('tuple', []) () >>> vtor.check('tuple', (1, 2)) (1, 2) >>> vtor.check('tuple', [1, 2]) (1, 2) >>> vtor.check('tuple(3)', (1, 2)) Traceback (most recent call last): VdtValueTooShortError: the value "(1, 2)" is too short. >>> vtor.check('tuple(max=5)', (1, 2, 3, 4, 5, 6)) Traceback (most recent call last): VdtValueTooLongError: the value "(1, 2, 3, 4, 5, 6)" is too long. >>> vtor.check('tuple(min=3, max=5)', (1, 2, 3, 4)) (1, 2, 3, 4) >>> vtor.check('tuple', 0) Traceback (most recent call last): VdtTypeError: the value "0" is of the wrong type. >>> vtor.check('tuple', '12') Traceback (most recent call last): VdtTypeError: the value "12" is of the wrong type. )rfr©rIr¿rÀs r%rrs€ô> ”˜  SÓ)Ó *Ð*r'cóî—t|t«s t|«‚td||f«\}} t |«}|�||kr t |«‚|�||kDr t|«‚|S#t $r t|«‚wxYw)a¯ Check that the supplied value is a string. You can optionally specify the minimum and maximum number of members. >>> vtor.check('string', '0') '0' >>> vtor.check('string', 0) Traceback (most recent call last): VdtTypeError: the value "0" is of the wrong type. >>> vtor.check('string(2)', '12') '12' >>> vtor.check('string(2)', '1') Traceback (most recent call last): VdtValueTooShortError: the value "1" is too short. >>> vtor.check('string(min=2, max=3)', '123') '123' >>> vtor.check('string(min=2, max=3)', '1234') Traceback (most recent call last): VdtValueTooLongError: the value "1234" is too long. r¾)rµr¶rr¼r£rÓr r rÔs r%rr0s�€ô, �eœ[Ô )ܘ5Ó!Ð!Ü& ~¸¸S°zÓBÑ€Wˆgð"ܘ%“jˆ ðИ{¨WÒ4Ü# EÓ*Ð*ØÐ˜{¨WÒ4Ü" 5Ó)Ð)Ø €Løô ò"ܘ5Ó!Ð!ð"ús ® AÁA4cóT—t|||«D�cgc] }t|«‘Œc}Scc}w)a Check that the value is a list of integers. You can optionally specify the minimum and maximum number of members. Each list member is checked that it is an integer. >>> vtor.check('int_list', ()) [] >>> vtor.check('int_list', []) [] >>> vtor.check('int_list', (1, 2)) [1, 2] >>> vtor.check('int_list', [1, 2]) [1, 2] >>> vtor.check('int_list', [1, 'a']) Traceback (most recent call last): VdtTypeError: the value "a" is of the wrong type. )rr©rIr¿rÀÚmems r%rrTs+€ô((/¨u°c¸3Ô'?Ó @Ñ'? ŒJ�s�OÐ'?Ñ @Ð@ùÒ @ó�%cóT—t|||«D�cgc] }t|«‘Œc}Scc}w)al Check that the value is a list of booleans. You can optionally specify the minimum and maximum number of members. Each list member is checked that it is a boolean. >>> vtor.check('bool_list', ()) [] >>> vtor.check('bool_list', []) [] >>> check_res = vtor.check('bool_list', (True, False)) >>> check_res == [True, False] 1 >>> check_res = vtor.check('bool_list', [True, False]) >>> check_res == [True, False] 1 >>> vtor.check('bool_list', [True, 'a']) Traceback (most recent call last): VdtTypeError: the value "a" is of the wrong type. )rrrÜs r%rrks+€ô,(/¨u°c¸3Ô'?Ó @Ñ'? ŒJ�s�OÐ'?Ñ @Ð@ùÒ @rÞcóT—t|||«D�cgc] }t|«‘Œc}Scc}w)a Check that the value is a list of floats. You can optionally specify the minimum and maximum number of members. Each list member is checked that it is a float. >>> vtor.check('float_list', ()) [] >>> vtor.check('float_list', []) [] >>> vtor.check('float_list', (1, 2.0)) [1.0, 2.0] >>> vtor.check('float_list', [1, 2.0]) [1.0, 2.0] >>> vtor.check('float_list', [1, 'a']) Traceback (most recent call last): VdtTypeError: the value "a" is of the wrong type. )rrrÜs r%rr„s+€ô(&-¨U°C¸Ô%=Ó >Ñ%=˜cŒH�S�MÐ%=Ñ >Ð>ùÒ >rÞcóŠ—t|t«r t|«‚t|||«D�cgc] }t |«‘Œc}Scc}w)an Check that the value is a list of strings. You can optionally specify the minimum and maximum number of members. Each list member is checked that it is a string. >>> vtor.check('string_list', ()) [] >>> vtor.check('string_list', []) [] >>> vtor.check('string_list', ('a', 'b')) ['a', 'b'] >>> vtor.check('string_list', ['a', 1]) Traceback (most recent call last): VdtTypeError: the value "1" is of the wrong type. >>> vtor.check('string_list', 'hello') Traceback (most recent call last): VdtTypeError: the value "hello" is of the wrong type. )rµr¶rrrrÜs r%rr›s@€ô*�%œÔ%ܘ5Ó!Ð!Ü&-¨e°S¸#Ô&>Ó ?Ñ&>˜sŒI�c�NÐ&>Ñ ?Ð?ùÒ ?s«AcóT—t|||«D�cgc] }t|«‘Œc}Scc}w)a Check that the value is a list of IP addresses. You can optionally specify the minimum and maximum number of members. Each list member is checked that it is an IP address. >>> vtor.check('ip_addr_list', ()) [] >>> vtor.check('ip_addr_list', []) [] >>> vtor.check('ip_addr_list', ('1.2.3.4', '5.6.7.8')) ['1.2.3.4', '5.6.7.8'] >>> vtor.check('ip_addr_list', ['a']) Traceback (most recent call last): VdtValueError: the value "a" is unacceptable. )rrrÜs r%rrµs+€ô$(/¨u°c¸3Ô'?Ó @Ñ'? ŒJ�s�OÐ'?Ñ @Ð@ùÒ @rÞcóN—t|ttf«s|g}t|||«S)aé Check that a value is a list, coercing strings into a list with one member. Useful where users forget the trailing comma that turns a single value into a list. You can optionally specify the minimum and maximum number of members. A minumum of greater than one will fail if the user only supplies a string. >>> vtor.check('force_list', ()) [] >>> vtor.check('force_list', []) [] >>> vtor.check('force_list', 'hello') ['hello'] )rµrerfrrÙs r%roroÊs(€ô" �eœd¤E˜]Ô +Ø�ˆÜ �5˜#˜sÓ #Ð#r')r`rarcrdrbcóL— t|«}|t|«kr t|«‚|t|«kDr t |«‚ t ||«D��cgc]\}}t ||«‘Œc}}S#t$r t|«‚wxYwcc}}w#t$r}td|«‚d}~wwxYw)aà Check that the value is a list. Allow specifying the type of each member. Work on lists of specific lengths. You specify each member as a positional argument specifying type Each type should be one of the following strings : 'integer', 'float', 'ip_addr', 'string', 'boolean' So you can specify a list of two strings, followed by two integers as : mixed_list('string', 'string', 'integer', 'integer') The length of the list must match the number of positional arguments you supply. >>> mix_str = "mixed_list('integer', 'float', 'ip_addr', 'string', 'boolean')" >>> check_res = vtor.check(mix_str, (1, 2.0, '1.2.3.4', 'a', True)) >>> check_res == [1, 2.0, '1.2.3.4', 'a', True] 1 >>> check_res = vtor.check(mix_str, ('1', '2.0', '1.2.3.4', 'a', 'True')) >>> check_res == [1, 2.0, '1.2.3.4', 'a', True] 1 >>> vtor.check(mix_str, ('b', 2.0, '1.2.3.4', 'a', True)) Traceback (most recent call last): VdtTypeError: the value "b" is of the wrong type. >>> vtor.check(mix_str, (1, 2.0, '1.2.3.4', 'a')) Traceback (most recent call last): VdtValueTooShortError: the value "(1, 2.0, '1.2.3.4', 'a')" is too short. >>> vtor.check(mix_str, (1, 2.0, '1.2.3.4', 'a', 1, 'b')) Traceback (most recent call last): VdtValueTooLongError: the value "(1, 2.0, '1.2.3.4', 'a', 1, 'b')" is too long. >>> vtor.check(mix_str, 0) Traceback (most recent call last): VdtTypeError: the value "0" is of the wrong type. >>> vtor.check('mixed_list("yoda")', ('a')) Traceback (most recent call last): VdtParamError: passed an incorrect value "KeyError('yoda',)" for parameter "'mixed_list'" rlN) r£rÓrr r r´Úfun_dictrŠr)rIr§Úlengthrœr*r»s r%rrês¯€ðV"Ü�U“ˆð”�D“ ÒÜ# EÓ*Ð*Ø ”#�d“)Ò Ü" 5Ó)Ð)ð-Ü36°t¸UÔ3CÔDÑ3C¡x s¨C”˜‘ ˜cÕ"Ð3CÒDÐDøô ò"ܘ5Ó!Ð!ð"üóEøÜ ò-ܘL¨!Ó,Ð,ûð-ús5‚ A+ÁB ÁBÁ'B Á+BÂB  B# BÂB#cóZ—t|t«s t|«‚||vr t|«‚|S)a£ This check matches the value to any of a set of options. >>> vtor.check('option("yoda", "jedi")', 'yoda') 'yoda' >>> vtor.check('option("yoda", "jedi")', 'jed') Traceback (most recent call last): VdtValueError: the value "jed" is unacceptable. >>> vtor.check('option("yoda", "jedi")', 0) Traceback (most recent call last): VdtTypeError: the value "0" is of the wrong type. )rµr¶rr )rIÚoptionss r%rr#s1€ô �eœ[Ô )ܘ5Ó!Ð!Ø �GÑ Ü˜EÓ"Ð"Ø €Lr'có —|||fS)ag A function that exists for test purposes. >>> checks = [ ... '3, 6, min=1, max=3, test=list(a, b, c)', ... '3', ... '3, 6', ... '3,', ... 'min=1, test="a b c"', ... 'min=5, test="a, b, c"', ... 'min=1, max=3, test="a, b, c"', ... 'min=-100, test=-99', ... 'min=1, max=3', ... '3, 6, test="36"', ... '3, 6, test="a, b, c"', ... '3, max=3, test=list("a", "b", "c")', ... '''3, max=3, test=list("'a'", 'b', "x=(c)")''', ... "test='x=fish(3)'", ... ] >>> v = Validator({'test': _test}) >>> for entry in checks: ... pprint(v.check(('test(%s)' % entry), 3)) (3, ('3', '6'), {'max': '3', 'min': '1', 'test': ['a', 'b', 'c']}) (3, ('3',), {}) (3, ('3', '6'), {}) (3, ('3',), {}) (3, (), {'min': '1', 'test': 'a b c'}) (3, (), {'min': '5', 'test': 'a, b, c'}) (3, (), {'max': '3', 'min': '1', 'test': 'a, b, c'}) (3, (), {'min': '-100', 'test': '-99'}) (3, (), {'max': '3', 'min': '1'}) (3, ('3', '6'), {'test': '36'}) (3, ('3', '6'), {'test': 'a, b, c'}) (3, ('3',), {'max': '3', 'test': ['a', 'b', 'c']}) (3, ('3',), {'max': '3', 'test': ["'a'", 'b', 'x=(c)']}) (3, (), {'test': 'x=fish(3)'}) >>> v = Validator() >>> v.check('integer(default=6)', '3') 3 >>> v.check('integer(default=6)', None, True) 6 >>> v.get_default_value('integer(default=6)') 6 >>> v.get_default_value('float(default=6)') 6.0 >>> v.get_default_value('pass(default=None)') >>> v.get_default_value("string(default='None')") 'None' >>> v.get_default_value('pass') Traceback (most recent call last): KeyError: 'Check "pass" has no default value.' >>> v.get_default_value('pass(default=list(1, 2, 3, 4))') ['1', '2', '3', '4'] >>> v = Validator() >>> v.check("pass(default=None)", None, True) >>> v.check("pass(default='None')", None, True) 'None' >>> v.check('pass(default="None")', None, True) 'None' >>> v.check('pass(default=list(1, 2, 3, 4))', None, True) ['1', '2', '3', '4'] Bug test for unicode arguments >>> v = Validator() >>> v.check(unicode('string(min=4)'), unicode('test')) == unicode('test') True >>> v = Validator() >>> v.get_default_value(unicode('string(min=4, default="1234")')) == unicode('1234') True >>> v.check(unicode('string(min=4, default="1234")'), unicode('test')) == unicode('test') True >>> v = Validator() >>> default = v.get_default_value('string(default=None)') >>> default == None 1 r#)rIr§Úkeywargss r%Ú_testrë7s€ðb �4˜Ð "Ð"r'có—y)z¯ >>> >>> v = Validator() >>> v.get_default_value('string(default="#ff00dd")') '#ff00dd' >>> v.get_default_value('integer(default=3) # comment') 3 Nr#r#r'r%Ú_test2rí‹ó�r'có—y)a¢ >>> vtor.check('string(default="")', '', missing=True) '' >>> vtor.check('string(default="\n")', '', missing=True) '\n' >>> print(vtor.check('string(default="\n")', '', missing=True)) >>> vtor.check('string()', '\n') '\n' >>> vtor.check('string(default="\n\n\n")', '', missing=True) '\n\n\n' >>> vtor.check('string()', 'random \n text goes here\n\n') 'random \n text goes here\n\n' >>> vtor.check('string(default=" \nrandom text\ngoes \n here\n\n ")', ... '', missing=True) ' \nrandom text\ngoes \n here\n\n ' >>> vtor.check("string(default='\n\n\n')", '', missing=True) '\n\n\n' >>> vtor.check("option('\n','a','b',default='\n')", '', missing=True) '\n' >>> vtor.check("string_list()", ['foo', '\n', 'bar']) ['foo', '\n', 'bar'] >>> vtor.check("string_list(default=list('\n'))", '', missing=True) ['\n'] Nr#r#r'r%Ú_test3rð•rîr'Ú__main__Úvtor)ÚglobsÚ optionflagsz{} failures out of {} testsr«)NN)JrArÚ__all__r¬ÚsysrÚ version_infoÚ basestringr¶r‡Úunicoder³r7r­r°r®r”r¥r¯r±r+Ú NameErrorrrÚ ExceptionrrrrNrrr r r r r Úobjectrr¼rrrÎrrrrrrrrrrrorårrrërírðr>ÚdoctestÚmodulesÚgetÚmÚ__dict__ÚcopyrórrÚtestmodÚIGNORE_EXCEPTION_DETAILÚELLIPSISÚfailuresÚtestsÚformatr#r'r%Úr s¶ðñ"nð`€ ð €ó@ Û Ýð ×Ñ�dÒØ�Kà€Kñ €Gð €Dà ˆB�J‰Jðð*‡Z�Z�"—)‘)Ñó+ € ð.�— ‘ ð ð‡Z�Z�"—)‘)Ñó € ð'€ ðR˜ Ñ$€ ðÙò ò<1<ôh �Iô ô<�mô<ô N˜=ô Nô i�Kô iô X�=ô Xô S�Mô Sô P˜Mô Pô N˜-ô Nô 7˜Mô 7ô O˜=ô OôOH�ôOHódóJ5óp1ðj �d ¨t¸DØ ˜ U°UÀ%ñ € ò 9"òx"óJ*óZ+óD!óHAó.Aó2?ó.@ó4Aó*$ð0Ø ØØØñ  €ò6-òrò(Q#òhòð: ˆzÒãÛØ � ‰ �‰˜ Ó#€AØ �J‰J�O‰OÓ €EØ ‡L�LØ‘ “ ðôð&�g—o‘oØ �Ø×3Ñ3°g×6FÑ6FÑFôH�O€HˆeñÐNÐ6×=Ñ=¸hÈÓNÓNˆ<ˆxðøðU%òõðús H È HÈH