示例#1
0
文件: validators.py 项目: lslaz1/karl
 def __call__(self, v):
     if v:
         if v.startswith('www.'):
             v = 'http://%s' % v
         try:
             validate.is_url(v, with_scheme=True)
         except Invalid:
             msg = u"Must start with 'http://', 'https://', or 'www.'"
             raise Invalid(msg, validator=self)
示例#2
0
 def __call__(self, v):
     if v:
         if v.startswith("www."):
             v = "http://%s" % v
         try:
             validate.is_url(v, with_scheme=True)
         except Invalid, e:
             msg = u"Must start with 'http://', 'https://', or 'www.'"
             raise Invalid(msg, validator=self)
示例#3
0
 def __call__(self, v):
     try:
         validate.is_url(v,
                         full=self.full,
                         absolute=self.absolute,
                         relative=self.relative,
                         messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)
示例#4
0
 def test_validate_withoutscheme(self):
     fn = lambda v: validate.is_url(v, with_scheme=True)
     self.section = 'fail'
     values = [
         'foo.com',
     ]
     check_fail('function', self, fn, values)
示例#5
0
 def test_validate_pass_relative(self):
     fn = lambda v: validate.is_url(v, full=False, relative=True, absolute=False)
     self.section='pass'
     values = [
         'foo',
         ]
     check_pass('function', self, fn, values)
示例#6
0
 def test_validate_pass_withoutscheme(self):
     fn = lambda v: validate.is_url(v, with_scheme=True)
     self.section = 'pass'
     values = [
         'http://foo.com',
     ]
     check_pass('function', self, fn, values)
示例#7
0
 def test_validate_full(self):
     fn = lambda v: validate.is_url(v, full=True, absolute=False, relative=False)
     self.section='fail'
     values = [
         'foo.com',
         ]
     check_fail('function', self, fn, values)
示例#8
0
 def test_validate_withoutscheme(self):
     fn = lambda v: validate.is_url(v, with_scheme=True)
     self.section='fail'
     values = [
         'foo.com',
         ]
     check_fail('function', self, fn, values)
示例#9
0
 def test_validate_pass_withoutscheme(self):
     fn = lambda v: validate.is_url(v, with_scheme=True)
     self.section='pass'
     values = [
         'http://foo.com',
         ]
     check_pass('function', self, fn, values)
示例#10
0
 def test_validate_pass_relative(self):
     fn = lambda v: validate.is_url(
         v, full=False, relative=True, absolute=False)
     self.section = 'pass'
     values = [
         'foo',
     ]
     check_pass('function', self, fn, values)
示例#11
0
 def test_validate_full(self):
     fn = lambda v: validate.is_url(
         v, full=True, absolute=False, relative=False)
     self.section = 'fail'
     values = [
         'foo.com',
     ]
     check_fail('function', self, fn, values)
示例#12
0
 def __call__(self, v):
     try:
         validate.is_url(v, with_scheme=self.with_scheme, messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)
示例#13
0
 def __call__(self, v):
     try:
         validate.is_url(v, full=self.full, absolute=self.absolute, relative=self.relative,  messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)