' 192. 168. 1.2 ' is not a valid ip addr :)
Returns True if `address` is a valid IPv4 address.
>>> validipaddr('192 .168. 1.1 ')
Looking at the code it seems to be properly handled by int:
octets = address.split('.')
if len(octets) != 4:
for x in octets:
if not (0 <= int(x) <= 255):
Why would you want this to fail specifically? For a web-framework I think it's fair to allow for some error recovery such as this, and I'm sure there are other frameworks out there that allow for more rigorous IP address validation.
This method definitely seems weak. If the framework tells someone that an improperly formatted address is valid then they're going to use that address in it's improper form.
This really should be done using a regular expression. That would invalidate an address with spaces while ensuring that there 4 octets in the range of 0 - 255.
Perhaps adding an optional argument strict that panicks when it sees spaces,etc is not a bad idea.
However, I see no 'need' for that.
Using regexps and enforcing stricter and correct checking would definitely be better.