[Tutor] Looking for ConfigObj Documentation
Marc Tompkins
marc.tompkins at gmail.com
Thu Feb 19 00:18:03 CET 2009
On Wed, Feb 18, 2009 at 2:57 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net>wrote:
> Thanks. I recall installing several libraries though, where somehow they
> were packaged to automatically install when opened.
>
> In the <http://www.voidspace.org.uk/python/configobj.html><http://www.voidspace.org.uk/python/configobj.html>description, I do not see much of an explanations of examples of items like,
> integer(min=0, default=0). It looks like they may be called configspecs. I
> see this in section 5.3.2.2.
>
> key1 = integer(0, 30, default=15)
> key2 = integer(default=15)
> key3 = boolean(default=True)
> key4 = option('Hello', 'Goodbye', 'Not Today', default='Not Today')
>
> but not much else. Validators? Are there others like integer, booleand and
> option? Items like start_time would then be called keywords?
>
The configspec (configuration specification) is that thing I put inside of
triple quotes. It's basically a template of what your config file will look
like once it has actual data in it.
In 5.3.2, the sentence "The validate method uses the
validate<http://www.voidspace.org.uk/python/validate.html>module to do
the validation" links to the validate.py documentation - but
you won't see that if you're reading it on paper...
Remember I said there's a bunch of stuff there you might not need just now?
A good deal of it has to do with extending ConfigObj for your own twisted,
nefarious purposes (bwahahahahaha!) - you can write your own validators for
just about any kind of values you can imagine. However, just to get
started, the built-ins are probably good (from the validate.py doc,
http://www.voidspace.org.uk/python/validate.html#the-standard-functions):
========================================================
The standard functions come built-in to every Validator instance. They work
with the following basic data types :
- integer
- float
- boolean
- string
- 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.
'string':
matches any string. Takes optional keyword args 'min' and 'max' to specify
min and max length of string.
'ip_addr':
matches an Internet Protocol address, v.4, represented by a dotted-quad
string, i.e. '1.2.3.4'.
'list':
matches any list. Takes optional keyword args 'min', and 'max' to specify
min and max sizes of the list. The list checks always return a list.
'tuple':
matches any list. This check returns a tuple rather than a list.
'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.
'string_list':
Matches a list of strings. Takes the same arguments as list.
'ip_addr_list':
Matches a list of IP addresses. 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 :
int, str, boolean, float, ip_addr
So to specify a list with two strings followed by two integers, you write
the check as :
mixed_list(str, str, int, int)
'pass':
matches everything: it never fails and the value is unchanged. It is also
the default if no check is specified.
'option':
matches any from a list of options. You specify this test with :
option('option 1', 'option 2', 'option 3')
===============================================================
--
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090218/b38c0077/attachment-0001.htm>
More information about the Tutor
mailing list