Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.3.0 (TBD)
-----------

- Fixed deprecated query method of dnspython (#294 - monoidic)

1.2.0 (2020-09-17)
------------------

Expand Down
8 changes: 4 additions & 4 deletions ipwhois/asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def parse_fields_dns(self, response):
except Exception as e:

raise ASNParseError('Parsing failed for "{0}" with exception: {1}.'
''.format(response, e)[:100])
''.format(response, e)[:100]) from e

return ret

Expand Down Expand Up @@ -222,7 +222,7 @@ def parse_fields_verbose_dns(self, response):
except Exception as e:

raise ASNParseError('Parsing failed for "{0}" with exception: {1}.'
''.format(response, e)[:100])
''.format(response, e)[:100]) from e

return ret

Expand Down Expand Up @@ -279,7 +279,7 @@ def parse_fields_whois(self, response):
except Exception as e:

raise ASNParseError('Parsing failed for "{0}" with exception: {1}.'
''.format(response, e)[:100])
''.format(response, e)[:100]) from e

return ret

Expand Down Expand Up @@ -379,7 +379,7 @@ def parse_fields_http(self, response, extra_org_map=None):
except Exception as e: # pragma: no cover

raise ASNParseError('Parsing failed for "{0}" with exception: {1}.'
''.format(response, e)[:100])
''.format(response, e)[:100]) from e

return asn_data

Expand Down
6 changes: 3 additions & 3 deletions ipwhois/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def get_bulk_asn_whois(addresses=None, retry_count=3, timeout=120):

else:

raise ASNLookupError('ASN bulk lookup failed.')
raise ASNLookupError('ASN bulk lookup failed.') from e

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise ASNLookupError('ASN bulk lookup failed.')
raise ASNLookupError('ASN bulk lookup failed.') from e


def bulk_lookup_rdap(addresses=None, inc_raw=False, retry_count=3, depth=0,
Expand Down
63 changes: 30 additions & 33 deletions ipwhois/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def get_asn_dns(self):
try:

log.debug('ASN query for {0}'.format(self.dns_zone))
data = self.dns_resolver.query(self.dns_zone, 'TXT')
data = self.dns_resolver.resolve(self.dns_zone, 'TXT')
return list(data)

except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers,
Expand All @@ -229,13 +229,13 @@ def get_asn_dns(self):
raise ASNLookupError(
'ASN lookup failed (DNS {0}) for {1}.'.format(
e.__class__.__name__, self.address_str)
)
) from e

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise ASNLookupError(
'ASN lookup failed for {0}.'.format(self.address_str)
)
) from e

def get_asn_verbose_dns(self, asn=None):
"""
Expand All @@ -262,7 +262,7 @@ def get_asn_verbose_dns(self, asn=None):
try:

log.debug('ASN verbose query for {0}'.format(zone))
data = self.dns_resolver.query(zone, 'TXT')
data = self.dns_resolver.resolve(zone, 'TXT')
return str(data[0])

except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers,
Expand All @@ -271,13 +271,13 @@ def get_asn_verbose_dns(self, asn=None):
raise ASNLookupError(
'ASN lookup failed (DNS {0}) for {1}.'.format(
e.__class__.__name__, asn)
)
) from e

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise ASNLookupError(
'ASN lookup failed for {0}.'.format(asn)
)
) from e

def get_asn_whois(self, retry_count=3):
"""
Expand Down Expand Up @@ -337,13 +337,13 @@ def get_asn_whois(self, retry_count=3):

raise ASNLookupError(
'ASN lookup failed for {0}.'.format(self.address_str)
)
) from e

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise ASNLookupError(
'ASN lookup failed for {0}.'.format(self.address_str)
)
) from e

