Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 794f919

Browse files
author
MooCow
authored
Merge pull request #237 from maarten-boot/master
add text to Domain result; but only if requested
2 parents 1e87df8 + 0d99842 commit 794f919

File tree

10 files changed

+29
-13
lines changed

10 files changed

+29
-13
lines changed

test2.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import sys
77

88
Verbose = False
9+
PrintGetRawWhoisResult = False
10+
911
Failures = {}
1012
IgnoreReturncode = False
1113

@@ -20,12 +22,15 @@ def xType(x):
2022
return s.split("'")[1]
2123

2224

23-
def testItem(d):
25+
def testItem(d: str, printgetRawWhoisResult: bool = False):
26+
global PrintGetRawWhoisResult
27+
2428
w = whois.query(
2529
d,
2630
ignore_returncode=IgnoreReturncode,
2731
verbose=Verbose,
2832
internationalized=True,
33+
include_raw_whois_text=PrintGetRawWhoisResult,
2934
)
3035

3136
if w is None:
@@ -174,6 +179,8 @@ def usage():
174179
# files are processed as in the -f option so comments and empty lines are skipped
175180
# the option can be repeated to specify more then one directory
176181
182+
[ -p | --print also print text containing the raw output of whois ]
183+
177184
# options are exclusive and without any options the test2 program does nothing
178185
179186
# test one specific file with verbose and IgnoreReturncode
@@ -214,12 +221,14 @@ def showFailures():
214221
def main(argv):
215222
global Verbose
216223
global IgnoreReturncode
224+
global PrintGetRawWhoisResult
217225

218226
try:
219227
opts, args = getopt.getopt(
220228
argv,
221-
"vIhaf:d:D:r:H:",
229+
"pvIhaf:d:D:r:H:",
222230
[
231+
"print",
223232
"verbose",
224233
"IgnoreReturncode",
225234
"all",
@@ -268,6 +277,9 @@ def main(argv):
268277
if opt in ("-v", "--verbose"):
269278
Verbose = True
270279

280+
if opt in ("-p", "--print"):
281+
PrintGetRawWhoisResult = True
282+
271283
if opt in ("-D", "--Directory"):
272284
directory = arg
273285
isDir = os.path.isdir(directory)
@@ -325,7 +337,6 @@ def main(argv):
325337
return
326338

327339
if len(domains):
328-
print("## ===== TEST DOMAINS")
329340
testDomains(domains)
330341
showFailures()
331342
return

testdata/example.com/output

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
## ===== TEST DOMAINS
21

32
test domain: <<<<<<<<<< example.com >>>>>>>>>>>>>>>>>>>>
43
name str 'example.com'

testdata/example.net/output

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
## ===== TEST DOMAINS
21

32
test domain: <<<<<<<<<< example.net >>>>>>>>>>>>>>>>>>>>
43
name str 'example.net'

testdata/example.org/input

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Name Server: a.iana-servers.net
5858
Name Server: b.iana-servers.net
5959
DNSSEC: signedDelegation
6060
URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
61-
>>> Last update of WHOIS database: 2022-11-07T09:27:18Z <<<
61+
>>> Last update of WHOIS database: 2022-11-07T21:05:05Z <<<
6262

6363
For more information on Whois status codes, please visit https://icann.org/epp
6464

testdata/example.org/output

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
## ===== TEST DOMAINS
21

32
test domain: <<<<<<<<<< example.org >>>>>>>>>>>>>>>>>>>>
43
name str 'example.org'

testdata/make_testdata.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#! /usr/bin/bash
22

33
DOMAINS=(
4-
example.net
5-
example.com
6-
example.org
7-
meta.co.uk
4+
example.net # has iana source
5+
example.com # has iana source
6+
example.org # has no iana source
7+
meta.co.uk # has multiline for all relevant fields and 4 nameservers; should be fixed output has only 2
8+
# xs4all.nl # has multiline nameserver and multiline registrar; outout has no nameservers should be 2
89
)
910

1011
for str in ${DOMAINS[@]}

testdata/meta.co.uk/input

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
c.ns.facebook.com
3232
d.ns.facebook.com
3333

34-
WHOIS lookup made at 09:27:19 07-Nov-2022
34+
WHOIS lookup made at 21:05:06 07-Nov-2022
3535

3636
--
3737
This WHOIS information is provided for free by Nominet UK the central registry

testdata/meta.co.uk/output

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
## ===== TEST DOMAINS
21

32
test domain: <<<<<<<<<< meta.co.uk >>>>>>>>>>>>>>>>>>>>
43
name str 'meta.co.uk'

whois/_3_adjust.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ class Domain:
3333
def __init__(
3434
self,
3535
data: Dict[str, Any],
36+
whois_str: Optional[str] = None,
3637
verbose: bool = False,
38+
include_raw_whois_text: bool = False,
3739
):
40+
if include_raw_whois_text and whois_str is not None:
41+
self.text = whois_str
42+
3843
self.name = data["domain_name"][0].strip().lower()
3944
self.tld = data["tld"]
4045

whois/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def query(
195195
verbose: bool = False,
196196
with_cleanup_results=False,
197197
internationalized: bool = False,
198+
include_raw_whois_text: bool = False,
198199
) -> Optional[Domain]:
199200
"""
200201
force=True Don't use cache.
@@ -285,7 +286,9 @@ def query(
285286
if pd and pd["domain_name"][0]:
286287
return Domain(
287288
pd,
289+
whois_str=q,
288290
verbose=verbose,
291+
include_raw_whois_text=include_raw_whois_text,
289292
)
290293

291294
if len(d) > (len(tldLevel) + 1):

0 commit comments

Comments
 (0)