o
    wÔ+f\
  ã                   @   s    d dl mZ G dd„ deƒZdS )é   )ÚApiKeyIncludedExceptionc                   @   s.   e Zd ZdZdZd
dd„Zdd„ Zdd	„ ZdS )ÚValidateApiKeyz;Validates content to ensure SendGrid API key is not presentNTc                 C   sV   ddl }tƒ | _|dur|D ]}| j | |¡¡ q|r)d}| j | |¡¡ dS dS )zôCreate an API key validator

            :param regex_strings: list of regex strings
            :type regex_strings: list(str)
            :param use_default: Whether or not to include default regex
            :type use_default: bool
        é    NzSG\.[0-9a-zA-Z]+\.[0-9a-zA-Z]+)ÚreÚsetÚregexesÚaddÚcompile)ÚselfÚregex_stringsÚuse_defaultr   Úregex_stringÚdefault_regex_string© r   úS/var/www/html/venv/lib/python3.10/site-packages/sendgrid/helpers/mail/validators.pyÚ__init__	   s   	þzValidateApiKey.__init__c                 C   s~   t |tƒr|  |¡ dS t |tƒr;| dtƒ ¡}|D ]"}|dur:| d¡dks/t | d¡tƒr:| dd¡}|  |¡ qdS dS )aÂ  With the JSON dict that will be sent to SendGrid's API,
            check the content for SendGrid API keys - throw exception if found.

           :param request_body: The JSON dict that will be sent to SendGrid's
                                API.
           :type request_body: JSON serializable structure
           :raise ApiKeyIncludedException: If any content in request_body
                                           matches regex
        ÚcontentNÚtypez	text/htmlÚvalueÚ )Ú
isinstanceÚstrÚvalidate_message_textÚdictÚgetÚlist)r
   Úrequest_bodyÚcontentsr   Úmessage_textr   r   r   Úvalidate_message_dict   s   

ÿ
€÷z$ValidateApiKey.validate_message_dictc                 C   s2   t |tƒr| jD ]}| |¡durtƒ ‚qdS dS )af  With a message string, check to see if it contains a SendGrid API Key
            If a key is found, throw an exception

           :param message_string: message that will be sent
           :type message_string: string
           :raises ApiKeyIncludedException: If message_string matches a regex
                                            string
        N)r   r   r   Úmatchr   )r
   Úmessage_stringÚregexr   r   r   r   9   s   
	
ÿþz$ValidateApiKey.validate_message_text)NT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r      s    
r   N)Ú
exceptionsr   Úobjectr   r   r   r   r   Ú<module>   s    