-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added image model and url validators
- Loading branch information
1 parent
dbaa4ee
commit 86497a4
Showing
5 changed files
with
35 additions
and
1 deletion.
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
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,28 @@ | ||
from types import NoneType | ||
|
||
import validators | ||
|
||
|
||
class Image: | ||
def __init__(self, image_id: str, page_number: int, url: str | None): | ||
self.id = image_id | ||
self.page_number = page_number | ||
self.__url = None | ||
|
||
self.url = url | ||
|
||
@property | ||
def url(self): | ||
return self.__url | ||
|
||
@url.setter | ||
def url(self, url: str | None): | ||
if not isinstance(url, (str, NoneType)): | ||
raise TypeError(f"Url must be str or None got {type(url)}") | ||
if url is not None and not validators.url(url): | ||
raise ValueError(f"Url {url} is not valid") | ||
self.__url = url | ||
|
||
@staticmethod | ||
def get_empty_instance(): | ||
return Image("", 1, None) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ render-html>=1.0.1 | |
requests>=2.28.1 | ||
requests-oauthlib>=1.3.1 | ||
SQLAlchemy>=2.0.25 | ||
validators>=0.33.0 |
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ render-html>=1.0.1 | |
requests>=2.28.1 | ||
requests-oauthlib>=1.3.1 | ||
SQLAlchemy>=2.0.25 | ||
validators>=0.33.0 |