Files
2025-04-30 08:48:49 -05:00

67 lines
1.7 KiB
Python

# uncompyle6 version 3.9.2
# Python bytecode version base 3.7.0 (3394)
# Decompiled from: Python 3.8.19 (default, Mar 20 2024, 15:27:52)
# [Clang 14.0.6 ]
# Embedded file name: /var/user/app/device_supervisorbak/device_supervisor/lib/jwt/compat.py
# Compiled at: 2024-04-18 03:12:55
# Size of source mod 2**32: 1692 bytes
"""
The `compat` module provides support for backwards compatibility with older
versions of python, and compatibility wrappers around optional packages.
"""
import hmac, struct, sys
PY3 = sys.version_info[0] == 3
if PY3:
text_type = str
binary_type = bytes
else:
text_type = unicode
binary_type = str
string_types = (text_type, binary_type)
try:
from collections.abc import Iterable, Mapping
except ImportError:
from collections import Iterable, Mapping
try:
constant_time_compare = hmac.compare_digest
except AttributeError:
def constant_time_compare(val1, val2):
"""
Returns True if the two strings are equal, False otherwise.
The time taken is independent of the number of characters that match.
"""
if len(val1) != len(val2):
return False
result = 0
for x, y in zip(val1, val2):
result |= ord(x) ^ ord(y)
return result == 0
if getattr(int, "to_bytes", None):
def bytes_from_int(val):
remaining = val
byte_length = 0
while remaining != 0:
remaining = remaining >> 8
byte_length += 1
return val.to_bytes(byte_length, "big", signed=False)
else:
def bytes_from_int(val):
buf = []
while val:
val, remainder = divmod(val, 256)
buf.append(remainder)
buf.reverse()
return (struct.pack)("%sB" % len(buf), *buf)