_compat.py (salt-3002.1) | : | _compat.py (salt-3002.2) | ||
---|---|---|---|---|
# -*- coding: utf-8 -*- | ||||
""" | """ | |||
Salt compatibility code | Salt compatibility code | |||
""" | """ | |||
# pylint: disable=import-error,unused-import,invalid-name,W0231,W0233 | # pylint: disable=import-error,unused-import,invalid-name,W0231,W0233 | |||
# Import python libs | ||||
from __future__ import absolute_import, print_function, unicode_literals | ||||
import binascii | import binascii | |||
import logging | import logging | |||
import sys | import sys | |||
# Import 3rd-party libs | ||||
from salt.exceptions import SaltException | from salt.exceptions import SaltException | |||
from salt.ext.six import binary_type, integer_types, string_types, text_type | from salt.ext.six import binary_type, integer_types, string_types, text_type | |||
from salt.ext.six.moves import StringIO, cStringIO | from salt.ext.six.moves import StringIO, cStringIO | |||
log = logging.getLogger(__name__) | log = logging.getLogger(__name__) | |||
try: | try: | |||
# Python >2.5 | # Python >2.5 | |||
import xml.etree.cElementTree as ElementTree | import xml.etree.cElementTree as ElementTree | |||
except Exception: # pylint: disable=broad-except | except Exception: # pylint: disable=broad-except | |||
skipping to change at line 155 | skipping to change at line 150 | |||
self._is_packed_binary = lambda p: isinstance(p, bytes) | self._is_packed_binary = lambda p: isinstance(p, bytes) | |||
# pylint: enable-all | # pylint: enable-all | |||
if isinstance(address, string_types) and "%" in address: | if isinstance(address, string_types) and "%" in address: | |||
buff = address.split("%") | buff = address.split("%") | |||
if len(buff) != 2: | if len(buff) != 2: | |||
raise SaltException('Invalid IPv6 address: "{}"'.format(address) ) | raise SaltException('Invalid IPv6 address: "{}"'.format(address) ) | |||
address, self.__scope = buff | address, self.__scope = buff | |||
else: | else: | |||
self.__scope = None | self.__scope = None | |||
# For compatibility with python3.9 ipaddress | ||||
self._scope_id = self.__scope | ||||
if sys.version_info.major == 2: | if sys.version_info.major == 2: | |||
ipaddress._BaseAddress.__init__(self, address) | ipaddress._BaseAddress.__init__(self, address) | |||
ipaddress._BaseV6.__init__(self, address) | ipaddress._BaseV6.__init__(self, address) | |||
else: | else: | |||
# Python 3.4 fix. Versions higher are simply not affected | # Python 3.4 fix. Versions higher are simply not affected | |||
# https://github.com/python/cpython/blob/3.4/Lib/ipaddress.py#L543-L 544 | # https://github.com/python/cpython/blob/3.4/Lib/ipaddress.py#L543-L 544 | |||
self._version = 6 | self._version = 6 | |||
self._max_prefixlen = ipaddress.IPV6LENGTH | self._max_prefixlen = ipaddress.IPV6LENGTH | |||
# Efficient constructor from integer. | # Efficient constructor from integer. | |||
End of changes. 4 change blocks. | ||||
5 lines changed or deleted | 3 lines changed or added |