-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduction of extra rules for parked domains.
This patch touches and fixes #255. Indeed, before this patch, we didn't bother to try to find parked domains. This patch introduces a new layout of SPECIAL rules that tries to check if the tested subject is a parked one. Warning: This patch is at an early stage. It is enabled when anyone allow the usage of special rules but it doesn't yet cover all possible parked subjects. Also: * Improvment of the extra rules layout by changing structure. Contributors: * @keczuppp
- Loading branch information
Showing
9 changed files
with
509 additions
and
131 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
""" | |||
The tool to check the availability or syntax of domain, IP or URL. | |||
:: | |||
██████╗ ██╗ ██╗███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗██████╗ ██╗ ███████╗ | |||
██╔══██╗╚██╗ ██╔╝██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝██╔══██╗██║ ██╔════╝ | |||
██████╔╝ ╚████╔╝ █████╗ ██║ ██║██╔██╗ ██║██║ █████╗ ██████╔╝██║ █████╗ | |||
██╔═══╝ ╚██╔╝ ██╔══╝ ██║ ██║██║╚██╗██║██║ ██╔══╝ ██╔══██╗██║ ██╔══╝ | |||
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗ | |||
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝ | |||
Provides everything related to the extras of the availablity checker. | |||
Author: | |||
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom | |||
Special thanks: | |||
https://pyfunceble.github.io/#/special-thanks | |||
Contributors: | |||
https://pyfunceble.github.io/#/contributors | |||
Project link: | |||
https://github.com/funilrys/PyFunceble | |||
Project documentation: | |||
https://pyfunceble.readthedocs.io/en/dev/ | |||
Project homepage: | |||
https://pyfunceble.github.io/ | |||
License: | |||
:: | |||
Copyright 2017, 2018, 2019, 2020, 2022 Nissar Chababy | |||
Licensed under the Apache License, Version 2.0 (the "License"); | |||
you may not use this file except in compliance with the License. | |||
You may obtain a copy of the License at | |||
http://www.apache.org/licenses/LICENSE-2.0 | |||
Unless required by applicable law or agreed to in writing, software | |||
distributed under the License is distributed on an "AS IS" BASIS, | |||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
""" |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,215 @@ | |||
""" | |||
The tool to check the availability or syntax of domain, IP or URL. | |||
:: | |||
██████╗ ██╗ ██╗███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗██████╗ ██╗ ███████╗ | |||
██╔══██╗╚██╗ ██╔╝██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝██╔══██╗██║ ██╔════╝ | |||
██████╔╝ ╚████╔╝ █████╗ ██║ ██║██╔██╗ ██║██║ █████╗ ██████╔╝██║ █████╗ | |||
██╔═══╝ ╚██╔╝ ██╔══╝ ██║ ██║██║╚██╗██║██║ ██╔══╝ ██╔══██╗██║ ██╔══╝ | |||
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗ | |||
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝ | |||
Provides the base of all extra handlers. | |||
Author: | |||
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom | |||
Special thanks: | |||
https://pyfunceble.github.io/#/special-thanks | |||
Contributors: | |||
https://pyfunceble.github.io/#/contributors | |||
Project link: | |||
https://github.com/funilrys/PyFunceble | |||
Project documentation: | |||
https://pyfunceble.readthedocs.io/en/dev/ | |||
Project homepage: | |||
https://pyfunceble.github.io/ | |||
License: | |||
:: | |||
Copyright 2017, 2018, 2019, 2020, 2022 Nissar Chababy | |||
Licensed under the Apache License, Version 2.0 (the "License"); | |||
you may not use this file except in compliance with the License. | |||
You may obtain a copy of the License at | |||
http://www.apache.org/licenses/LICENSE-2.0 | |||
Unless required by applicable law or agreed to in writing, software | |||
distributed under the License is distributed on an "AS IS" BASIS, | |||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
""" | |||
|
|||
import functools | |||
from typing import Callable, Optional | |||
|
|||
import PyFunceble.factory | |||
from PyFunceble.checker.availability.status import AvailabilityCheckerStatus | |||
|
|||
|
|||
class ExtraRuleHandlerBase: | |||
""" | |||
Provides the base of all extra rules handler. | |||
:param statatus: | |||
The previously gathered status. | |||
:type status: | |||
:class:`~PyFunceble.checker.availability.status.AvailabilityCheckerStatus` | |||
""" | |||
|
|||
_status: Optional[AvailabilityCheckerStatus] = None | |||
|
|||
def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None: | |||
if status is not None: | |||
self.status = status | |||
|
|||
# Be sure that all settings are loaded proprely!! | |||
PyFunceble.factory.Requester.guess_all_settings() | |||
|
|||
def ensure_status_is_given( | |||
func: Callable[..., "ExtraRuleHandlerBase"] | |||
): # pylint: disable=no-self-argument | |||
""" | |||
Ensures that the status is given before running the decorated method. | |||
:raise TypeError: | |||
If the subject is not a string. | |||
""" | |||
|
|||
@functools.wraps(func) | |||
def wrapper(self, *args, **kwargs): # pragma: no cover ## Safety! | |||
if not self.status: | |||
raise TypeError( | |||
f"<self.status> should be {AvailabilityCheckerStatus}, " | |||
f"{type(self.status)} given." | |||
) | |||
|
|||
return func(self, *args, **kwargs) # pylint: disable=not-callable | |||
|
|||
return wrapper | |||
|
|||
def setup_status_before( | |||
func: Callable[..., "ExtraRuleHandlerBase"] | |||
): # pylint: disable=no-self-argument | |||
""" | |||
Ensures that the status is given before running the decorated method. | |||
:raise TypeError: | |||
If the subject is not a string. | |||
""" | |||
|
|||
@functools.wraps(func) | |||
def wrapper(self, *args, **kwargs): # pragma: no cover ## Safety! | |||
self.status.status_before_extra_rules = self.status.status | |||
self.status.status_source_before_extra_rules = self.status.status_source | |||
|
|||
return func(self, *args, **kwargs) # pylint: disable=not-callable | |||
|
|||
return wrapper | |||
|
|||
def setup_status_after( | |||
func: Callable[..., "ExtraRuleHandlerBase"] | |||
): # pylint: disable=no-self-argument | |||
""" | |||
Ensures that the status is given before running the decorated method. | |||
:raise TypeError: | |||
If the subject is not a string. | |||
""" | |||
|
|||
@functools.wraps(func) | |||
def wrapper(self, *args, **kwargs): # pragma: no cover ## Safety! | |||
result = func(self, *args, **kwargs) # pylint: disable=not-callable | |||
|
|||
if self.status.status_after_extra_rules: | |||
self.status.status = self.status.status_after_extra_rules | |||
self.status.status_source = self.status.status_source_after_extra_rules | |||
|
|||
PyFunceble.facility.Logger.info( | |||
"Could define the status of %r from our own set of rules.", | |||
self.status.idna_subject, | |||
) | |||
else: | |||
self.status.status_before_extra_rules = None | |||
self.status.status_source_before_extra_rules = None | |||
self.status.status_after_extra_rules = None | |||
self.status.status_source_after_extra_rules = None | |||
|
|||
return result | |||
|
|||
return wrapper | |||
|
|||
@property | |||
def status(self) -> Optional[AvailabilityCheckerStatus]: | |||
""" | |||
Provides the current state of the :code:`_status` attribute. | |||
""" | |||
|
|||
return self._status | |||
|
|||
@status.setter | |||
def status(self, value: AvailabilityCheckerStatus) -> None: | |||
""" | |||
Sets the status to work with. | |||
:param value: | |||
The status to work with. | |||
:raise TypeError: | |||
When the given :code:`value` is not a | |||
:class:`~PyFunceble.checker.availability.status.AvailabilityCheckerStatus`. | |||
""" | |||
|
|||
if not isinstance(value, AvailabilityCheckerStatus): | |||
raise TypeError( | |||
f"<value> should be {AvailabilityCheckerStatus}, {type(value)} given." | |||
) | |||
|
|||
self._status = value | |||
|
|||
def set_status(self, value: AvailabilityCheckerStatus) -> "ExtraRuleHandlerBase": | |||
""" | |||
Sets the status to work with. | |||
:param value: | |||
The status to work with. | |||
""" | |||
|
|||
self.status = value | |||
|
|||
return self | |||
|
|||
def start(self) -> "ExtraRuleHandlerBase": | |||
""" | |||
Starts the gathering process. | |||
""" | |||
|
|||
raise NotImplementedError() | |||
|
|||
def switch_to_down(self) -> "ExtraRuleHandlerBase": | |||
""" | |||
Switches the status to inactive. | |||
""" | |||
|
|||
self.status.status_after_extra_rules = PyFunceble.storage.STATUS.down | |||
self.status.status_source_after_extra_rules = "SPECIAL" | |||
|
|||
return self | |||
|
|||
def switch_to_up(self) -> "ExtraRuleHandlerBase": | |||
""" | |||
Switches the status to active. | |||
""" | |||
|
|||
self.status.status_after_extra_rules = PyFunceble.storage.STATUS.up | |||
self.status.status_source_after_extra_rules = "SPECIAL" |
Oops, something went wrong.