mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
commit
48d298c568
2 changed files with 15 additions and 3 deletions
|
@ -7,8 +7,8 @@ Salt compatibility code
|
|||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
import sys
|
||||
import types
|
||||
import logging
|
||||
import binascii
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.exceptions import SaltException
|
||||
|
@ -173,7 +173,7 @@ class IPv6AddressScoped(ipaddress.IPv6Address):
|
|||
self._ip = address
|
||||
elif self._is_packed_binary(address):
|
||||
self._check_packed_address(address, 16)
|
||||
self._ip = ipaddress._int_from_bytes(address, 'big')
|
||||
self._ip = int(binascii.hexlify(address), 16)
|
||||
else:
|
||||
address = str(address)
|
||||
if '/' in address:
|
||||
|
@ -190,7 +190,7 @@ class IPv6AddressScoped(ipaddress.IPv6Address):
|
|||
packed = False
|
||||
if isinstance(data, bytes) and len(data) == 16 and b':' not in data:
|
||||
try:
|
||||
packed = bool(int(str(bytearray(data)).encode('hex'), 16))
|
||||
packed = bool(int(binascii.hexlify(data), 16))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
|
|
@ -69,3 +69,15 @@ class CompatTestCase(TestCase):
|
|||
else:
|
||||
expected = 'StringIO.StringIO instance'
|
||||
self.assertTrue(expected in repr(ret))
|
||||
|
||||
def test_ipv6_class__is_packed_binary(self):
|
||||
ipv6 = compat.IPv6AddressScoped('2001:db8::')
|
||||
self.assertEqual(str(ipv6), '2001:db8::')
|
||||
|
||||
def test_ipv6_class__is_packed_binary_integer(self):
|
||||
ipv6 = compat.IPv6AddressScoped(42540766411282592856903984951653826560)
|
||||
self.assertEqual(str(ipv6), '2001:db8::')
|
||||
|
||||
def test_ipv6_class__is_packed_binary__issue_51831(self):
|
||||
ipv6 = compat.IPv6AddressScoped(b'sixteen.digit.bn')
|
||||
self.assertEqual(str(ipv6), '7369:7874:6565:6e2e:6469:6769:742e:626e')
|
||||
|
|
Loading…
Add table
Reference in a new issue