-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
453 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Common functions for providing cross-python version compatibility. | ||
""" | ||
import sys | ||
from six import integer_types | ||
|
||
|
||
def str_idx_as_int(string, index): | ||
"""Take index'th byte from string, return as integer""" | ||
val = string[index] | ||
if isinstance(val, integer_types): | ||
return val | ||
return ord(val) | ||
|
||
|
||
if sys.version_info < (3, 0): | ||
def normalise_bytes(buffer_object): | ||
"""Cast the input into array of bytes.""" | ||
return buffer(buffer_object) | ||
|
||
def hmac_compat(ret): | ||
return ret | ||
|
||
else: | ||
if sys.version_info < (3, 4): | ||
# on python 3.3 hmac.hmac.update() accepts only bytes, on newer | ||
# versions it does accept memoryview() also | ||
def hmac_compat(data): | ||
if isinstance(data, bytes): | ||
return bytes(data) | ||
return data | ||
else: | ||
def hmac_compat(data): | ||
return data | ||
|
||
def normalise_bytes(buffer_object): | ||
"""Cast the input into array of bytes.""" | ||
return memoryview(buffer_object).cast('B') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.