compat.py 576 B

12345678910111213141516171819202122232425262728
  1. import sys
  2. # pylint: skip-file
  3. if sys.version_info[0] == 2:
  4. import ipaddr as ipaddress # pylint:disable=F0401
  5. ipaddress.ip_address = ipaddress.IPAddress
  6. int_from_byte = ord
  7. FileNotFoundError = IOError
  8. def int_from_bytes(b):
  9. if b:
  10. return int(b.encode("hex"), 16)
  11. return 0
  12. byte_from_int = chr
  13. else:
  14. import ipaddress # pylint:disable=F0401
  15. int_from_byte = lambda x: x
  16. FileNotFoundError = FileNotFoundError
  17. int_from_bytes = lambda x: int.from_bytes(x, 'big')
  18. byte_from_int = lambda x: bytes([x])