Coverage for presidio_analyzer / analyzer_request.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1import re 

2from typing import Dict 

3 

4from presidio_analyzer import PatternRecognizer 

5 

6 

7class AnalyzerRequest: 

8 """ 

9 Analyzer request data. 

10 

11 :param req_data: A request dictionary with the following fields: 

12 text: the text to analyze 

13 language: the language of the text 

14 entities: List of PII entities that should be looked for in the text. 

15 If entities=None then all entities are looked for. 

16 correlation_id: cross call ID for this request 

17 score_threshold: A minimum value for which to return an identified entity 

18 log_decision_process: Should the decision points within the analysis 

19 be logged 

20 return_decision_process: Should the decision points within the analysis 

21 returned as part of the response 

22 """ 

23 

24 def __init__(self, req_data: Dict): 

25 self.text = req_data.get("text") 

26 self.language = req_data.get("language") 

27 self.entities = req_data.get("entities") 

28 self.correlation_id = req_data.get("correlation_id") 

29 self.score_threshold = req_data.get("score_threshold") 

30 self.return_decision_process = req_data.get("return_decision_process") 

31 ad_hoc_recognizers = req_data.get("ad_hoc_recognizers") 

32 self.ad_hoc_recognizers = [] 

33 if ad_hoc_recognizers: 

34 self.ad_hoc_recognizers = [ 

35 PatternRecognizer.from_dict(rec) for rec in ad_hoc_recognizers 

36 ] 

37 self.context = req_data.get("context") 

38 self.allow_list = req_data.get("allow_list") 

39 self.allow_list_match = req_data.get("allow_list_match", "exact") 

40 self.regex_flags = req_data.get( 

41 "regex_flags", re.DOTALL | re.MULTILINE | re.IGNORECASE 

42 )