WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4391cd9

Browse files
committed
ruff formatting, resolves #57
1 parent 6385250 commit 4391cd9

17 files changed

+1886
-1343
lines changed

setup.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,58 @@
11
from setuptools import setup, find_packages
22

33

4-
version = '3.1.1'
4+
version = "3.1.1"
55

66

7-
with open('README.md', 'rt') as f:
7+
with open("README.md", "rt") as f:
88
long_description = f.read()
99

1010

11-
with open('requirements.txt', 'rt') as f:
11+
with open("requirements.txt", "rt") as f:
1212
requirements = tuple(f.read().split())
1313

1414

1515
setup(
16-
name = 'whoisit',
17-
version = version,
18-
url = 'https://github.com/meeb/whoisit',
19-
author = 'https://github.com/meeb',
20-
author_email = '[email protected]',
21-
description = 'A Python client to RDAP WHOIS-like services for internet resources.',
22-
long_description = long_description,
23-
long_description_content_type = 'text/markdown',
24-
license = 'BSD',
25-
include_package_data = True,
26-
install_requires = requirements,
27-
packages = find_packages(exclude=('tests',)),
28-
classifiers = [
29-
'Development Status :: 5 - Production/Stable',
30-
'Environment :: Web Environment',
31-
'Intended Audience :: Developers',
32-
'License :: OSI Approved :: BSD License',
33-
'Operating System :: OS Independent',
34-
'Programming Language :: Python',
35-
'Programming Language :: Python :: 3',
36-
'Topic :: Software Development :: Libraries :: Python Modules',
16+
name="whoisit",
17+
version=version,
18+
url="https://github.com/meeb/whoisit",
19+
author="https://github.com/meeb",
20+
author_email="[email protected]",
21+
description="A Python client to RDAP WHOIS-like services for internet resources.",
22+
long_description=long_description,
23+
long_description_content_type="text/markdown",
24+
license="BSD",
25+
include_package_data=True,
26+
install_requires=requirements,
27+
packages=find_packages(exclude=("tests",)),
28+
classifiers=[
29+
"Development Status :: 5 - Production/Stable",
30+
"Environment :: Web Environment",
31+
"Intended Audience :: Developers",
32+
"License :: OSI Approved :: BSD License",
33+
"Operating System :: OS Independent",
34+
"Programming Language :: Python",
35+
"Programming Language :: Python :: 3",
36+
"Topic :: Software Development :: Libraries :: Python Modules",
37+
],
38+
keywords=[
39+
"whoisit",
40+
"whois",
41+
"rdap",
42+
"ip",
43+
"network",
44+
"cidr",
45+
"prefix",
46+
"domain",
47+
"asn",
48+
"autnum",
49+
"tld",
50+
"entity",
51+
"handle",
52+
"arin",
53+
"afrinic",
54+
"apnic",
55+
"ripe",
56+
"lacnic",
3757
],
38-
keywords = ['whoisit', 'whois', 'rdap', 'ip', 'network', 'cidr', 'prefix', 'domain',
39-
'asn', 'autnum', 'tld', 'entity', 'handle', 'arin', 'afrinic', 'apnic',
40-
'ripe', 'lacnic']
4158
)

tests/test_bootstrap.py

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010

1111
class BootstrapTestCase(unittest.TestCase):
12-
1312
maxDiff = None
1413

1514
def setUp(self):
1615
whoisit.clear_bootstrapping()
17-
with open(BASE_DIR / 'data_bootstrap.json', 'rt') as f:
16+
with open(BASE_DIR / "data_bootstrap.json", "rt") as f:
1817
self.bootstrap_data = f.read()
1918

2019
def tearDown(self):
@@ -32,13 +31,13 @@ def test_bootstrap_saving(self):
3231
def test_bootstrap_loading(self):
3332
whoisit.clear_bootstrapping()
3433
with self.assertRaises(whoisit.errors.BootstrapError):
35-
whoisit.load_bootstrap_data('')
34+
whoisit.load_bootstrap_data("")
3635
with self.assertRaises(whoisit.errors.BootstrapError):
3736
whoisit.load_bootstrap_data('{"some":"dict"}')
3837
with self.assertRaises(whoisit.errors.BootstrapError):
3938
whoisit.load_bootstrap_data(12345)
4039
with self.assertRaises(whoisit.errors.BootstrapError):
41-
whoisit.load_bootstrap_data(b'test')
40+
whoisit.load_bootstrap_data(b"test")
4241
whoisit.clear_bootstrapping()
4342
self.assertFalse(whoisit.is_bootstrapped())
4443
whoisit.load_bootstrap_data(self.bootstrap_data)
@@ -49,8 +48,8 @@ def test_bootstrap_loading(self):
4948
whoisit.clear_bootstrapping()
5049

5150
def test_bootstrap_asn_parser(self):
52-
test_rdap_url = 'https://rdap.example.com/'
53-
test_data = [[['1-2', '6-7', '9'], [test_rdap_url]]]
51+
test_rdap_url = "https://rdap.example.com/"
52+
test_data = [[["1-2", "6-7", "9"], [test_rdap_url]]]
5453
expected = {
5554
(1, 2): [test_rdap_url],
5655
(6, 7): [test_rdap_url],
@@ -59,57 +58,56 @@ def test_bootstrap_asn_parser(self):
5958
self.assertEqual(whoisit._bootstrap.parse_asn_data(test_data), expected)
6059

6160
def test_bootstrap_dns_parser(self):
62-
test_rdap_url = 'https://rdap.example.com/'
63-
test_data = [[['a', 'b', 'c'], [test_rdap_url]]]
61+
test_rdap_url = "https://rdap.example.com/"
62+
test_data = [[["a", "b", "c"], [test_rdap_url]]]
6463
expected = {
65-
'a': [test_rdap_url],
66-
'b': [test_rdap_url],
67-
'c': [test_rdap_url],
64+
"a": [test_rdap_url],
65+
"b": [test_rdap_url],
66+
"c": [test_rdap_url],
6867
}
6968
self.assertEqual(whoisit._bootstrap.parse_dns_data(test_data), expected)
7069

7170
def test_bootstrap_ipv4_parser(self):
72-
test_rdap_url = 'https://rdap.example.com/'
73-
test_data = [[['10.0.0.0/8', '127.0.0.0/8'], [test_rdap_url]]]
71+
test_rdap_url = "https://rdap.example.com/"
72+
test_data = [[["10.0.0.0/8", "127.0.0.0/8"], [test_rdap_url]]]
7473
expected = {
75-
IPv4Network('10.0.0.0/8'): [test_rdap_url],
76-
IPv4Network('127.0.0.0/8'): [test_rdap_url],
74+
IPv4Network("10.0.0.0/8"): [test_rdap_url],
75+
IPv4Network("127.0.0.0/8"): [test_rdap_url],
7776
}
7877
self.assertEqual(whoisit._bootstrap.parse_ipv4_data(test_data), expected)
7978

8079
def test_bootstrap_ipv6_parser(self):
81-
test_rdap_url = 'https://rdap.example.com/'
82-
test_data = [[['2001:1400::/22', '2001:200::/23'], [test_rdap_url]]]
80+
test_rdap_url = "https://rdap.example.com/"
81+
test_data = [[["2001:1400::/22", "2001:200::/23"], [test_rdap_url]]]
8382
expected = {
84-
IPv6Network('2001:1400::/22'): [test_rdap_url],
85-
IPv6Network('2001:200::/23'): [test_rdap_url],
83+
IPv6Network("2001:1400::/22"): [test_rdap_url],
84+
IPv6Network("2001:200::/23"): [test_rdap_url],
8685
}
8786
self.assertEqual(whoisit._bootstrap.parse_ipv6_data(test_data), expected)
8887

8988
def test_bootstrap_object_parser(self):
90-
test_rdap_url = 'https://rdap.example.com/'
91-
test_data = [[['does', 'nothing', 'yet'], [test_rdap_url]]]
89+
test_rdap_url = "https://rdap.example.com/"
90+
test_data = [[["does", "nothing", "yet"], [test_rdap_url]]]
9291
expected = {}
9392
self.assertEqual(whoisit._bootstrap.parse_object_data(test_data), expected)
9493

9594
def test_bootstrap_full_parsing(self):
96-
9795
# Load bootstrap data
9896
whoisit.clear_bootstrapping()
9997
whoisit.load_bootstrap_data(self.bootstrap_data)
10098

10199
# ASN endpoint tests
102100
test = 327691
103-
expected = ['https://rdap.afrinic.net/rdap/'], True
101+
expected = ["https://rdap.afrinic.net/rdap/"], True
104102
self.assertEqual(whoisit._bootstrap.get_asn_endpoints(test), expected)
105103
test = 4567
106-
expected = ['https://rdap.arin.net/registry/'], True
104+
expected = ["https://rdap.arin.net/registry/"], True
107105
self.assertEqual(whoisit._bootstrap.get_asn_endpoints(test), expected)
108106
test = 206236
109-
expected = ['https://rdap.db.ripe.net/'], True
107+
expected = ["https://rdap.db.ripe.net/"], True
110108
self.assertEqual(whoisit._bootstrap.get_asn_endpoints(test), expected)
111109
test = 2047
112-
expected = ['https://rdap.db.ripe.net/'], True
110+
expected = ["https://rdap.db.ripe.net/"], True
113111
self.assertEqual(whoisit._bootstrap.get_asn_endpoints(test), expected)
114112
# One of the random fallbacks for an invalid ASN
115113
test = 59438593485903
@@ -123,97 +121,107 @@ def test_bootstrap_full_parsing(self):
123121
self.assertEqual(exact_match, False)
124122

125123
# Domain endpoint tests
126-
test = 'com'
127-
expected = ['https://rdap.verisign.com/com/v1/'], True
124+
test = "com"
125+
expected = ["https://rdap.verisign.com/com/v1/"], True
128126
self.assertEqual(whoisit._bootstrap.get_dns_endpoints(test), expected)
129-
test = 'no'
130-
expected = ['https://rdap.norid.no/'], True
127+
test = "no"
128+
expected = ["https://rdap.norid.no/"], True
131129
self.assertEqual(whoisit._bootstrap.get_dns_endpoints(test), expected)
132-
test = 'dev'
133-
expected = ['https://www.registry.google/rdap/'], True
130+
test = "dev"
131+
expected = ["https://www.registry.google/rdap/"], True
134132
self.assertEqual(whoisit._bootstrap.get_dns_endpoints(test), expected)
135133
# Invalid TLDs should raise an error
136-
test = 'testtesttesttesttesttesttesttesttesttesttest'
134+
test = "testtesttesttesttesttesttesttesttesttesttest"
137135
with self.assertRaises(whoisit.errors.UnsupportedError):
138136
whoisit._bootstrap.get_dns_endpoints(test)
139137

140138
# IPv4 prefix endpoint tests
141-
test = IPv4Address('1.1.1.1')
142-
expected = ['https://rdap.apnic.net/'], True
139+
test = IPv4Address("1.1.1.1")
140+
expected = ["https://rdap.apnic.net/"], True
143141
self.assertEqual(whoisit._bootstrap.get_ipv4_endpoints(test), expected)
144-
test = IPv4Network('1.1.1.0/24')
145-
expected = ['https://rdap.apnic.net/'], True
142+
test = IPv4Network("1.1.1.0/24")
143+
expected = ["https://rdap.apnic.net/"], True
146144
self.assertEqual(whoisit._bootstrap.get_ipv4_endpoints(test), expected)
147-
test = IPv4Address('8.8.8.8')
148-
expected = ['https://rdap.arin.net/registry/'], True
145+
test = IPv4Address("8.8.8.8")
146+
expected = ["https://rdap.arin.net/registry/"], True
149147
self.assertEqual(whoisit._bootstrap.get_ipv4_endpoints(test), expected)
150-
test = IPv4Network('8.8.8.0/24')
151-
expected = ['https://rdap.arin.net/registry/'], True
148+
test = IPv4Network("8.8.8.0/24")
149+
expected = ["https://rdap.arin.net/registry/"], True
152150
self.assertEqual(whoisit._bootstrap.get_ipv4_endpoints(test), expected)
153151
with self.assertRaises(whoisit.errors.BootstrapError):
154152
# Private IP addresses can't have a public RDAP endpoint at all
155-
whoisit._bootstrap.get_ipv4_endpoints(IPv4Address('127.0.0.1'))
153+
whoisit._bootstrap.get_ipv4_endpoints(IPv4Address("127.0.0.1"))
156154

157155
# IPv6 prefix endpoint tests
158-
test = IPv6Address('2606:4700:4700::1111')
159-
expected = ['https://rdap.arin.net/registry/'], True
156+
test = IPv6Address("2606:4700:4700::1111")
157+
expected = ["https://rdap.arin.net/registry/"], True
160158
self.assertEqual(whoisit._bootstrap.get_ipv6_endpoints(test), expected)
161-
test = IPv6Network('2606:4700::/32')
162-
expected = ['https://rdap.arin.net/registry/'], True
159+
test = IPv6Network("2606:4700::/32")
160+
expected = ["https://rdap.arin.net/registry/"], True
163161
self.assertEqual(whoisit._bootstrap.get_ipv6_endpoints(test), expected)
164-
test = IPv6Address('2001:67c:2e8:22::c100:68b')
165-
expected = ['https://rdap.db.ripe.net/'], True
162+
test = IPv6Address("2001:67c:2e8:22::c100:68b")
163+
expected = ["https://rdap.db.ripe.net/"], True
166164
self.assertEqual(whoisit._bootstrap.get_ipv6_endpoints(test), expected)
167-
test = IPv6Network('2001:67c:2e8::/48')
168-
expected = ['https://rdap.db.ripe.net/'], True
165+
test = IPv6Network("2001:67c:2e8::/48")
166+
expected = ["https://rdap.db.ripe.net/"], True
169167
self.assertEqual(whoisit._bootstrap.get_ipv6_endpoints(test), expected)
170168
with self.assertRaises(whoisit.errors.BootstrapError):
171169
# Private IP addresses can't have a public RDAP endpoint at all
172-
whoisit._bootstrap.get_ipv6_endpoints(IPv6Address('fc00::1'))
170+
whoisit._bootstrap.get_ipv6_endpoints(IPv6Address("fc00::1"))
173171

174172
# Entity endpoint tests with prefixes
175-
test = 'ENTITY-RIPE'
176-
expected = ['https://rdap.db.ripe.net/'], True
173+
test = "ENTITY-RIPE"
174+
expected = ["https://rdap.db.ripe.net/"], True
177175
self.assertEqual(whoisit._bootstrap.get_entity_endpoints(test), expected)
178-
test = 'ENTITY-AP'
179-
expected = ['https://rdap.apnic.net/'], True
176+
test = "ENTITY-AP"
177+
expected = ["https://rdap.apnic.net/"], True
180178
self.assertEqual(whoisit._bootstrap.get_entity_endpoints(test), expected)
181-
test = 'ARIN-ENTITY'
182-
expected = ['https://rdap.arin.net/registry/'], True
179+
test = "ARIN-ENTITY"
180+
expected = ["https://rdap.arin.net/registry/"], True
183181
self.assertEqual(whoisit._bootstrap.get_entity_endpoints(test), expected)
184182
# Entities without a prefix or postfix we can parse are unsupported
185183
with self.assertRaises(whoisit.errors.UnsupportedError):
186-
whoisit._bootstrap.get_entity_endpoints('ANYTHING')
184+
whoisit._bootstrap.get_entity_endpoints("ANYTHING")
187185

188186
# Clean up
189187
whoisit.clear_bootstrapping()
190188

191189
def test_override_endpoint(self):
192-
193190
# Load bootstrap data
194191
whoisit.clear_bootstrapping()
195192
whoisit.load_bootstrap_data(self.bootstrap_data)
196193

197194
# Invalid RIR endpoint name
198195
with self.assertRaises(whoisit.errors.BootstrapError):
199-
whoisit._bootstrap.get_rir_endpoint('test')
196+
whoisit._bootstrap.get_rir_endpoint("test")
200197

201198
# Check the RIRs are all supported
202199
for name, endpoint in whoisit._bootstrap.RIR_RDAP_ENDPOINTS.items():
203200
self.assertEqual(whoisit._bootstrap.get_rir_endpoint(name), endpoint)
204201

205202
# Check the RIR names are valid
206-
expected = ('afnic', 'afrinic', 'arin', 'apnic', 'jpnic', 'idnic', 'krnic',
207-
'lacnic', 'registro.br', 'ripe', 'twnic')
203+
expected = (
204+
"afnic",
205+
"afrinic",
206+
"arin",
207+
"apnic",
208+
"jpnic",
209+
"idnic",
210+
"krnic",
211+
"lacnic",
212+
"registro.br",
213+
"ripe",
214+
"twnic",
215+
)
208216
self.assertEqual(whoisit._bootstrap.get_rir_endpoint_names(), expected)
209217

210218
# Clean up
211219
whoisit.clear_bootstrapping()
212220

213221
def test_iana_overrides(self):
214-
215222
# Test iana_overrides are a dict
216223
from whoisit.overrides import iana_overrides
224+
217225
self.assertIsInstance(iana_overrides, dict)
218226

219227
# Test bootstrapping with overrides disabled
@@ -222,32 +230,31 @@ def test_iana_overrides(self):
222230
self.assertFalse(whoisit._bootstrap.is_using_overrides())
223231
with self.assertRaises(whoisit.errors.UnsupportedError):
224232
# .de has no RDAP entry in IANA data currently, this should error
225-
whoisit._bootstrap.get_dns_endpoints('de')
233+
whoisit._bootstrap.get_dns_endpoints("de")
226234

227235
# Test bootstrapping with overrides enabled
228236
whoisit.clear_bootstrapping()
229237
whoisit.load_bootstrap_data(self.bootstrap_data, overrides=True)
230238
self.assertTrue(whoisit._bootstrap.is_using_overrides())
231239
# .de has endpoint overrides
232-
override_endpoints, match = whoisit._bootstrap.get_dns_endpoints('de')
233-
self.assertEqual(override_endpoints[0], 'https://rdap.denic.de/')
240+
override_endpoints, match = whoisit._bootstrap.get_dns_endpoints("de")
241+
self.assertEqual(override_endpoints[0], "https://rdap.denic.de/")
234242
self.assertFalse(match)
235243

236244
def test_insecure_scheme_endpoints(self):
237-
238245
# Test secure HTTPS endpoints, the default
239246
whoisit.clear_bootstrapping()
240247
whoisit.load_bootstrap_data(self.bootstrap_data, allow_insecure=False)
241248
self.assertFalse(whoisit._bootstrap.is_allowing_insecure_endpoints())
242249
with self.assertRaises(whoisit.errors.UnsupportedError):
243250
# .uz only has an insecure HTTP RDAP entry in IANA data
244-
whoisit._bootstrap.get_dns_endpoints('uz')
251+
whoisit._bootstrap.get_dns_endpoints("uz")
245252

246253
# Test bootstrapping with insecure endpoints allowed
247254
whoisit.clear_bootstrapping()
248255
whoisit.load_bootstrap_data(self.bootstrap_data, allow_insecure=True)
249256
self.assertTrue(whoisit._bootstrap.is_allowing_insecure_endpoints())
250257
# .uz should now have a valid RDAP endpoint over HTTP
251-
override_endpoints, match = whoisit._bootstrap.get_dns_endpoints('uz')
252-
self.assertEqual(override_endpoints[0], 'http://cctld.uz:9000/')
258+
override_endpoints, match = whoisit._bootstrap.get_dns_endpoints("uz")
259+
self.assertEqual(override_endpoints[0], "http://cctld.uz:9000/")
253260
self.assertTrue(match)

0 commit comments

Comments
 (0)