forked from jpadilla/pyjwt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat.py
More file actions
31 lines (22 loc) · 694 Bytes
/
compat.py
File metadata and controls
31 lines (22 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
The `compat` module provides support for backwards compatibility with older
versions of python, and compatibility wrappers around optional packages.
"""
# flake8: noqa
import hmac
text_type = str
binary_type = bytes
string_types = (str, bytes)
try:
# Importing ABCs from collections will be removed in PY3.8
from collections.abc import Iterable, Mapping
except ImportError:
from collections import Iterable, Mapping
constant_time_compare = hmac.compare_digest
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)