pre-compile range option regexp to ease reuse

This commit is contained in:
Fabien LOISON 2017-12-13 11:34:17 +01:00
parent 3d90dc7c21
commit 3788717b7e
No known key found for this signature in database
GPG Key ID: FF90CA148348048E
1 changed files with 6 additions and 2 deletions

View File

@ -9,6 +9,10 @@ DEFAULT_OPTIONS = {
}
_RESIZE_OPTION_REGEXP = re.compile(
r"^([0-9]+)[x\s:,;]([0-9]+)$", flags=re.IGNORECASE)
def normalize_options(options=None):
if not options:
return dict(DEFAULT_OPTIONS)
@ -48,8 +52,8 @@ def normalize_options(options=None):
if value.isdigit():
value = int(value)
elif re.match(r"^([0-9]+)[x\s:,;]([0-9]+)$", value):
match = re.match(r"^([0-9]+)[x\s:,;]([0-9]+)$", value)
elif _RESIZE_OPTION_REGEXP.match(value):
match = _RESIZE_OPTION_REGEXP.match(value)
value = [
int(match.group(1)),
int(match.group(2)),