ó
Y[c           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z e j e	 ƒ Z
 d „  Z d „  Z d „  Z d „  Z d d	 „ Z d S(
   s'   Subscribes users to the EFF newsletter.iÿÿÿÿN(   t	   constants(   t
   interfacesc         C   sd   |  j  d k r) |  j r% t d ƒ n  d S|  j d k rG t ƒ  |  _ n  |  j r` t |  j  ƒ n  d S(   sè   High level function to take care of EFF newsletter subscriptions.

    The user may be asked if they want to sign up for the newsletter if
    they have not already specified.

    :param .IConfig config: Client configuration.

    s$   you didn't provide an e-mail addressN(   t   emailt   Nonet	   eff_emailt   _report_failuret   _want_subscriptiont	   subscribe(   t   config(    (    s/   /usr/lib/python2.7/dist-packages/certbot/eff.pyt   handle_subscription   s    			c          C   s.   d }  t  j j t j ƒ } | j |  d t ƒS(   s—   Does the user want to be subscribed to the EFF newsletter?

    :returns: True if we should subscribe the user, otherwise, False
    :rtype: bool

    s:  Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. t   default(   t   zopet	   componentt
   getUtilityR   t   IDisplayt   yesnot   False(   t   promptt   display(    (    s/   /usr/lib/python2.7/dist-packages/certbot/eff.pyR   !   s    c         C   sT   t  j } i d d 6|  d 6d d 6} t j d | | ƒ t t j | d | ƒƒ d S(	   sh   Subscribe the user to the EFF mailing list.

    :param str email: the e-mail address to subscribe

    t   jsont	   data_typeR   t%   eff_supporters_library_subscribe_formt   form_ids   Sending POST request to %s:
%st   dataN(   R    t   EFF_SUBSCRIBE_URIt   loggert   debugt   _check_responset   requestst   post(   R   t   urlR   (    (    s/   /usr/lib/python2.7/dist-packages/certbot/eff.pyR   2   s    	

c         C   s‰   t  j d |  j ƒ y1 |  j ƒ  |  j ƒ  d t k rC t d ƒ n  Wn> t j j	 k
 rd t ƒ  n! t
 t f k
 r„ t d ƒ n Xd S(   sÎ   Check for errors in the server's response.

    If an error occurred, it will be reported to the user.

    :param requests.Response response: the server's response to the
        subscription request

    s   Received response:
%st   statuss)   your e-mail address appears to be invalids,   there was a problem with the server responseN(   R   R   t   contentt   raise_for_statusR   R   R   R   t
   exceptionst	   HTTPErrort
   ValueErrort   KeyError(   t   response(    (    s/   /usr/lib/python2.7/dist-packages/certbot/eff.pyR   @   s    	

c         C   st   d g } |  d k	 r2 | j d ƒ | j |  ƒ n  | j d ƒ t j j t j ƒ } | j d j | ƒ | j	 ƒ d S(   sè   Notify the user of failing to sign them up for the newsletter.

    :param reason: a phrase describing what the problem was
        beginning with a lowercase letter and no closing punctuation
    :type reason: `str` or `None`

    s4   We were unable to subscribe you the EFF mailing lists	    because s:   . You can try again later by visiting https://act.eff.org.t    N(
   R   t   appendR   R   R   R   t	   IReportert   add_messaget   joint   LOW_PRIORITY(   t   reasont   msgt   reporter(    (    s/   /usr/lib/python2.7/dist-packages/certbot/eff.pyR   T   s    	(   t   __doc__t   loggingR   t   zope.componentR   t   certbotR    R   t	   getLoggert   __name__R   R	   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/certbot/eff.pyt   <module>   s   				