-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schemas: add url map converter for version
Signed-off-by: Parth Shandilya <[email protected]>
- Loading branch information
Showing
5 changed files
with
114 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""URL Map Converter module.""" | ||
|
||
import re | ||
|
||
from flask import abort | ||
from werkzeug.routing import BaseConverter | ||
|
||
SCHEMA_VERSION_REGEXP = r'^\d+\.\d+\.\d+$' | ||
|
||
|
||
class SchemaVersionConverter(BaseConverter): | ||
"""Converter class for validating schema version number.""" | ||
|
||
def __init__(self, url_map): | ||
"""Initialise converter.""" | ||
super().__init__(url_map) | ||
|
||
def to_python(self, value): | ||
if not bool(re.match(SCHEMA_VERSION_REGEXP, value)): | ||
abort(404) | ||
return value | ||
|
||
def to_url(self, value): | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters