Re: [Rest2web-develop] Added an 'ip_addr' IPv4 address value test...
Brought to you by:
mjfoord
From: Michael F. <mi...@pc...> - 2005-07-20 09:50:27
|
Nicola Larosa wrote: >>>This ambiguity of code tests and value tests is tiring me. What if we >>>called "checks" the value tests, and just "test" the code tests? I'll >>>shoulder the burden of updating docstrings *and* documentation, if you agree. > > >>So tests are the doctests and validate performs 'checks' on values. >> >>Ok - *but* are you going to rename the ``Validator.test`` method to >>``Validator.check`` ? > > > Of course. :-) > > > >>I have to recode the Validator support (and therefore the docs) in >>ConfigObj anyway - so I'll implement whatever we decide. > > > I'm for consistency (where useful), so I'd use "check" wherever it's > visible to the (programmer) user, either docs or API. > The current ConfigObj method is called ``validate`` as it does more than check a single value. I'm adding the ability to check individual values to the ``Section`` - a method I will now call ``check``. [snip..] >>Do you think the ``import socket, struct`` belongs in the body of the >>module ? This means that importing validate *automatically* imports >>socket.. a heavy dependency for just one of the checks. > > > What's the problem? Isn't it in the std lib anyway? > On some platforms (like my PDA) importing socket is a non-trivial action. I'm not sure if struct is available for *all* platforms (not all the stdlib is implemented for all platforms - so dependency on a c module for functionality that is unlikely to be used by many users....). Anyway - it's academic if we move that out into a separate module or move the import statements. > > >>How about in the body of the module : :: >> >> socket = None >> struct = None >> >>In the check : >> >>def dottedQuadToNum(ip): >> """Convert decimal dotted quad string to long integer""" >> global socket, struct >> if socket is None: >> import socket >> import struct >> >>and the equivalent in ``numToDottedQuad``. > > > I think you can just move the imports inside the functions, without the > global checking business. Python will take care of that, I don't see > problems on multiple execution. > Ok > But even before that, I'd place these two methods in a separate "utils.py" > module, and maybe import *them* on demand. > I like the idea of keeping it as a single file if we can - but then it's nice to include 'extra' tests that don't need to be part of the core dist. Whatever you think best really. > > >>Another difficulty - if your config file has an IP address with the >>relevant check in the configspec then the IP address will be checked and >>converted to a long using ``dottedQuadToNum``. >> >>When you come to write out the config file (by calling ``write`` or >>``writein`` then the long will be converted using 'str'..... You'd have >>to call ``numToDottedQuad`` yourself unless we add an alternative >>mechanism (unvalidation ! - registering a str function as well for each >>check...) > > > Nothing of the sort. Look again at line #876: the long is not actually > used, the value stays string. ;-D > Ahhh.... ok. > > >>Did you see your mention in Daily Python URL ? > > > Yes, I did, you sprawled my name all over the place. I'm pleased, of > course. :-) BTW, the one suggesting Medusa+Quixote was me, again. ;-) > I know, but I thought you'd had enough publicity ! What I really want is a way into twisted/nevow with WSGI... knowing where to start is the problem. Regards, Fuzzy http://www.voidspace.org.uk/python |