-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
34 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .check_wrappers import html_check, css_check | ||
from .flatten import flatten_varargs |
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,34 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
def fail(): | ||
"""Return a Check that always fails""" | ||
# Local import to avoid circular dependencies | ||
from validators.checks import Check | ||
|
||
def _inner(_: BeautifulSoup) -> bool: | ||
return False | ||
|
||
return Check(_inner) | ||
|
||
|
||
def html_check(func): | ||
"""Decorator that checks if an HTML element is not None""" | ||
def wrapper(*args, **kwargs): | ||
if args[0]._element is None: | ||
return fail() | ||
|
||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
|
||
def css_check(func): | ||
"""Decorator that checks if an element's HTML tag and CSS validator are not None""" | ||
def wrapper(*args, **kwargs): | ||
if args[0]._element is None or args[0]._css_validator is None: | ||
return fail() | ||
|
||
return func(*args, **kwargs) | ||
|
||
return wrapper |
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