Skip to content

Commit f34e048

Browse files
committed
Improve handling around checkers.
1 parent 6bd74a1 commit f34e048

File tree

28 files changed

+194
-108
lines changed

28 files changed

+194
-108
lines changed

PyFunceble/checker/availability/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,11 @@ def subject_propagator(self) -> "CheckerBase":
511511
self.ip_syntax_checker.subject = self.idna_subject
512512
self.url_syntax_checker.subject = self.idna_subject
513513

514-
self.status = AvailabilityCheckerStatus()
515-
self.status.params = self.params
514+
if self.status.subject_kind is None:
515+
self.status = AvailabilityCheckerStatus()
516+
self.params = AvailabilityCheckerParams()
517+
self.status.params = self.params
518+
516519
self.status.dns_lookup_record = self.dns_query_tool.lookup_record
517520
self.status.whois_lookup_record = self.whois_query_tool.lookup_record
518521

PyFunceble/checker/availability/domain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import PyFunceble.facility
5454
import PyFunceble.storage
5555
from PyFunceble.checker.availability.base import AvailabilityCheckerBase
56+
from PyFunceble.checker.availability.params import AvailabilityCheckerParams
57+
from PyFunceble.checker.availability.status import AvailabilityCheckerStatus
5658
from PyFunceble.checker.reputation.domain import DomainReputationChecker
5759

5860

@@ -87,6 +89,22 @@ class DomainAvailabilityChecker(AvailabilityCheckerBase):
8789
WHOIS datasets.
8890
"""
8991

92+
def subject_propagator(self) -> "DomainAvailabilityChecker":
93+
"""
94+
Propagate the currently set subject.
95+
96+
.. warning::
97+
You are not invited to run this method directly.
98+
"""
99+
100+
self.status = AvailabilityCheckerStatus()
101+
self.params = AvailabilityCheckerParams()
102+
self.status.params = self.params
103+
104+
self.status.subject_kind = "domain"
105+
106+
return super().subject_propagator()
107+
90108
def try_to_query_status_from_reputation(self) -> "DomainAvailabilityChecker":
91109
"""
92110
Tries to query the status from the reputation lookup.

PyFunceble/checker/availability/extras/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ExtraRuleHandlerBase:
6767
"""
6868
Provides the base of all extra rules handler.
6969
70-
:param statatus:
70+
:param status:
7171
The previously gathered status.
7272
:type status:
7373
:class:`~PyFunceble.checker.availability.status.AvailabilityCheckerStatus`
@@ -167,7 +167,7 @@ def req_url(self) -> Optional[str]:
167167
Provides a viable request URL.
168168
"""
169169

170-
if any(self.status.idna_subject.startswith(x) for x in ("http:", "https:")):
170+
if self.status.idna_subject.startswith(("http:", "https:")):
171171
return self.status.idna_subject
172172
return f"http://{self.status.idna_subject}:80"
173173

@@ -177,7 +177,7 @@ def req_url_https(self) -> Optional[str]:
177177
Provides a viable request URL that default to an HTTPS URL.
178178
"""
179179

180-
if any(self.status.idna_subject.startswith(x) for x in ("http:", "https:")):
180+
if self.status.idna_subject.startswith(("http:", "https:")):
181181
return self.status.idna_subject
182182
return f"https://{self.status.idna_subject}:443"
183183

@@ -226,7 +226,7 @@ def do_request(self, *, allow_redirects: bool = True) -> requests.Response:
226226
Do a request and store its response into the `req` attribute.
227227
228228
:param bool allow_redirects:
229-
Whether we shoold follow the redirection - or not.
229+
Whether we should follow the redirection - or not.
230230
"""
231231

232232
self.req = self.requester.get(self.req_url, allow_redirects=allow_redirects)

PyFunceble/checker/availability/extras/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def start(self) -> "DNSRulesHandler":
132132
if not self.regex_helper.set_regex(regex).match(
133133
self.status.netloc, return_match=False
134134
):
135-
break
135+
continue
136136

137137
for ruler, params in rulesets:
138138
if self.status.status_after_extra_rules:

