updates
This commit is contained in:
@@ -9,10 +9,11 @@ import sys
|
||||
import types
|
||||
import typing
|
||||
import warnings
|
||||
from collections.abc import Callable, Sequence
|
||||
|
||||
|
||||
# We use a UserWarning subclass, instead of DeprecationWarning, because CPython
|
||||
# decided deprecation warnings should be invisble by default.
|
||||
# decided deprecation warnings should be invisible by default.
|
||||
class CryptographyDeprecationWarning(UserWarning):
|
||||
pass
|
||||
|
||||
@@ -21,9 +22,20 @@ class CryptographyDeprecationWarning(UserWarning):
|
||||
# ubiquity of their use. They should not be removed until we agree on when that
|
||||
# cycle ends.
|
||||
DeprecatedIn36 = CryptographyDeprecationWarning
|
||||
DeprecatedIn37 = CryptographyDeprecationWarning
|
||||
DeprecatedIn40 = CryptographyDeprecationWarning
|
||||
DeprecatedIn41 = CryptographyDeprecationWarning
|
||||
DeprecatedIn42 = CryptographyDeprecationWarning
|
||||
DeprecatedIn43 = CryptographyDeprecationWarning
|
||||
|
||||
|
||||
# If you're wondering why we don't use `Buffer`, it's because `Buffer` would
|
||||
# be more accurately named: Bufferable. It means something which has an
|
||||
# `__buffer__`. Which means you can't actually treat the result as a buffer
|
||||
# (and do things like take a `len()`).
|
||||
if sys.version_info >= (3, 9):
|
||||
Buffer = typing.Union[bytes, bytearray, memoryview]
|
||||
else:
|
||||
Buffer = typing.ByteString
|
||||
|
||||
|
||||
def _check_bytes(name: str, value: bytes) -> None:
|
||||
@@ -31,26 +43,21 @@ def _check_bytes(name: str, value: bytes) -> None:
|
||||
raise TypeError(f"{name} must be bytes")
|
||||
|
||||
|
||||
def _check_byteslike(name: str, value: bytes) -> None:
|
||||
def _check_byteslike(name: str, value: Buffer) -> None:
|
||||
try:
|
||||
memoryview(value)
|
||||
except TypeError:
|
||||
raise TypeError(f"{name} must be bytes-like")
|
||||
|
||||
|
||||
def int_to_bytes(integer: int, length: typing.Optional[int] = None) -> bytes:
|
||||
def int_to_bytes(integer: int, length: int | None = None) -> bytes:
|
||||
if length == 0:
|
||||
raise ValueError("length argument can't be 0")
|
||||
return integer.to_bytes(
|
||||
length or (integer.bit_length() + 7) // 8 or 1, "big"
|
||||
)
|
||||
|
||||
|
||||
def _extract_buffer_length(obj: typing.Any) -> typing.Tuple[typing.Any, int]:
|
||||
from cryptography.hazmat.bindings._rust import _openssl
|
||||
|
||||
buf = _openssl.ffi.from_buffer(obj)
|
||||
return buf, int(_openssl.ffi.cast("uintptr_t", buf))
|
||||
|
||||
|
||||
class InterfaceNotImplemented(Exception):
|
||||
pass
|
||||
|
||||
@@ -84,16 +91,16 @@ class _ModuleWithDeprecations(types.ModuleType):
|
||||
|
||||
delattr(self._module, attr)
|
||||
|
||||
def __dir__(self) -> typing.Sequence[str]:
|
||||
return ["_module"] + dir(self._module)
|
||||
def __dir__(self) -> Sequence[str]:
|
||||
return ["_module", *dir(self._module)]
|
||||
|
||||
|
||||
def deprecated(
|
||||
value: object,
|
||||
module_name: str,
|
||||
message: str,
|
||||
warning_class: typing.Type[Warning],
|
||||
name: typing.Optional[str] = None,
|
||||
warning_class: type[Warning],
|
||||
name: str | None = None,
|
||||
) -> _DeprecatedValue:
|
||||
module = sys.modules[module_name]
|
||||
if not isinstance(module, _ModuleWithDeprecations):
|
||||
@@ -105,7 +112,7 @@ def deprecated(
|
||||
return dv
|
||||
|
||||
|
||||
def cached_property(func: typing.Callable) -> property:
|
||||
def cached_property(func: Callable) -> property:
|
||||
cached_name = f"_cached_{func}"
|
||||
sentinel = object()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user