Skip to content

Commit ba60d82

Browse files
author
James William Pye
committed
Remove ipaddr code.
A little too quick to implement, but only a little wasted time.
1 parent 5175b26 commit ba60d82

2 files changed

Lines changed: 25 additions & 56 deletions

File tree

postgresql/protocol/typio.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -421,38 +421,8 @@ def numeric_unpack(x):
421421
pg_types.CIRCLEOID : (circle_pack, circle_unpack),
422422
}
423423

424-
# Conditionally use ipaddr.
425-
# Condition goes away when 3.0 is deprecated.
426-
try:
427-
import ipaddr
428-
def net_pack(ip):
429-
family = None
430-
converted = False
431-
while family is None:
432-
if isinstance(ip, ipaddr.IPv4):
433-
family = 2
434-
elif isinstance(ip, ipaddr.IPv6):
435-
family = 3
436-
else:
437-
if converted is True:
438-
raise ValueError("unknown IP type: " + repr(ip))
439-
ip = ipaddr.IP(ip)
440-
converted = True
441-
return ts.net_pack((family, ip.prefixlen, ip.packed))
442-
443-
def net_unpack(data):
444-
family, mask, data = ts.net_unpack(data)
445-
if family in (2, 3):
446-
v = ipaddr.IP(data)
447-
else:
448-
raise ValueError("unknown net family: " + repr(family))
449-
v.prefixlen = mask
450-
return v
451-
oid_to_io[pg_types.CIDROID] = (net_pack, net_unpack)
452-
oid_to_io[pg_types.INETOID] = (net_pack, net_unpack)
453-
except ImportError:
454-
oid_to_io[pg_types.CIDROID] = (None, None)
455-
oid_to_io[pg_types.INETOID] = (None, None)
424+
oid_to_io[pg_types.CIDROID] = (None, None)
425+
oid_to_io[pg_types.INETOID] = (None, None)
456426

457427
def process_tuple(procs, tup, exception_handler):
458428
"""

postgresql/test/test_driver.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -270,38 +270,37 @@
270270
),
271271
]
272272

273-
try:
274-
import ipaddr
273+
if False:
274+
# When an implementation does make it,
275+
# re-enable these tests.
275276
type_samples.append((
276277
'inet', [
277-
ipaddr.IPv4('255.255.255.255'),
278-
ipaddr.IPv4('127.0.0.1'),
279-
ipaddr.IPv4('10.0.0.1'),
280-
ipaddr.IPv4('0.0.0.0'),
281-
ipaddr.IPv6('::1'),
282-
ipaddr.IPv6('ffff' + ':ffff'*7),
283-
ipaddr.IPv6('fe80::1'),
284-
ipaddr.IPv6('fe80::1'),
285-
ipaddr.IPv6('0::0'),
278+
IPAddress4('255.255.255.255'),
279+
IPAddress4('127.0.0.1'),
280+
IPAddress4('10.0.0.1'),
281+
IPAddress4('0.0.0.0'),
282+
IPAddress6('::1'),
283+
IPAddress6('ffff' + ':ffff'*7),
284+
IPAddress6('fe80::1'),
285+
IPAddress6('fe80::1'),
286+
IPAddress6('0::0'),
286287
],
287288
))
288289
type_samples.append((
289290
'cidr', [
290-
ipaddr.IPv4('255.255.255.255/32'),
291-
ipaddr.IPv4('127.0.0.0/8'),
292-
ipaddr.IPv4('127.1.0.0/16'),
293-
ipaddr.IPv4('10.0.0.0/32'),
294-
ipaddr.IPv4('0.0.0.0/0'),
295-
ipaddr.IPv6('ffff' + ':ffff'*7 + '/128'),
296-
ipaddr.IPv6('::1/128'),
297-
ipaddr.IPv6('fe80::1/128'),
298-
ipaddr.IPv6('fe80::0/64'),
299-
ipaddr.IPv6('fe80::0/16'),
300-
ipaddr.IPv6('0::0/0'),
291+
IPNetwork4('255.255.255.255/32'),
292+
IPNetwork4('127.0.0.0/8'),
293+
IPNetwork4('127.1.0.0/16'),
294+
IPNetwork4('10.0.0.0/32'),
295+
IPNetwork4('0.0.0.0/0'),
296+
IPNetwork6('ffff' + ':ffff'*7 + '/128'),
297+
IPNetwork6('::1/128'),
298+
IPNetwork6('fe80::1/128'),
299+
IPNetwork6('fe80::0/64'),
300+
IPNetwork6('fe80::0/16'),
301+
IPNetwork6('0::0/0'),
301302
],
302303
))
303-
except ImportError:
304-
pass
305304

306305
class test_driver(pg_unittest.TestCaseWithCluster):
307306
"""

0 commit comments

Comments
 (0)