Re: [Rest2web-develop] Added an 'ip_addr' IPv4 address value test...
Brought to you by:
mjfoord
From: Nicola L. <ni...@te...> - 2005-07-20 09:27:08
|
>> 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. > I'm liking what you've done with validate. > Thanks for reformatting the docs as well - writing docs on a PDA is > *hard* :-) I am unable to leave well alone what looks even slightly misplaced. ;-) > 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? > 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. But even before that, I'd place these two methods in a separate "utils.py" module, and maybe import *them* on demand. > 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 > 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. ;-) -- Nicola Larosa - ni...@te... When I was growing up, my parents used to say to me, "Tom, finish your dinner - people in China are starving." But after sailing to the edges of the flat world for a year, I am now telling my own daughters, "Girls, finish your homework - people in China and India are starving for your jobs." -- Thomas L. Friedman, New York Times, April 2005 |