-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (27 loc) · 871 Bytes
/
utils.py
File metadata and controls
39 lines (27 loc) · 871 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
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
'''
Some common, generic utilities
'''
from __future__ import absolute_import
from base64 import urlsafe_b64encode, urlsafe_b64decode
import warnings
def urlsafe_nopadding_b64encode(data):
'''URL safe Base64 encode without padding (=)'''
warnings.warn(type(data))
return urlsafe_b64encode(data.encode('utf-8')).rstrip('=')
def urlsafe_nopadding_b64decode(data):
'''URL safe Base64 decode without padding (=)'''
padding = len(data) % 4
if padding != 0:
padding = 4 - padding
padding = '=' * padding
data = data + padding
return urlsafe_b64decode(data)
def const_equal(str_a, str_b):
'''Constant time string comparison'''
if len(str_a) != len(str_b):
return False
result = True
for i in range(len(str_a)):
result &= (str_a[i] == str_b[i])
return result