|
6 | 6 |
|
7 | 7 | log = logging.getLogger(__name__) |
8 | 8 |
|
| 9 | + |
| 10 | +@dataclass(slots=True) |
| 11 | +class ParameterContext: |
| 12 | + # currently no params are mandatory |
| 13 | + |
| 14 | + # if the whois command fails with code 1 still process the data returned as normal. |
| 15 | + ignore_returncode: bool = False |
| 16 | + |
| 17 | + # Don't use cache. |
| 18 | + force: bool = False |
| 19 | + |
| 20 | + # bla bla |
| 21 | + verbose: bool = False |
| 22 | + |
| 23 | + # cleanup lines starting with % and REDACTED FOR PRIVACY |
| 24 | + with_cleanup_results: bool = False |
| 25 | + |
| 26 | + # if true convert with internationalizedDomainNameToPunyCode() |
| 27 | + internationalized: bool = False |
| 28 | + |
| 29 | + # if reqested the full response is also returned. |
| 30 | + include_raw_whois_text: bool = False |
| 31 | + |
| 32 | + # as it says |
| 33 | + return_raw_text_for_unsupported_tld: bool = False |
| 34 | + |
| 35 | + # try to parse partial response when cmd timed out |
| 36 | + # (stdbuf should be in PATH for best results) |
| 37 | + parse_partial_response: bool = False |
| 38 | + |
| 39 | + # when simplistic is true, |
| 40 | + # we return null for most exceptions and dont pass info why we have no data. |
| 41 | + simplistic: bool = False |
| 42 | + |
| 43 | + # show redacted output default no redacted data is shown |
| 44 | + withRedacted: bool = False |
| 45 | + |
| 46 | + # specify the path to the cli whois you want to use. |
| 47 | + cmd: str = "whois" |
| 48 | + |
| 49 | + # specify the path to the cli whois you want to use. |
| 50 | + cache_file: str | None = None |
| 51 | + |
| 52 | + # use this whois server for making this query: |
| 53 | + # Linux/Mac: 'whois -h <server> <domain>' |
| 54 | + # Windows: 'whois.exe <domain> <server>'" |
| 55 | + server: str | None = None |
| 56 | + |
| 57 | + # Cache expiration time for given domain in seconds 60*60*48 (48 hours). |
| 58 | + cache_age: int = 172800 |
| 59 | + |
| 60 | + # Time [s] it will wait after you query WHOIS database. |
| 61 | + slow_down: int = 0 |
| 62 | + |
| 63 | + # timeout in seconds for the whois command to return a result. |
| 64 | + timeout: float = 30.0 |
| 65 | + |
| 66 | + # allow auto install of sysinternals whois on windows if no whois found |
| 67 | + tryInstallMissingWhoisOnWindows: bool = False |
| 68 | + |
| 69 | + # The number of lines we consider a short response. |
| 70 | + shortResponseLen: int = 5 |
| 71 | + |
| 72 | + # if lib 'tld' is installed add tld info based on get_tld(); fake the tld if needed |
| 73 | + withPublicSuffix: bool = False |
| 74 | + |
| 75 | + # try to extract the whois servers from the whois output (uses --verbose) |
| 76 | + extractServers: bool = False |
| 77 | + |
| 78 | + # strip https://icann.org/epp# from status response |
| 79 | + stripHttpStatus: bool = False |
| 80 | + |
| 81 | + # if set to true we skip the strip www action |
| 82 | + noIgnoreWww: bool = False |
| 83 | + |
| 84 | + # if set to true we only consult rdap |
| 85 | + rdapOnly: bool = False |
| 86 | + |
| 87 | + # if set to true we only consult whois |
| 88 | + whoisOnly: bool = False |
| 89 | + |
| 90 | + def to_json(self) -> str: |
| 91 | + return json.dumps(asdict(self)) |
| 92 | + |
| 93 | + @classmethod |
| 94 | + def from_json(cls, s: str) -> "ParameterContext": |
| 95 | + return cls(**json.loads(s)) |
| 96 | + |
| 97 | + |
9 | 98 | ParamsStringJson: str = """ |
10 | 99 | { |
11 | 100 | "ignore_returncode": { |
|
156 | 245 | """ |
157 | 246 |
|
158 | 247 |
|
159 | | -@dataclass(slots=True) |
160 | 248 | class ParameterContext2: |
161 | | - # if the whois command fails with code 1 still process the data returned as normal. |
162 | | - ignore_returncode: bool = False |
163 | | - # Don't use cache. |
164 | | - force: bool = False |
165 | | - verbose: bool = False |
166 | | - # cleanup lines starting with % and REDACTED FOR PRIVACY |
167 | | - with_cleanup_results: bool = False |
168 | | - # if true convert with internationalizedDomainNameToPunyCode() |
169 | | - internationalized: bool = False |
170 | | - # if reqested the full response is also returned. |
171 | | - include_raw_whois_text: bool = False |
172 | | - return_raw_text_for_unsupported_tld: bool = False |
173 | | - # try to parse partial response when cmd timed out |
174 | | - # (stdbuf should be in PATH for best results) |
175 | | - parse_partial_response: bool = False |
176 | | - |
177 | | - # when simplistic is true, |
178 | | - # we return null for most exceptions and dont pass info why we have no data. |
179 | | - simplistic: bool = False |
180 | | - |
181 | | - # show redacted output default no redacted data is shown |
182 | | - withRedacted: bool = False |
183 | | - |
184 | | - # specify the path to the cli whois you want to use. |
185 | | - cmd: str = "whois" |
186 | | - |
187 | | - # specify the path to the cli whois you want to use. |
188 | | - cache_file: str | None = None |
189 | | - |
190 | | - # use this whois server for making this query: |
191 | | - # Linux/Mac: 'whois -h <server> <domain>' |
192 | | - # Windows: 'whois.exe <domain> <server>'" |
193 | | - server: str | None = None |
194 | | - |
195 | | - # Cache expiration time for given domain in seconds 60*60*48 (48 hours). |
196 | | - cache_age: int = 172800 |
197 | | - |
198 | | - # Time [s] it will wait after you query WHOIS database. |
199 | | - slow_down: int = 0 |
200 | | - |
201 | | - # timeout in seconds for the whois command to return a result. |
202 | | - timeout: float = 30.0 |
203 | | - |
204 | | - # allow auto install of sysinternals whois on windows if no whois found |
205 | | - tryInstallMissingWhoisOnWindows: bool = False |
206 | | - |
207 | | - # The number of lines we consider a short response. |
208 | | - shortResponseLen: int = 5 |
209 | | - |
210 | | - # if lib 'tld' is installed add tld info based on get_tld(); fake the tld if needed |
211 | | - withPublicSuffix: bool = False |
212 | | - |
213 | | - # try to extract the whois servers from the whois output (uses --verbose) |
214 | | - extractServers: bool = False |
215 | | - |
216 | | - # strip https://icann.org/epp# from status response |
217 | | - stripHttpStatus: bool = False |
218 | | - |
219 | | - # if set to true we skip the strip www action |
220 | | - noIgnoreWww: bool = False |
221 | | - |
222 | | - # if set to true we only consult rdap |
223 | | - rdapOnly: bool = False |
224 | | - |
225 | | - # if set to true we only consult whois |
226 | | - whoisOnly: bool = False |
227 | | - |
228 | | - def to_json(self) -> str: |
229 | | - return json.dumps(asdict(self)) |
230 | | - |
231 | | - @classmethod |
232 | | - def from_json(cls, s: str) -> "ParameterContext2": |
233 | | - return cls(**json.loads(s)) |
234 | | - |
235 | | - |
236 | | -class ParameterContext: |
237 | 249 | kt: dict[str, Any] |
238 | 250 | value: dict[str, Any] |
239 | 251 | params: dict[str, Any] |
@@ -355,13 +367,13 @@ def toJson( |
355 | 367 |
|
356 | 368 | def fromJson( |
357 | 369 | self, |
358 | | - jString: str, |
| 370 | + jstring: str, |
359 | 371 | ) -> None: |
360 | | - zz = json.loads(jString) |
| 372 | + zz = json.loads(jstring) |
361 | 373 | for k, v in zz.items(): |
362 | 374 | self.set(k, v) |
363 | 375 |
|
364 | 376 |
|
365 | 377 | if __name__ == "__main__": |
366 | 378 | pc = ParameterContext() |
367 | | - print(pc.value) |
| 379 | + print(asdict(pc)) |
0 commit comments