67
67
from pymongo .asynchronous .pool import AsyncBaseConnection
68
68
from pymongo .common import CONNECT_TIMEOUT
69
69
from pymongo .daemon import _spawn_daemon
70
- from pymongo .encryption_options import AutoEncryptionOpts , RangeOpts
70
+ from pymongo .encryption_options import AutoEncryptionOpts , RangeOpts , TextOpts
71
71
from pymongo .errors import (
72
72
ConfigurationError ,
73
73
EncryptedCollectionError ,
@@ -516,6 +516,11 @@ class Algorithm(str, enum.Enum):
516
516
517
517
.. versionadded:: 4.4
518
518
"""
519
+ TEXTPREVIEW = "TextPreview"
520
+ """**BETA** - TextPreview.
521
+
522
+ .. versionadded:: 4.15
523
+ """
519
524
520
525
521
526
class QueryType (str , enum .Enum ):
@@ -541,6 +546,24 @@ class QueryType(str, enum.Enum):
541
546
.. versionadded:: 4.4
542
547
"""
543
548
549
+ PREFIXPREVIEW = "prefixPreview"
550
+ """**BETA** - Used to encrypt a value for a prefixPreview query.
551
+
552
+ .. versionadded:: 4.15
553
+ """
554
+
555
+ SUFFIXPREVIEW = "suffixPreview"
556
+ """**BETA** - Used to encrypt a value for a suffixPreview query.
557
+
558
+ .. versionadded:: 4.15
559
+ """
560
+
561
+ SUBSTRINGPREVIEW = "substringPreview"
562
+ """**BETA** - Used to encrypt a value for a substringPreview query.
563
+
564
+ .. versionadded:: 4.15
565
+ """
566
+
544
567
545
568
def _create_mongocrypt_options (** kwargs : Any ) -> MongoCryptOptions :
546
569
# For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms.
@@ -876,6 +899,7 @@ async def _encrypt_helper(
876
899
contention_factor : Optional [int ] = None ,
877
900
range_opts : Optional [RangeOpts ] = None ,
878
901
is_expression : bool = False ,
902
+ text_opts : Optional [TextOpts ] = None ,
879
903
) -> Any :
880
904
self ._check_closed ()
881
905
if isinstance (key_id , uuid .UUID ):
@@ -895,6 +919,12 @@ async def _encrypt_helper(
895
919
range_opts .document ,
896
920
codec_options = self ._codec_options ,
897
921
)
922
+ text_opts_bytes = None
923
+ if text_opts :
924
+ text_opts_bytes = encode (
925
+ text_opts .document ,
926
+ codec_options = self ._codec_options ,
927
+ )
898
928
with _wrap_encryption_errors ():
899
929
encrypted_doc = await self ._encryption .encrypt (
900
930
value = doc ,
@@ -905,6 +935,7 @@ async def _encrypt_helper(
905
935
contention_factor = contention_factor ,
906
936
range_opts = range_opts_bytes ,
907
937
is_expression = is_expression ,
938
+ text_opts = text_opts_bytes ,
908
939
)
909
940
return decode (encrypted_doc )["v" ]
910
941
@@ -917,6 +948,7 @@ async def encrypt(
917
948
query_type : Optional [str ] = None ,
918
949
contention_factor : Optional [int ] = None ,
919
950
range_opts : Optional [RangeOpts ] = None ,
951
+ text_opts : Optional [TextOpts ] = None ,
920
952
) -> Binary :
921
953
"""Encrypt a BSON value with a given key and algorithm.
922
954
@@ -937,9 +969,14 @@ async def encrypt(
937
969
used.
938
970
:param range_opts: Index options for `range` queries. See
939
971
:class:`RangeOpts` for some valid options.
972
+ :param text_opts: Index options for `textPreview` queries. See
973
+ :class:`TextOpts` for some valid options.
940
974
941
975
:return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6.
942
976
977
+ .. versionchanged:: 4.9
978
+ Added the `text_opts` parameter.
979
+
943
980
.. versionchanged:: 4.9
944
981
Added the `range_opts` parameter.
945
982
@@ -960,6 +997,7 @@ async def encrypt(
960
997
contention_factor = contention_factor ,
961
998
range_opts = range_opts ,
962
999
is_expression = False ,
1000
+ text_opts = text_opts ,
963
1001
),
964
1002
)
965
1003
0 commit comments