fune/third_party/python/ecdsa/ecdsa/_compat.py
Mitchell Hentges 6d154c1ed3 Bug 1713377: Change vendoring to use wheels where possible r=ahal,glandium
Vendoring wheels has three benefits:
* There's far less files, so Firefox checkouts will be smaller.
* It works around `zipp` not allowing `pip install`
  from extracted source `tar.gz` files. Now, we should
  be able to use the pip resolver against vendored
  packages, which will be needed for future
  mach virtualenv work.
* `./mach vendor python` takes far less time to execute.

Since we need the raw Python to be available to add to the `sys.path`,
we extract the wheels before putting them in tree.
Due to the structure of some wheels being less nested
than of a source `tar.gz`, `common_virtualenv_packages`
needed to be adjusted accordingly.

`install_pip_package()` had to be tweaked as well since you can't
`pip install` an extracted wheel. So, we "re-bundle" the wheel
before installing from a vendored package.

Replace python packages with wheels where possible

This contains the vendoring changes caused by the
last patch.

For reviewing, there's a couple things to note:
* A bunch of files are deleted, since there's generally
  less files in a wheel than in a source archive.
* There's a new `.dist-info` directory for each
  extracted wheel, so expect roughly 5 or
  6 new files for each wheel'd package.
* There should be no source code changes other than
  moves from package names changing from having
  `-` to having `_`.

Differential Revision: https://phabricator.services.mozilla.com/D116512
2021-06-16 15:53:16 +00:00

39 lines
1.1 KiB
Python

"""
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."""
# flake8 runs on py3 where `buffer` indeed doesn't exist...
return buffer(buffer_object) # noqa: F821
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 not 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')