Permalink
Browse files

Merge branch 'develop' of github.com:toscawidgets/tw2.core into develop

  • Loading branch information...
ralphbean committed Sep 3, 2013
2 parents e1fe134 + bfc4531 commit 4fec80d221fe423c89485d3871073994bd3850ed
Showing with 45 additions and 11 deletions.
  1. +10 −10 setup.py
  2. +7 −0 tests/test_validation.py
  3. +1 −1 tw2/core/__init__.py
  4. +27 −0 tw2/core/validation.py
@@ -71,25 +71,25 @@ def get_description(fname='README.rst'):
name='tw2.core',
version='2.2.0.2',
description='The runtime components for ToscaWidgets 2, a web widget toolkit.',
long_description = get_description(),
long_description=get_description(),
author='Paul Johnston, Christopher Perkins, Alberto Valverde Gonzalez & contributors',
author_email='toscawidgets-discuss@googlegroups.com',
url = "http://toscawidgets.org/",
download_url = "https://pypi.python.org/pypi/tw2.core/",
url="http://toscawidgets.org/",
download_url="https://pypi.python.org/pypi/tw2.core/",
license='MIT',
install_requires=requires,
tests_require=tests_require,
test_suite = 'nose.collector',
extras_require = {
test_suite='nose.collector',
extras_require={
'genshi': _extra_genshi,
'mako': _extra_mako,
'jinja': _extra_jinja,
'chameleon': _extra_chameleon,
},
license='MIT',
packages = ['tw2', 'tw2.core'],
namespace_packages = ['tw2'],
packages=['tw2', 'tw2.core'],
namespace_packages=['tw2'],
include_package_data=True,
exclude_package_data={"thirdparty" : ["*"]},
exclude_package_data={"thirdparty": ["*"]},
entry_points="""
[tw2.widgets]
widgets = tw2.core
@@ -106,7 +106,7 @@ def get_description(fname='README.rst'):
""",
zip_safe=False,
classifiers = [
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Environment :: Web Environment :: ToscaWidgets',
@@ -12,6 +12,7 @@
import six
from six.moves import map
from six.moves import zip
import uuid
HAS_SKIP = sys.version_info[0] == 2 and sys.version_info[1] == 7
@@ -510,6 +511,12 @@ class TestIPAddressValidator(tb.ValidatorTest):
params = ['123.123.123.123', 'asdf']
expected = ['123.123.123.123', ValidationError]
class TestUUIDValidator(tb.ValidatorTest):
validator = UUIDValidator
attrs = [{}, {}]
params = ['34a9c4dd-1562-4413-bb27-a439292a5e61', 'asdf']
expected = [uuid.UUID('34a9c4dd-1562-4413-bb27-a439292a5e61'), ValidationError]
class TestValidatorMisc(TestCase):
def testRequired(self):
@@ -27,7 +27,7 @@
RegexValidator, IntValidator, OneOfValidator, DateValidator,
DateTimeValidator, ValidationError, Invalid, EmailValidator,
UrlValidator, IpAddressValidator, StringLengthValidator,
ListLengthValidator, RangeValidator, MatchValidator,
ListLengthValidator, RangeValidator, MatchValidator, UUIDValidator,
BoolValidator, BlankValidator, safe_validate, EmptyField,
CompoundValidator,
Any, All,
@@ -7,6 +7,7 @@
import functools
import webob
import warnings
import uuid
from .i18n import _
import six
@@ -570,6 +571,32 @@ def _validate_python(self, value, state=None):
raise ValidationError('badnetblock', self)
class UUIDValidator(Validator):
"""
Confirm the value is a valid uuid and convert to uuid.UUID.
"""
msgs = {
'badregex': ('baduuid', _('Value not recognised as a UUID')),
}
regex = re.compile(\
'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
def _validate_python(self, value, state=None):
if not self.regex.search(str(value)):
raise ValidationError('badregex', self)
def _convert_to_python(self, value, state=None):
try:
return uuid.UUID( "{%s}" % value )
except ValueError:
raise ValidationError('baduuid', self)
def _convert_from_python(self, value, state=None):
return str(value)
class MatchValidator(Validator):
"""Confirm a field matches another field

0 comments on commit 4fec80d

Please sign in to comment.