Merge pull request #224 from secynic/203/deprecationwarnings

Fixed deprecation warnings in core code (#203 - cstranex)
This commit is contained in:
Philip Hane 2019-01-28 22:46:19 -06:00 committed by GitHub
commit 09a05f9af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 71 additions and 70 deletions

View File

@ -10,6 +10,7 @@ Changelog
- Fixed bug in ASN HTTP lookup where the ARIN results were reversed, and
parsing would fail on the first item (#220)
- Removed support for Python 2.6/3.3, added support for 3.7 (#221)
- Fixed deprecation warnings in core code (#203 - cstranex)
1.0.0 (2017-07-30)
------------------

View File

@ -174,7 +174,7 @@ Input
| allow_permutations | bool | Allow net.Net() to use additional methods if |
| | | DNS lookups to Cymru fail. *WARNING* |
| | | deprecated in favor of new argument |
| | | asn_methods. Defaults to True. |
| | | asn_methods. Defaults to False. |
+--------------------+--------+-----------------------------------------------+
RDAP (HTTP)

View File

@ -511,7 +511,7 @@ class IPASN:
asn_data_list = []
for asn_entry in response:
asn_data_list.append(self._parse_fields_dns(
asn_data_list.append(self.parse_fields_dns(
str(asn_entry)))
# Iterate through the parsed ASN results to find the
@ -544,7 +544,7 @@ class IPASN:
try:
response = self._net.get_asn_whois(retry_count)
asn_data = self._parse_fields_whois(
asn_data = self.parse_fields_whois(
response) # pragma: no cover
break
@ -560,7 +560,7 @@ class IPASN:
response = self._net.get_asn_http(
retry_count=retry_count
)
asn_data = self._parse_fields_http(response,
asn_data = self.parse_fields_http(response,
extra_org_map)
break
@ -916,7 +916,7 @@ class ASNOrigin:
results['raw'] = response
nets = []
nets_response = self._get_nets_radb(response, is_http)
nets_response = self.get_nets_radb(response, is_http)
nets.extend(nets_response)
@ -936,7 +936,7 @@ class ASNOrigin:
section_end = nets[index + 1]['start']
temp_net = self._parse_fields(
temp_net = self.parse_fields(
response,
fields['radb']['fields'],
section_end,

View File

@ -48,7 +48,7 @@ class IPWhois:
"""
def __init__(self, address, timeout=5, proxy_opener=None,
allow_permutations=True):
allow_permutations=False):
self.net = Net(
address=address, timeout=timeout, proxy_opener=proxy_opener,

View File

@ -113,7 +113,7 @@ class Net:
"""
def __init__(self, address, timeout=5, proxy_opener=None,
allow_permutations=True):
allow_permutations=False):
# IPv4Address or IPv6Address
if isinstance(address, IPv4Address) or isinstance(

View File

@ -483,7 +483,7 @@ class NIRWhois:
request_type=NIR_WHOIS[nir]['request_type']
)
return self._parse_fields(
return self.parse_fields(
response=contact_response,
fields_dict=NIR_WHOIS[nir]['contact_fields'],
dt_format=dt_format,
@ -582,11 +582,11 @@ class NIRWhois:
nets_response = None
if nir == 'jpnic':
nets_response = self._get_nets_jpnic(response)
nets_response = self.get_nets_jpnic(response)
elif nir == 'krnic':
nets_response = self._get_nets_krnic(response)
nets_response = self.get_nets_krnic(response)
nets.extend(nets_response)
@ -609,7 +609,7 @@ class NIRWhois:
dt_format = None
temp_net = self._parse_fields(
temp_net = self.parse_fields(
response=response,
fields_dict=NIR_WHOIS[nir]['fields'],
net_start=section_end,
@ -659,7 +659,7 @@ class NIRWhois:
tmp_response = None
tmp_handle = contact
temp_net['contacts'][key] = self._get_contact(
temp_net['contacts'][key] = self.get_contact(
response=tmp_response,
handle=tmp_handle,
nir=nir,

View File

@ -35,16 +35,14 @@ class TestIPASN(TestCommon):
ipasn.lookup(asn_methods=['dns', 'whois', 'http'])
ipasn.lookup(asn_methods=['http'])
net = Net(address='74.125.225.229', timeout=0,
allow_permutations=False)
net = Net(address='74.125.225.229', timeout=0)
ipasn = IPASN(net)
self.assertRaises(ASNRegistryError, ipasn.lookup)
net = Net(address='74.125.225.229', timeout=0,
allow_permutations=True)
net = Net(address='74.125.225.229', timeout=0)
ipasn = IPASN(net)
self.assertRaises(ASNRegistryError, ipasn.lookup, **dict(
asn_alts=['http']))
asn_methods=['http']))
class TestASNOrigin(TestCommon):
@ -86,12 +84,11 @@ class TestASNOrigin(TestCommon):
self.fail('Unexpected exception raised: {0}'.format(e))
net = Net(address='74.125.225.229', timeout=0,
allow_permutations=True)
net = Net(address='74.125.225.229', timeout=0)
asnorigin = ASNOrigin(net)
self.assertRaises(ASNOriginLookupError, asnorigin.lookup, **dict(
asn='15169',
asn_alts=['http']))
asn_methods=['http']))
self.assertRaises(ValueError, asnorigin.lookup, **dict(
asn='15169',

View File

@ -3,6 +3,7 @@ from ipwhois.tests import TestCommon
from ipwhois.exceptions import (ASNLookupError, ASNRegistryError,
BlacklistError, WhoisLookupError,
HTTPLookupError, HostLookupError)
from ipwhois.asn import IPASN
from ipwhois.net import Net
LOG_FORMAT = ('[%(asctime)s] [%(levelname)s] [%(filename)s:%(lineno)s] '
@ -14,10 +15,12 @@ log = logging.getLogger(__name__)
class TestNet(TestCommon):
def test_lookup_asn(self):
# TODO: keep until deprecated lookup is removed, for coverage
net = Net('74.125.225.229')
ipasn = IPASN(net)
try:
self.assertIsInstance(net.lookup_asn(), tuple)
self.assertIsInstance(ipasn.lookup(), dict)
except HTTPLookupError:
pass
except AssertionError as e:

View File

@ -21,23 +21,23 @@ class TestIPASN(TestCommon):
self.assertRaises(NetError, IPASN, 'a')
def test__parse_fields_dns(self):
def test_parse_fields_dns(self):
data = '"15169 | 74.125.225.0/24 | US | arin | 2007-03-13"'
net = Net('74.125.225.229')
ipasn = IPASN(net)
try:
self.assertIsInstance(ipasn._parse_fields_dns(data), dict)
self.assertIsInstance(ipasn.parse_fields_dns(data), dict)
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: {0}'.format(e))
data = '"15169 | 74.125.225.0/24 | US | random | 2007-03-13"'
self.assertRaises(ASNRegistryError, ipasn._parse_fields_dns, data)
self.assertRaises(ASNRegistryError, ipasn.parse_fields_dns, data)
data = ''
self.assertRaises(ASNParseError, ipasn._parse_fields_dns, data)
self.assertRaises(ASNParseError, ipasn.parse_fields_dns, data)
def test_parse_fields_verbose_dns(self):
@ -58,14 +58,14 @@ class TestIPASN(TestCommon):
data = ''
self.assertRaises(ASNParseError, ipasn.parse_fields_verbose_dns, data)
def test__parse_fields_whois(self):
def test_parse_fields_whois(self):
data = ('15169 | 74.125.225.229 | 74.125.225.0/24 | US | arin'
' | 2007-03-13 | GOOGLE - Google Inc., US')
net = Net('74.125.225.229')
ipasn = IPASN(net)
try:
self.assertIsInstance(ipasn._parse_fields_whois(data), dict)
self.assertIsInstance(ipasn.parse_fields_whois(data), dict)
except AssertionError as e:
raise e
except Exception as e:
@ -73,12 +73,12 @@ class TestIPASN(TestCommon):
data = ('15169 | 74.125.225.229 | 74.125.225.0/24 | US | rdm'
' | 2007-03-13 | GOOGLE - Google Inc., US')
self.assertRaises(ASNRegistryError, ipasn._parse_fields_whois, data)
self.assertRaises(ASNRegistryError, ipasn.parse_fields_whois, data)
data = '15169 | 74.125.225.229 | 74.125.225.0/24 | US'
self.assertRaises(ASNParseError, ipasn._parse_fields_whois, data)
self.assertRaises(ASNParseError, ipasn.parse_fields_whois, data)
def test__parse_fields_http(self):
def test_parse_fields_http(self):
data = {
'nets': {
@ -92,7 +92,7 @@ class TestIPASN(TestCommon):
net = Net('1.2.3.4')
ipasn = IPASN(net)
try:
self.assertIsInstance(ipasn._parse_fields_http(response=data),
self.assertIsInstance(ipasn.parse_fields_http(response=data),
dict)
except AssertionError as e:
raise e
@ -101,7 +101,7 @@ class TestIPASN(TestCommon):
data['nets']['net']['orgRef']['@handle'] = 'RIPE'
try:
self.assertIsInstance(ipasn._parse_fields_http(response=data),
self.assertIsInstance(ipasn.parse_fields_http(response=data),
dict)
except AssertionError as e:
raise e
@ -110,7 +110,7 @@ class TestIPASN(TestCommon):
data['nets']['net']['orgRef']['@handle'] = 'DNIC'
try:
self.assertIsInstance(ipasn._parse_fields_http(response=data),
self.assertIsInstance(ipasn.parse_fields_http(response=data),
dict)
except AssertionError as e:
raise e
@ -119,7 +119,7 @@ class TestIPASN(TestCommon):
data['nets']['net']['orgRef']['@handle'] = 'INVALID'
try:
self.assertRaises(ASNRegistryError, ipasn._parse_fields_http,
self.assertRaises(ASNRegistryError, ipasn.parse_fields_http,
response=data)
except AssertionError as e:
raise e
@ -128,7 +128,7 @@ class TestIPASN(TestCommon):
data = ''
try:
self.assertRaises(ASNRegistryError, ipasn._parse_fields_http,
self.assertRaises(ASNRegistryError, ipasn.parse_fields_http,
response=data)
except AssertionError as e:
raise e
@ -175,7 +175,7 @@ class TestASNOrigin(TestCommon):
self.fail('Unexpected exception raised: {0}'.format(e))
def test__parse_fields(self):
def test_parse_fields(self):
net = Net('74.125.225.229')
obj = ASNOrigin(net)
@ -184,12 +184,12 @@ class TestASNOrigin(TestCommon):
# groups are messed up.
tmp_dict = ASN_ORIGIN_WHOIS['radb']['fields']
tmp_dict['route'] = r'(route):[^\S\n]+(?P<val1>.+?)\n'
obj._parse_fields(
obj.parse_fields(
response="\nroute: 66.249.64.0/20\n",
fields_dict=tmp_dict
)
obj._parse_fields(
obj.parse_fields(
response="\nchanged: noc@google.com 20110301\n",
fields_dict=ASN_ORIGIN_WHOIS['radb']['fields']
)
@ -211,7 +211,7 @@ class TestASNOrigin(TestCommon):
'\nsource: RADB'
'\n\n'
)
obj._parse_fields(
obj.parse_fields(
response=multi_net_response,
fields_dict=ASN_ORIGIN_WHOIS['radb']['fields']
)
@ -240,9 +240,9 @@ class TestASNOrigin(TestCommon):
'\nsource: RADB'
'\n\n'
)
obj._get_nets_radb(multi_net_response)
obj.get_nets_radb(multi_net_response)
self.assertEqual(obj._get_nets_radb(multi_net_response, is_http=True),
self.assertEqual(obj.get_nets_radb(multi_net_response, is_http=True),
[])
net = Net('2001:43f8:7b0::')
@ -259,7 +259,7 @@ class TestASNOrigin(TestCommon):
'\n\n'
)
self.assertEquals(
obj._get_nets_radb(multi_net_response),
obj.get_nets_radb(multi_net_response),
[{
'updated': None,
'maintainer': None,

View File

@ -57,7 +57,7 @@ class TestNIRWhois(TestCommon):
self.assertRaises(KeyError, obj.lookup)
self.assertRaises(KeyError, obj.lookup, **dict(nir='a'))
def test__parse_fields(self):
def test_parse_fields(self):
net = Net('133.1.2.5')
obj = NIRWhois(net)
@ -66,13 +66,13 @@ class TestNIRWhois(TestCommon):
# groups are messed up.
tmp_dict = NIR_WHOIS['jpnic']['fields']
tmp_dict['name'] = r'(NetName):[^\S\n]+(?P<val1>.+?)\n'
obj._parse_fields(
obj.parse_fields(
response='\nNetName: TEST\n',
fields_dict=tmp_dict,
dt_format=NIR_WHOIS['jpnic']['dt_format']
)
obj._parse_fields(
obj.parse_fields(
response='\nUpdated: 2012-02-24\n',
fields_dict=NIR_WHOIS['jpnic']['fields'],
dt_format=NIR_WHOIS['jpnic']['dt_format']
@ -81,13 +81,13 @@ class TestNIRWhois(TestCommon):
log.debug(
'Testing field parse error. This should be followed by a '
'debug log.')
obj._parse_fields(
obj.parse_fields(
response='\nUpdated: 2012-02-244\n',
fields_dict=NIR_WHOIS['jpnic']['fields'],
dt_format=NIR_WHOIS['jpnic']['dt_format']
)
def test__get_nets_jpnic(self):
def test_get_nets_jpnic(self):
net = Net('133.1.2.5')
obj = NIRWhois(net)
@ -98,9 +98,9 @@ class TestNIRWhois(TestCommon):
'a. [Network Number] asd>133.1.0.0/16</A>'
'a. [Network Number] asd>133.1.0.0/24</A>'
)
obj._get_nets_jpnic(multi_net_response)
obj.get_nets_jpnic(multi_net_response)
self.assertFalse(obj._get_nets_jpnic(
self.assertFalse(obj.get_nets_jpnic(
'a. [Network Number] asd>asd/16</A>'
))
@ -115,19 +115,19 @@ class TestNIRWhois(TestCommon):
'IPv4 Address : 115.0.0.0 - 115.23.255.255 (/12+/13)'
'IPv4 Address : 115.1.2.0 - 115.1.2.63 (/26)'
)
obj._get_nets_krnic(multi_net_response)
obj.get_nets_krnic(multi_net_response)
# ip_network ValueError
self.assertFalse(obj._get_nets_krnic(
self.assertFalse(obj.get_nets_krnic(
'IPv4 Address : asd - asd (/12+/13)'
))
# Expected IP range regex not found, but some value found
self.assertFalse(obj._get_nets_krnic(
self.assertFalse(obj.get_nets_krnic(
'IPv4 Address : asd'
))
def test__get_contact(self):
def test_get_contact(self):
net = Net('115.1.2.3')
obj = NIRWhois(net)
@ -139,7 +139,7 @@ class TestNIRWhois(TestCommon):
)
# No exception raised.
obj._get_contact(
obj.get_contact(
response=contact_response,
handle=None,
nir='krnic',

View File

@ -56,13 +56,13 @@ class TestWhois(TestCommon):
# groups are messed up.
tmp_dict = RIR_WHOIS['arin']['fields']
tmp_dict['name'] = r'(NetName):[^\S\n]+(?P<val1>.+?)\n'
obj._parse_fields(
obj.parse_fields(
response="\nNetName: TEST\n",
fields_dict=tmp_dict,
dt_format=RIR_WHOIS['arin']['dt_format']
)
obj._parse_fields(
obj.parse_fields(
response="\nUpdated: 2012-02-24\n",
fields_dict=RIR_WHOIS['arin']['fields'],
dt_format=RIR_WHOIS['arin']['dt_format']
@ -70,13 +70,13 @@ class TestWhois(TestCommon):
log.debug('Testing field parse error. This should be followed by a '
'debug log.')
obj._parse_fields(
obj.parse_fields(
response='\nUpdated: 2012-02-244\n',
fields_dict=RIR_WHOIS['arin']['fields'],
dt_format=RIR_WHOIS['arin']['dt_format']
)
def test__get_nets_arin(self):
def test_get_nets_arin(self):
net = Net('74.125.225.229')
obj = Whois(net)
@ -90,9 +90,9 @@ class TestWhois(TestCommon):
'\nNetRange: 74.125.1.0 - 74.125.1.0'
'\n'
)
obj._get_nets_arin(multi_net_response)
obj.get_nets_arin(multi_net_response)
def test__get_nets_lacnic(self):
def test_get_nets_lacnic(self):
net = Net('200.57.141.161')
obj = Whois(net)
@ -103,9 +103,9 @@ class TestWhois(TestCommon):
'\ninetnum: 200.57.256/19\r\n'
'\n'
)
obj._get_nets_lacnic(multi_net_response)
obj.get_nets_lacnic(multi_net_response)
def test__get_nets_other(self):
def test_get_nets_other(self):
net = Net('210.107.73.73')
obj = Whois(net)
@ -116,4 +116,4 @@ class TestWhois(TestCommon):
'\ninetnum: 210.107.0.0 - 210.107.127.256\n'
'\n'
)
obj._get_nets_other(multi_net_response)
obj.get_nets_other(multi_net_response)

View File

@ -740,7 +740,7 @@ class Whois:
results['raw_referral'] = response_ref
temp_rnet = self._parse_fields(
temp_rnet = self.parse_fields(
response_ref,
RWHOIS['fields'],
field_list=field_list
@ -758,15 +758,15 @@ class Whois:
if asn_data['asn_registry'] == 'arin':
nets_response = self._get_nets_arin(response)
nets_response = self.get_nets_arin(response)
elif asn_data['asn_registry'] == 'lacnic':
nets_response = self._get_nets_lacnic(response)
nets_response = self.get_nets_lacnic(response)
else:
nets_response = self._get_nets_other(response)
nets_response = self.get_nets_other(response)
nets.extend(nets_response)
@ -788,7 +788,7 @@ class Whois:
dt_format = None
temp_net = self._parse_fields(
temp_net = self.parse_fields(
response,
RIR_WHOIS[asn_data['asn_registry']]['fields'],
section_end,