PYTHON-3511 Cleanup some more Python 2 references (#1309)

This commit is contained in:
Shane Harvey 2023-07-14 17:02:24 -04:00 committed by GitHub
parent c6a6ea6066
commit 469e2e95f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 14 deletions

View File

@ -663,9 +663,8 @@ def _make_c_string(string: Union[str, bytes]) -> bytes:
def _make_name(string: str) -> bytes:
"""Make a 'C' string suitable for a BSON key."""
# Keys can only be text in python 3.
if "\x00" in string:
raise InvalidDocument("BSON keys / regex patterns must not contain a NUL character")
raise InvalidDocument("BSON keys must not contain a NUL character")
return _utf_8_encode(string)[0] + b"\x00"

View File

@ -3211,7 +3211,6 @@ PyInit__cbson(void)
(void *) buffer_write_int32_at_position;
_cbson_API[_cbson_downcast_and_check_INDEX] = (void *) _downcast_and_check;
/* PyCapsule is new in python 3.1 */
c_api_object = PyCapsule_New((void *) _cbson_API, "_cbson._C_API", NULL);
if (c_api_object == NULL)
INITERROR;

View File

@ -197,12 +197,11 @@ class Binary(bytes):
what should be considered a string when we encode to BSON.
Raises TypeError if `data` is not an instance of :class:`bytes`
(:class:`str` in python 2) or `subtype` is not an instance of
:class:`int`. Raises ValueError if `subtype` is not in [0, 256).
or `subtype` is not an instance of :class:`int`.
Raises ValueError if `subtype` is not in [0, 256).
.. note::
In python 3 instances of Binary with subtype 0 will be decoded
directly to :class:`bytes`.
Instances of Binary with subtype 0 will be decoded directly to :class:`bytes`.
:Parameters:
- `data`: the binary data to represent. Can be any bytes-like type

View File

@ -189,7 +189,7 @@ def _build_credentials_tuple(
def _xor(fir: bytes, sec: bytes) -> bytes:
"""XOR two byte strings together (python 3.x)."""
"""XOR two byte strings together."""
return b"".join([bytes([x ^ y]) for x, y in zip(fir, sec)])

View File

@ -518,12 +518,11 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
- `tlsCertificateKeyFile`: A file containing the client certificate
and private key. Implies ``tls=True``. Defaults to ``None``.
- `tlsCRLFile`: A file containing a PEM or DER formatted
certificate revocation list. Only supported by python 2.7.9+
(pypy 2.5.1+). Implies ``tls=True``. Defaults to ``None``.
certificate revocation list. Implies ``tls=True``. Defaults to
``None``.
- `tlsCertificateKeyFilePassword`: The password or passphrase for
decrypting the private key in ``tlsCertificateKeyFile``. Only
necessary if the private key is encrypted. Only supported by
python 2.7.9+ (pypy 2.5.1+) and 3.3+. Defaults to ``None``.
necessary if the private key is encrypted. Defaults to ``None``.
- `tlsDisableOCSPEndpointCheck`: (boolean) If ``True``, disables
certificate revocation status checking via the OCSP responder
specified on the server certificate.

View File

@ -529,8 +529,8 @@ class TestBSON(unittest.TestCase):
def test_bytes_as_keys(self):
doc = {b"foo": "bar"}
# Since `bytes` are stored as Binary you can't use them
# as keys in python 3.x. Using binary data as a key makes
# no sense in BSON anyway and little sense in python.
# as keys. Using binary data as a key makes no sense in BSON
# anyway and little sense in python.
self.assertRaises(InvalidDocument, encode, doc)
def test_datetime_encode_decode(self):