def int_to_str(int_val, dialect=None): """ :param int_val: An unsigned integer. :param dialect: (optional) a Python class defining formatting options. :return: The IPv6 presentation (string) format address equivalent to the unsigned integer provided. """ if dialect is None: dialect = ipv6_compact addr = None try: packed_int = int_to_packed(int_val) if dialect.compact: # Default return value. addr = _inet_ntop(AF_INET6, packed_int) else: # Custom return value. words = list(_struct.unpack('>8H', packed_int)) tokens = [dialect.word_fmt % word for word in words] addr = word_sep.join(tokens) except Exception: raise ValueError('%r is not a valid 128-bit unsigned integer!' % (int_val, )) return addr
def int_to_str(int_val, dialect=None): """ :param int_val: An unsigned integer. :param dialect: (optional) a Python class defining formatting options. :return: The IPv6 presentation (string) format address equivalent to the unsigned integer provided. """ if dialect is None: dialect = ipv6_compact addr = None try: packed_int = int_to_packed(int_val) if dialect.compact: # Default return value. addr = _inet_ntop(AF_INET6, packed_int) else: # Custom return value. words = list(_struct.unpack('>8H', packed_int)) tokens = [dialect.word_fmt % word for word in words] addr = word_sep.join(tokens) except Exception: raise ValueError('%r is not a valid 128-bit unsigned integer!' \ % int_val) return addr