PyFunceble/checker/availability/extras/etoxic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class EToxicHandler(ExtraRuleHandlerBase):
6464
:class:`~PyFunceble.checker.availability.status.AvailabilityCheckerStatus`
6565
"""
6666

67-
MATCHES = [
67+
MATCHES = (
6868
".0wn0.com",
6969
".123.st",
7070
".1forum.biz",
@@ -282,7 +282,7 @@ class EToxicHandler(ExtraRuleHandlerBase):
282282
".yoo7.com",
283283
".ze-43eme.com",
284284
".zxr7team.com",
285-
]
285+
)
286286

287287
@ExtraRuleHandlerBase.ensure_status_is_given
288288
@ExtraRuleHandlerBase.setup_status_before
@@ -294,7 +294,7 @@ def start(self) -> "EToxicHandler":
294294
)
295295

296296
if self.status.status_before_extra_rules == PyFunceble.storage.STATUS.up:
297-
if any(self.status.netloc.endswith(x) for x in self.MATCHES):
297+
if self.status.netloc.endswith(self.MATCHES):
298298
self.do_on_header_match(
299299
self.req_url,
300300
matches={"location": [f"/{self.status.netloc}", "/search/"]},

PyFunceble/checker/availability/extras/parked.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ class ParkedRulesHandler(ExtraRuleHandlerBase):
6565
:class:`~PyFunceble.checker.availability.status.AvailabilityCheckerStatus`
6666
"""
6767

68+
PARKED_CONTENT_PATTERNS = (
69+
'class="parked-domains',
70+
"buy-domain",
71+
"this domain name is parked",
72+
"this domain is parked",
73+
"interested in this domain",
74+
"really cool domain parked",
75+
"domain is for sale",
76+
'_trackpageview("/parked/[% parked_type %]/',
77+
"| parked domain",
78+
"parked banner",
79+
"contact with domain owner",
80+
"web page is parked",
81+
"buy or lease this domain",
82+
"parked domain name on ",
83+
"it is currently parked by the owner",
84+
"parked page for",
85+
)
86+
6887
def _switch_down_by_cookie(self) -> "ParkedRulesHandler":
6988
"""
7089
Tries to switch the status to inactive if some special cookies where found.
@@ -75,31 +94,14 @@ def _switch_down_by_cookie(self) -> "ParkedRulesHandler":
7594

7695
return self
7796

78-
def _swith_down_by_content(self) -> "ParkedRulesHandler":
97+
def _switch_down_by_content(self) -> "ParkedRulesHandler":
7998
"""
8099
Tries to switch the status to inactive if some relative content were found.
81100
"""
82101

83102
content = self.req.text.lower()
84103

85-
if ( # pylint: disable=too-many-boolean-expressions
86-
'class="parked-domains' in content
87-
or "buy-domain" in content
88-
or "this domain name is parked" in content
89-
or "this domain is parked" in content
90-
or "interested in this domain" in content
91-
or "really cool domain parked" in content
92-
or "domain is for sale" in content
93-
or '_trackpageview("/parked/[% parked_type %]/' in content
94-
or "| parked domain" in content
95-
or "parked banner" in content
96-
or "contact with domain owner" in content
97-
or "web page is parked" in content
98-
or "buy or lease this domain" in content
99-
or "parked domain name on " in content
100-
or "it is currently parked by the owner" in content
101-
or "parked page for" in content
102-
):
104+
if any(x in content for x in self.PARKED_CONTENT_PATTERNS):
103105
self.switch_to_down()
104106

105107
return self
@@ -120,7 +122,7 @@ def start(self) -> "ParkedRulesHandler":
120122
self._switch_down_by_cookie()
121123

122124
if not self.status.status_after_extra_rules:
123-
self._swith_down_by_content()
125+
self._switch_down_by_content()
124126

125127
PyFunceble.facility.Logger.info(
126128
"Finished to check %r against our own set of parked rules.",

PyFunceble/checker/availability/extras/rules.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import PyFunceble.storage
5959
from PyFunceble.checker.availability.extras.base import ExtraRuleHandlerBase
6060
from PyFunceble.checker.availability.status import AvailabilityCheckerStatus
61-
from PyFunceble.helpers.regex import RegexHelper
6261

6362

6463
class ExtraRulesHandler(ExtraRuleHandlerBase):
@@ -106,7 +105,7 @@ def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None:
106105
r"\.translate\.goog$": [(self.switch_to_down_if_status_code, 403)],
107106
r"\.tumblr\.com$": [(self.switch_to_down_if_status_code, 404)],
108107
r"\.vercel\.app$": [
109-
(self.switch_to_down_if_status_code, "451"),
108+
(self.switch_to_down_if_status_code, 451),
110109
self.handle_vercel_dot_app,
111110
],
112111
r"\.web\.app$": [(self.switch_to_down_if_status_code, 404)],
@@ -119,8 +118,8 @@ def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None:
119118
(self.switch_to_down_if_status_code, 410),
120119
self.handle_wordpress_dot_com,
121120
],
122-
r"\.weebly\.com$": [(self.switch_to_down_if_status_code, {"404", "406"})],
123-
r"\.zzz\.com\.ua$": [(self.switch_to_down_if_status_code, {"402"})],
121+
r"\.weebly\.com$": [(self.switch_to_down_if_status_code, {404, 406})],
122+
r"\.zzz\.com\.ua$": [(self.switch_to_down_if_status_code, {402})],
124123
}
125124

126125
if PyFunceble.facility.ConfigLoader.is_already_loaded():
@@ -135,15 +134,12 @@ def __regex_registry_handler(self, regex_registry: dict) -> "ExtraRulesHandler":
135134
Handles the standard regex lookup case.
136135
"""
137136

