Skip to content

Commit 52623ab

Browse files
committed
diocument all exceptions in ruff rules
1 parent c49573f commit 52623ab

14 files changed

Lines changed: 120 additions & 155 deletions

pyproject.toml

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,19 @@
156156
]
157157

158158
ignore = [
159-
# ignore for now:
160-
#"ARG001",
161-
#"ARG002",
162-
163-
"D100",
164-
"D101",
165-
"D102",
166-
"D104",
167-
"D105",
168-
"D107",
159+
"D100", # Missing docstring in public module
160+
"D101", # Missing docstring in public module
161+
"D102", # Missing docstring in public method
169162
"D103", # Missing docstring in public function
163+
"D104", # Missing docstring in public package
164+
"D105", # Missing docstring in magic method
165+
"D107", # Missing docstring in magic method
166+
"D203", "D211", # `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
170167

171-
"N802",
172-
"N803",
173-
"N806",
174-
"N812",
175-
"N815",
176-
"N816",
177-
"N818",
178-
"N999",
179-
180-
"PLR2004",
168+
"N802", # Function name `getThisTld` should be lowercase
169+
"N803", # Argument name `xx` should be lowercase
170+
"N806", # Variable `xx` in function should be lowercase
171+
"N999", # Invalid module name
181172

182173
"PLR0911", # Too many return statements
183174
"PLR0912", # Too many branches
@@ -186,9 +177,10 @@
186177
"PLW0603", # Using the global statement to update `xxx` is discouraged
187178
"PLW0602", # Using global for `xxx` but no assignment is done
188179

189-
"RUF001","RUF067", "RUF012",
190-
"S101", # Use of `assert` detected
180+
"RUF001", # String contains ambiguous urf8 char
181+
"RUF067", # `__init__` module should only contain docstrings and re-exports
191182

183+
"S101", # Use of `assert` detected
192184
#
193185
"COM812", # The following rule may cause conflicts when used with the formatter: `COM812`
194186
"T201", # print statements are ok, used in verbose mode

t1.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from whoisdomain import ProcFunc
77

8+
N = 26
9+
810

911
def remoteFunc(
1012
conn: Any,
@@ -51,7 +53,7 @@ def main() -> None:
5153
for item in names:
5254
v = f(item)
5355
print(v)
54-
if n >= 26:
56+
if n >= N:
5557
break
5658

5759
f = pf.makeHandler(remoteFunc, restart_after_count)
@@ -61,7 +63,7 @@ def main() -> None:
6163
for item in names:
6264
v = f(item)
6365
print(v)
64-
if n >= 26:
66+
if n >= N:
6567
break
6668

6769

whoisdomain/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
from .domain import Domain
2626
from .doWhoisCommand import setMyCache
2727
from .exceptions import (
28-
FailedParsingWhoisOutput,
29-
UnknownDateFormat,
30-
UnknownTld,
31-
WhoisCommandFailed,
32-
WhoisCommandTimeout,
33-
WhoisPrivateRegistry,
34-
WhoisQuotaExceeded,
28+
FailedParsingWhoisOutputError,
29+
UnknownDateFormatError,
30+
UnknownTldError,
31+
WhoisCommandFailedError,
32+
WhoisCommandTimeoutError,
33+
WhoisPrivateRegistryError,
34+
WhoisQuotaExceededError,
3535
)
3636
from .helpers import (
3737
cleanupWhoisResponse,
@@ -83,7 +83,7 @@
8383

8484
TLD_LIB_PRESENT: bool = False
8585
try:
86-
import tld as libTld # noqa: F401
86+
import tld as lib_tld # noqa: F401
8787

8888
TLD_LIB_PRESENT = True
8989
except ImportError as e:
@@ -94,7 +94,7 @@
9494
"ZZ",
9595
"DBMCache",
9696
"DummyCache",
97-
"FailedParsingWhoisOutput",
97+
"FailedParsingWhoisOutputError",
9898
"NoneStrings",
9999
"NoneStringsAdd",
100100
"ParameterContext",
@@ -105,12 +105,12 @@
105105
"SimpleCacheBase",
106106
"SimpleCacheWithFile",
107107
"TldInfo",
108-
"UnknownDateFormat",
109-
"UnknownTld",
110-
"WhoisCommandFailed",
111-
"WhoisCommandTimeout",
112-
"WhoisPrivateRegistry",
113-
"WhoisQuotaExceeded",
108+
"UnknownDateFormatError",
109+
"UnknownTldError",
110+
"WhoisCommandFailedError",
111+
"WhoisCommandTimeoutError",
112+
"WhoisPrivateRegistryError",
113+
"WhoisQuotaExceededError",
114114
"WhoisRdap",
115115
"cleanupWhoisResponse",
116116
"filterTldToSupportedPattern",

whoisdomain/cache/simpleCacheBase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def __init__(
1111
self,
1212
*,
1313
verbose: bool = False,
14-
cacheMaxAge: int = (60 * 60 * 48),
14+
cache_max_age: int = (60 * 60 * 48),
1515
) -> None:
1616
self.verbose = verbose
1717
self.memCache: dict[str, tuple[float, str]] = {}
18-
self.cacheMaxAge: int = cacheMaxAge
18+
self.cache_max_age: int = cache_max_age
1919

2020
def put(
2121
self,
@@ -38,7 +38,7 @@ def get(
3838
return None
3939

4040
t = time.time()
41-
hasExpired = cData[0] < (t - self.cacheMaxAge)
41+
hasExpired = cData[0] < (t - self.cache_max_age)
4242
if hasExpired is True:
4343
return None
4444

whoisdomain/cache/simpleCacheWithFile.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212

1313

1414
class SimpleCacheWithFile(SimpleCacheBase):
15-
cacheFilePath: str | None = None
15+
cache_file_path: str | None = None
1616

1717
def __init__(
1818
self,
1919
*,
2020
verbose: bool = False,
21-
cacheFilePath: str | None = None,
22-
cacheMaxAge: int = (60 * 60 * 48),
21+
cache_file_path: str | None = None,
22+
cache_max_age: int = (60 * 60 * 48),
2323
) -> None:
24-
super().__init__(verbose=verbose, cacheMaxAge=cacheMaxAge)
25-
self.cacheFilePath = cacheFilePath
24+
super().__init__(verbose=verbose, cache_max_age=cache_max_age)
25+
self.cache_file_path = cache_file_path
2626

2727
def _fileLoad(
2828
self,
2929
) -> None:
30-
if self.cacheFilePath is None:
30+
if self.cache_file_path is None:
3131
return
3232

33-
if not pathlib.Path(self.cacheFilePath).is_file():
33+
if not pathlib.Path(self.cache_file_path).is_file():
3434
return
3535

36-
with pathlib.Path(self.cacheFilePath).open(encoding="utf-8") as f:
36+
with pathlib.Path(self.cache_file_path).open(encoding="utf-8") as f:
3737
try:
3838
self.memCache = json.load(f)
3939
except ValueError as e:
@@ -43,10 +43,10 @@ def _fileLoad(
4343
def _fileSave(
4444
self,
4545
) -> None:
46-
if self.cacheFilePath is None:
46+
if self.cache_file_path is None:
4747
return
4848

49-
with pathlib.Path(self.cacheFilePath).open("w", encoding="utf-8") as f:
49+
with pathlib.Path(self.cache_file_path).open("w", encoding="utf-8") as f:
5050
json.dump(self.memCache, f)
5151

5252
def put(

whoisdomain/context/parameterContext.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,7 @@
149149
class ParameterContext:
150150
params: dict[str, Any]
151151
value: dict[str, Any]
152-
153-
KT: dict[str, Any] = {
154-
"int": int,
155-
"float": float,
156-
"str": str,
157-
"bool": bool,
158-
}
152+
KT: dict[str, Any]
159153

160154
def _loadDefaults(self) -> list[str]:
161155
mandatory: list[str] = []
@@ -205,6 +199,13 @@ def __init__(
205199
self,
206200
**kwargs: Any,
207201
) -> None:
202+
self.KT = {
203+
"int": int,
204+
"float": float,
205+
"str": str,
206+
"bool": bool,
207+
}
208+
208209
self.params = json.loads(ParamsStringJson)
209210
self.value = {}
210211

whoisdomain/doWhoisCommand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def _initDefaultCache(
4646
# if no cache defined init the default cache (optional with file storage based on pc)
4747
CACHE_STUB = SimpleCacheWithFile(
4848
verbose=pc.verbose,
49-
cacheFilePath=pc.cache_file,
50-
cacheMaxAge=pc.cache_age,
49+
cache_file_path=pc.cache_file,
50+
cache_max_age=pc.cache_age,
5151
)
5252

5353
msg = "initializing default cache"

whoisdomain/exceptions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@
55
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
66

77

8-
class WhoisException(Exception):
8+
class WhoisExceptionError(Exception):
99
# make all other exeptions based on a generic exception
1010
pass
1111

1212

13-
class UnknownTld(WhoisException):
13+
class UnknownTldError(WhoisExceptionError):
1414
pass
1515

1616

17-
class FailedParsingWhoisOutput(WhoisException):
17+
class FailedParsingWhoisOutputError(WhoisExceptionError):
1818
pass
1919

2020

21-
class WhoisQuotaExceeded(WhoisException):
21+
class WhoisQuotaExceededError(WhoisExceptionError):
2222
pass
2323

2424

25-
class UnknownDateFormat(WhoisException):
25+
class UnknownDateFormatError(WhoisExceptionError):
2626
pass
2727

2828

29-
class WhoisCommandFailed(WhoisException):
29+
class WhoisCommandFailedError(WhoisExceptionError):
3030
pass
3131

3232

33-
class WhoisPrivateRegistry(WhoisException):
33+
class WhoisPrivateRegistryError(WhoisExceptionError):
3434
# also known as restricted : see comments at the bottom in tld_regexpr.py
3535
# almost no info is returned or there is no cli whois server at all:
3636
# see: https://www.iana.org/domains/root/db/<tld>.html
3737
pass
3838

3939

40-
class WhoisCommandTimeout(WhoisException):
40+
class WhoisCommandTimeoutError(WhoisExceptionError):
4141
pass

whoisdomain/handleDateStrings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import re
1111

12-
from .exceptions import UnknownDateFormat
12+
from .exceptions import UnknownDateFormatError
1313

1414
log = logging.getLogger(__name__)
1515
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
@@ -139,4 +139,4 @@ def str_to_date(
139139
return z.astimezone().replace(tzinfo=None)
140140

141141
msg = f"Unknown date format: '{text}'"
142-
raise UnknownDateFormat(msg)
142+
raise UnknownDateFormatError(msg)

whoisdomain/helpers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
)
66

77
from .context.parameterContext import ParameterContext
8-
from .exceptions import WhoisQuotaExceeded
8+
from .exceptions import WhoisQuotaExceededError
99
from .tldDb.tld_regexpr import ZZ
1010
from .tldInfo import TldInfo
1111
from .version import VERSION
@@ -17,30 +17,30 @@
1717
def filterTldToSupportedPattern(
1818
dList: list[str],
1919
) -> str | None:
20-
global tldInfo
21-
return tldInfo.filterTldToSupportedPattern(dList)
20+
global MY_TLD_INFO
21+
return MY_TLD_INFO.filterTldToSupportedPattern(dList)
2222

2323

2424
def mergeExternalDictWithRegex(
2525
aDict: dict[str, Any] | None = None,
2626
) -> None:
27-
global tldInfo
27+
global MY_TLD_INFO
2828
if aDict is None:
2929
return
3030
if len(aDict) == 0:
3131
return
3232

33-
tldInfo.mergeExternalDictWithRegex(aDict)
33+
MY_TLD_INFO.mergeExternalDictWithRegex(aDict)
3434

3535

3636
def validTlds() -> list[str]:
37-
global tldInfo
38-
return tldInfo.validTlds()
37+
global MY_TLD_INFO
38+
return MY_TLD_INFO.validTlds()
3939

4040

4141
def get_TLD_RE() -> dict[str, dict[str, Any]]:
42-
global tldInfo
43-
return tldInfo.TLD_RE()
42+
global MY_TLD_INFO
43+
return MY_TLD_INFO.TLD_RE()
4444

4545

4646
def getVersion() -> str:
@@ -76,7 +76,7 @@ def cleanupWhoisResponse(
7676
for line in tmp:
7777
# some servers respond with: % Quota exceeded in the comment section (lines starting with %)
7878
if "quota exceeded" in line.lower():
79-
raise WhoisQuotaExceeded(whoisStr)
79+
raise WhoisQuotaExceededError(whoisStr)
8080

8181
if pc.with_cleanup_results is True and line.startswith("%"): # only remove if requested
8282
continue
@@ -97,6 +97,6 @@ def cleanupWhoisResponse(
9797

9898
VERBOSE: bool = False
9999

100-
# Here we focre load on import the processing of the ZZ database
101-
tldInfo = TldInfo(ZZ, verbose=VERBOSE)
102-
tldInfo.init() # must run on import
100+
# Here we force-load on import the processing of the ZZ database
101+
MY_TLD_INFO = TldInfo(ZZ, verbose=VERBOSE)
102+
MY_TLD_INFO.init() # must run on import

0 commit comments

Comments
 (0)