ó
º9—^c           @   s*   d  d l  m Z d e f d „  ƒ  YZ d S(   i   (   t   ApiKeyIncludedExceptiont   ValidateApiKeyc           B   s5   e  Z d  Z d Z d e d „ Z d „  Z d „  Z RS(   s;   Validates content to ensure SendGrid API key is not presentc         C   s}   d d l  } t ƒ  |  _ | d k	 rQ x* | D] } |  j j | j | ƒ ƒ q+ Wn  | ry d } |  j j | j | ƒ ƒ n  d S(   sô   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
        iÿÿÿÿNs   SG\.[0-9a-zA-Z]+\.[0-9a-zA-Z]+(   t   ret   sett   regexest   Nonet   addt   compile(   t   selft   regex_stringst   use_defaultR   t   regex_stringt   default_regex_string(    (    sB   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/validators.pyt   __init__	   s    	 c         C   s¹   t  | t ƒ r |  j | ƒ n– t  | t ƒ rµ | j d t ƒ  ƒ } xo | D]d } | d k	 rJ | j d ƒ d k s‰ t  | j d ƒ t ƒ r® | j d d ƒ } |  j | ƒ q® qJ qJ Wn  d S(   sÂ  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
        t   contentt   types	   text/htmlt   valuet    N(   t
   isinstancet   strt   validate_message_textt   dictt   gett   listR   (   R   t   request_bodyt   contentsR   t   message_text(    (    sB   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/validators.pyt   validate_message_dict   s    c         C   sK   t  | t ƒ rG x5 |  j D]' } | j | ƒ d k	 r t ƒ  ‚ q q Wn  d S(   sf  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   t   matchR   R    (   R   t   message_stringt   regex(    (    sB   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/validators.pyR   9   s    	N(	   t   __name__t
   __module__t   __doc__R   R   t   TrueR   R   R   (    (    (    sB   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/validators.pyR      s
   	N(   t
   exceptionsR    t   objectR   (    (    (    sB   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/validators.pyt   <module>   s   