def get_asn_http(self, retry_count=3):
"""
Expand Down Expand Up @@ -391,9 +391,9 @@ def get_asn_http(self, retry_count=3):

raise ASNLookupError(
'ASN lookup failed for {0}.'.format(self.address_str)
)
) from e

except:
except BaseException as e:

raise ASNLookupError(
'ASN lookup failed for {0}.'.format(self.address_str)
Expand Down Expand Up @@ -505,11 +505,11 @@ def get_asn_origin_whois(self, asn_registry='radb', asn=None,

raise

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise WhoisLookupError(
'ASN origin WHOIS lookup failed for {0}.'.format(asn)
)
) from e

def get_whois(self, asn_registry='arin', retry_count=3, server=None,
port=43, extra_blacklist=None):
Expand Down Expand Up @@ -624,7 +624,7 @@ def get_whois(self, asn_registry='arin', retry_count=3, server=None,

raise WhoisLookupError(
'WHOIS lookup failed for {0}.'.format(self.address_str)
)
) from e

except WhoisRateLimitError: # pragma: no cover

Expand All @@ -634,7 +634,7 @@ def get_whois(self, asn_registry='arin', retry_count=3, server=None,

raise

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise WhoisLookupError(
'WHOIS lookup failed for {0}.'.format(self.address_str)
Expand Down Expand Up @@ -673,12 +673,9 @@ def get_http_json(self, url=None, retry_count=3, rate_limit_timeout=120,
# Create the connection for the whois query.
log.debug('HTTP query for {0} at {1}'.format(
self.address_str, url))
conn = Request(url, headers=headers)
data = self.opener.open(conn, timeout=self.timeout)
try:
d = json.loads(data.readall().decode('utf-8', 'ignore'))
except AttributeError: # pragma: no cover
d = json.loads(data.read().decode('utf-8', 'ignore'))
r = self.http_client.get(url, headers=headers)
r.raise_for_status()
d = r.json

try:
# Tests written but commented out. I do not want to send a
Expand Down Expand Up @@ -730,12 +727,12 @@ def get_http_json(self, url=None, retry_count=3, rate_limit_timeout=120,
raise HTTPRateLimitError(
'HTTP lookup failed for {0}. Rate limit '
'exceeded, wait and try again (possibly a '
'temporary block).'.format(url))
'temporary block).'.format(url)) from e

else:

raise HTTPLookupError('HTTP lookup failed for {0} with error '
'code {1}.'.format(url, str(e.code)))
'code {1}.'.format(url, str(e.code))) from e

except (URLError, socket.timeout, socket.error) as e:

Expand All @@ -753,15 +750,15 @@ def get_http_json(self, url=None, retry_count=3, rate_limit_timeout=120,
else:

raise HTTPLookupError('HTTP lookup failed for {0}.'.format(
url))
url)) from e

except (HTTPLookupError, HTTPRateLimitError) as e: # pragma: no cover

raise e

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise HTTPLookupError('HTTP lookup failed for {0}.'.format(url))
raise HTTPLookupError('HTTP lookup failed for {0}.'.format(url)) from e

def get_host(self, retry_count=3):
"""
Expand Down Expand Up @@ -819,11 +816,11 @@ def get_host(self, retry_count=3):
'Host lookup failed for {0}.'.format(self.address_str)
)

except: # pragma: no cover
except BaseException as e: # pragma: no cover

raise HostLookupError(
'Host lookup failed for {0}.'.format(self.address_str)
)
) from e

def get_http_raw(self, url=None, retry_count=3, headers=None,
request_type='GET', form_data=None):
Expand Down Expand Up @@ -896,12 +893,12 @@ def get_http_raw(self, url=None, retry_count=3, headers=None,
else:

raise HTTPLookupError('HTTP lookup failed for {0}.'.format(
url))
url)) from e

except HTTPLookupError as e: # pragma: no cover

raise e

except Exception: # pragma: no cover
except BaseException as e: # pragma: no cover

raise HTTPLookupError('HTTP lookup failed for {0}.'.format(url))
raise HTTPLookupError('HTTP lookup failed for {0}.'.format(url)) from e
20 changes: 10 additions & 10 deletions ipwhois/rdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ def __init__(self, json_result):