138-
regex_helper = RegexHelper()
139-
140137
for (
141138
regex,
142139
data,
143140
) in regex_registry.items():
144-
broken = False
145141
for element in data:
146-
if not regex_helper.set_regex(regex).match(
142+
if not self.regex_helper.set_regex(regex).match(
147143
self.status.netloc, return_match=False
148144
):
149145
continue
@@ -154,11 +150,7 @@ def __regex_registry_handler(self, regex_registry: dict) -> "ExtraRulesHandler":
154150
element()
155151

156152
if self.status.status_after_extra_rules:
157-
broken = True
158-
break
159-
160-
if broken:
161-
break
153+
return self
162154

163155
return self
164156

PyFunceble/checker/availability/extras/subject_switch.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ def _switch_down_by_history(self) -> "SubjectSwitchRulesHandler":
116116
if netloc == self.status.idna_subject and netloc not in variations:
117117
continue
118118

119-
if not start_path:
120-
if local_path != "/":
121-
continue
122-
elif start_path != local_path:
119+
if (not start_path and local_path != "/") or (
120+
start_path and start_path != local_path
121+
):
123122
continue
124123

125124
self.switch_to_down()
@@ -141,7 +140,7 @@ def start(self) -> "SubjectSwitchRulesHandler":
141140
)
142141

143142
try:
144-
if any(self.status.netloc.startswith(x) for x in ("www.", "m.")):
143+
if self.status.netloc.startswith(("www.", "m.")):
145144
self.do_request()
146145

147146
if not self.status.status_after_extra_rules:

PyFunceble/checker/availability/ip.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import PyFunceble.facility
5454
import PyFunceble.storage
5555
from PyFunceble.checker.availability.base import AvailabilityCheckerBase
56+
from PyFunceble.checker.availability.params import AvailabilityCheckerParams
57+
from PyFunceble.checker.availability.status import AvailabilityCheckerStatus
5658
from PyFunceble.checker.reputation.ip import IPReputationChecker
5759

5860

@@ -87,6 +89,22 @@ class IPAvailabilityChecker(AvailabilityCheckerBase):
8789
WHOIS datasets.
8890
"""
8991

92+
def subject_propagator(self) -> "IPAvailabilityChecker":
93+
"""
94+
Propagate the currently set subject.
95+
96+
.. warning::
97+
You are not invited to run this method directly.
98+
"""
99+
100+
self.status = AvailabilityCheckerStatus()
101+
self.params = AvailabilityCheckerParams()
102+
self.status.params = self.params
103+
104+
self.status.subject_kind = "ip"
105+
106+
return super().subject_propagator()
107+
90108
def try_to_query_status_from_reputation(self) -> "IPAvailabilityChecker":
91109
"""
92110
Tries to query the status from the reputation lookup.

PyFunceble/checker/availability/params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
@dataclasses.dataclass
6161
class AvailabilityCheckerParams(CheckerParamsBase):
6262
"""
63-
Provides the description of an availability checker paramaters.
63+
Provides the description of an availability checker parameters.
6464
"""
6565

6666
use_extra_rules: Optional[bool] = None

0 commit comments

Comments
 (0)