def test_check(): d=dict(x=5, y=100) def add_z(val): val['z']=300 def len_d(v2, size): if len(v2)!=size: raise V.Invalid("wrong size") d2=V.check(add_z, partial(len_d, size=3))(d) assert d2 is d assert d['z']==300
def test_check(): d = dict(x=5, y=100) def add_z(val, context=None): val['z'] = 300 def len_d(v2, size, context=None): if len(v2) != size: raise V.Invalid("wrong size") d2 = V.check(add_z, partial(len_d, size=3))(d) assert d2 is d assert d['z'] == 300 d = dict(x=5, y=100) validator = V.check(is_in_context(), add_z, partial(len_d, size=3)) assert validator.__name__ == "check" result = validator(d, context=[dict(x=5, y=100)]) assert result is d assert d['z'] == 300
def test_check(): d = dict(x=5, y=100) def add_z(val, context=None): val['z'] = 300 def len_d(v2, size, context=None): if len(v2) != size: raise V.Invalid("wrong size") d2 = V.check(add_z, partial(len_d, size=3))(d) assert d2 is d assert d['z'] == 300 d = dict(x=5, y=100) validator = V.check( is_in_context(), add_z, partial(len_d, size=3)) assert validator.__name__ == "check" result = validator(d, context=[dict(x=5, y=100)]) assert result is d assert d['z'] == 300
import re import socket import urllib.parse from validino.base import Invalid, _msg, regex from validino.util import partial # lifted from formencode _usernameRE = re.compile(r"^[^ \t\n\r@<>()]+$", re.I) _domainRE = re.compile(r"^[a-z0-9][a-z0-9\.\-_]*\.[a-z]+$", re.I) __all__ = ['ip', 'url'] _ip_pat = '^%s$' % r'\.'.join(['|'.join([str(x) for x in range(256)] * 4)]) ip = partial(regex, _ip_pat) ip.__doc__ = """ Returns a validator that tests whether an ip address is properly formed. """ _error_message = ( "existence check not supported for schemas other than http and https" ) def url( check_exists=False, schemas=('http', 'https'), default_schema='http', default_host='', msg=None
if exc.errors: raise exc else: return values f.types = types f.require_type = require_type f.msg = msg f.cc_field = cc_field f.cc_type_field = cc_type_field return f _ip_pat = '^%s$' % r'\.'.join(['|'.join([str(x) for x in range(256)] * 4)]) ip = partial(regex, _ip_pat) ip.__doc__ = """ Returns a validator that tests whether an ip address is properly formed. """ def url(check_exists=False, schemas=('http', 'https'), default_schema='http', default_host='', msg=None): def f(value): if f.check_exists and set(f.schemas).difference(set( ('http', 'https'))): m = "existence check not supported for schemas other than http and https" raise RuntimeError(m)