[enh] Allow unicode pattern matching in 'pattern' extra parameter

This commit is contained in:
Jérôme Lebleu 2014-06-02 20:22:55 +02:00
parent 735ca3af87
commit 1a313a792c

View file

@ -145,7 +145,13 @@ class PatternParameter(_ExtraParameter):
def __call__(self, arguments, arg_name, arg_value):
pattern, message = (arguments[0], arguments[1])
if arg_value and not re.match(pattern, arg_value or ''):
# Use temporarly utf-8 encoded value
try:
v = unicode(arg_value, 'utf-8')
except:
v = arg_value
if v and not re.match(pattern, v or '', re.UNICODE):
raise MoulinetteError(errno.EINVAL, m18n.n(message))
return arg_value