add FileOption

This commit is contained in:
2013-09-30 21:21:47 +02:00
parent 1a294e3d09
commit cce080cbd3
3 changed files with 55 additions and 5 deletions

View File

@@ -1031,6 +1031,7 @@ class DomainnameOption(Option):
class EmailOption(DomainnameOption):
__slots__ = tuple()
_opt_type = 'email'
username_re = re.compile(r"^[\w!#$%&'*+\-/=?^`{|}~.]+$")
def __init__(self, *args, **kwargs):
@@ -1053,6 +1054,7 @@ class EmailOption(DomainnameOption):
class URLOption(DomainnameOption):
__slots__ = tuple()
_opt_type = 'url'
proto_re = re.compile(r'(http|https)://')
path_re = re.compile(r"^[a-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]+$")
@@ -1093,6 +1095,17 @@ class URLOption(DomainnameOption):
' {0}').format(self._name))
class FileOption(Option):
__slots__ = tuple()
_opt_type = 'file'
path_re = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
def _validate(self, value):
match = self.path_re.search(value)
if not match:
raise ValueError(_('invalid filename for {0}').format(self._name))
class OptionDescription(BaseOption):
"""Config's schema (organisation, group) and container of Options
The `OptionsDescription` objects lives in the `tiramisu.config.Config`.