_RDAPCommon.__init__(self, json_result)

except ValueError:
except ValueError as e:

raise InvalidNetworkObject('JSON result must be a dict.')
raise InvalidNetworkObject('JSON result must be a dict.') from e

self.vars.update({
'start_address': None,
Expand All @@ -500,12 +500,12 @@ def parse(self):

self.vars['handle'] = self.json['handle'].strip()

except (KeyError, ValueError):
except (KeyError, ValueError) as e:

log.debug('Handle missing, json_output: {0}'.format(json.dumps(
self.json)))
raise InvalidNetworkObject('Handle is missing for RDAP network '
'object')
'object') from e

try:

Expand All @@ -529,12 +529,12 @@ def parse(self):
self.vars['start_address'] = self.json['startAddress'].strip()
self.vars['end_address'] = self.json['endAddress'].strip()

except (KeyError, ValueError, TypeError):
except (KeyError, ValueError, TypeError) as e:

log.debug('IP address data incomplete. Data parsed prior to '
'exception: {0}'.format(json.dumps(self.vars)))
raise InvalidNetworkObject('IP address data is missing for RDAP '
'network object.')
'network object.') from e

try:

Expand Down Expand Up @@ -587,9 +587,9 @@ def __init__(self, json_result):

_RDAPCommon.__init__(self, json_result)

except ValueError:
except ValueError as e:

raise InvalidEntityObject('JSON result must be a dict.')
raise InvalidEntityObject('JSON result must be a dict.') from e

self.vars.update({
'roles': None,
Expand All @@ -607,9 +607,9 @@ def parse(self):

self.vars['handle'] = self.json['handle'].strip()

except (KeyError, ValueError, TypeError):
except (KeyError, ValueError, TypeError) as e:

raise InvalidEntityObject('Handle is missing for RDAP entity')
raise InvalidEntityObject('Handle is missing for RDAP entity') from e

for v in ['roles', 'country']:

Expand Down
6 changes: 0 additions & 6 deletions ipwhois/tests/online/test_asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def test_lookup(self):
self.assertIsInstance(ipasn.lookup(inc_raw=True), dict)
except ASNRegistryError:
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))

Expand Down Expand Up @@ -80,10 +78,6 @@ def test_lookup(self):

raise e

except Exception as e:

self.fail('Unexpected exception raised: {0}'.format(e))

net = Net(address='74.125.225.229', timeout=0)
asnorigin = ASNOrigin(net)
self.assertRaises(ASNOriginLookupError, asnorigin.lookup, **dict(
Expand Down
4 changes: 0 additions & 4 deletions ipwhois/tests/online/test_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def test_get_bulk_asn_whois(self):
self.assertIsInstance(get_bulk_asn_whois(addresses=ips), str)
except ASNLookupError:
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))

Expand Down Expand Up @@ -86,7 +84,5 @@ def test_bulk_lookup_rdap(self):

except ASNLookupError:
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))
10 changes: 0 additions & 10 deletions ipwhois/tests/online/test_ipwhois.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def test_lookup_whois(self):
except (ASNLookupError, ASNRegistryError, WhoisLookupError,
HTTPLookupError):
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))

Expand All @@ -70,8 +68,6 @@ def test_lookup_whois(self):
inc_raw=True), dict)
except (ASNLookupError, ASNRegistryError, WhoisLookupError):
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))

Expand All @@ -86,8 +82,6 @@ def test_lookup_whois(self):
extra_blacklist=['rwhois.cogentco.com']), dict)
except (ASNLookupError, ASNRegistryError, WhoisLookupError):
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))

Expand Down Expand Up @@ -164,10 +158,6 @@ def test_lookup_rdap(self):
except (ASNLookupError, ASNRegistryError, WhoisLookupError,
HTTPLookupError):
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))

handler = ProxyHandler({'http': 'http://0.0.0.0:80/'})
opener = build_opener(handler)
Expand Down
Loading