Skip to content

Commit

Permalink
Introduction of the imgur.com SPECIAL rule.
Browse files Browse the repository at this point in the history
This patch fixes #319.

Indeed, before this patch we weren't handling the case that a
hosted image or user has been deleted.

Contributors:
  * @smed79
  • Loading branch information
funilrys committed Dec 28, 2022
1 parent 3227499 commit 266f0a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
39 changes: 36 additions & 3 deletions PyFunceble/checker/availability/extras/rules.py
Expand Up @@ -92,6 +92,7 @@ def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None:
r"\.github\.io$": [(self.__switch_to_down_if, 404)],
r"\.godaddysites\.com$": [(self.__switch_to_down_if, 404)],
r"\.hpg.com.br$": [(self.__switch_to_down_if, 404)],
r"\.imgur\.com$": [self.__handle_imgur_dot_com],
r"\.liveadvert\.com$": [(self.__switch_to_down_if, 404)],
r"\.skyrock\.com$": [(self.__switch_to_down_if, 404)],
r"\.tumblr\.com$": [(self.__switch_to_down_if, 404)],
Expand Down Expand Up @@ -152,9 +153,7 @@ def __regex_registry_handler(self, regex_registry: dict) -> "ExtraRulesHandler":
) in regex_registry.items():
broken = False
for element in data:
if not RegexHelper(regex).match(
self.status.idna_subject, return_match=False
):
if not RegexHelper(regex).match(self.status.netloc, return_match=False):
continue

if isinstance(element, tuple):
Expand Down Expand Up @@ -246,6 +245,40 @@ def __handle_fc2_dot_com(self) -> "ExtraRulesHandler":

return self

def __handle_imgur_dot_com(self) -> "ExtraRulesHandler":
"""
Handles the :code:`imgur.com` case.
.. warning:.
This method assume that we know that we are handling a imgur.com
sub-domain.
"""

if self.status.idna_subject.startswith(
"http:"
) or self.status.idna_subject.startswith("https://"):
url = self.status.idna_subject
else:
url = f"https://{self.status.idna_subject}"

req = PyFunceble.factory.Requester.get(url, allow_redirects=True)
username = self.status.netloc.replace(".imgur.com", "")

for response in req.history:
if "Location" in req.response:
if req.headers["Location"].endswith(("/removed.png")):
self.switch_to_down()

if response.status_code in [404] and response.url.endswith(
f"/user/{username}"
):
self.switch_to_down()

if req.url.endswith(f"/user/{username}"):
self.switch_to_down()

return self

def __handle_active2inactive(self) -> "ExtraRulesHandler":
"""
Handles the status deescalation.
Expand Down
11 changes: 11 additions & 0 deletions docs/components/special-rules.rst
Expand Up @@ -319,6 +319,17 @@ supplied as :code:`INACTIVE`.

------

:code:`*.imgur.com`
"""""""""""""""""""

Any subjects matching the given pattern and:

- the :code:`/removed.png` path in the end URL (after redirect).

are supplied as :code:`INACTIVE`.

------

:code:`*.liveadvert.com`
""""""""""""""""""""""""

Expand Down

0 comments on commit 266f0a5

Please sign in to comment.