ó
Á£ô_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 d d l	 m
 Z d d l m Z d d l m Z d d l m Z d d	 l m Z e j e ƒ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d S(   s'   Subscribes users to the EFF newsletter.iÿÿÿÿN(   t   Optional(   t
   interfaces(   t   util(   t	   constants(   t   Account(   t   AccountFileStorage(   t   IConfigc         C   s¸   |  j  t k r d S|  j  t k r\ |  j d k r> t d ƒ qŒ | j j d |  j ƒ | _ n0 |  j rŒ t ƒ  rŒ | j j d |  j ƒ | _ n  | j j	 r´ t
 |  ƒ } | j | ƒ n  d S(   s©  High level function to store potential EFF newsletter subscriptions.

    The user may be asked if they want to sign up for the newsletter if
    they have not given their explicit approval or refusal using --eff-mail
    or --no-eff-mail flag.

    Decision about EFF subscription will be stored in the account metadata.

    :param IConfig config: Client configuration.
    :param Account acc: Current client account.

    Ns$   you didn't provide an e-mail addresst   register_to_eff(   t	   eff_emailt   Falset   Truet   emailt   Nonet   _report_failuret   metat   updatet   _want_subscriptionR   R   t   update_meta(   t   configt   acct   storage(    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyt   prepare_subscription   s    c         C   sa   |  j  r d S| j j r] t | j j ƒ | j j d d ƒ | _ t |  ƒ } | j | ƒ n  d S(   sê   High level function to take care of EFF newsletter subscriptions.

    Once subscription is handled, it will not be handled again.

    :param IConfig config: Client configuration.
    :param Account acc: Current client account.

    NR   (   t   dry_runR   R   t	   subscribeR   R   R   R   (   R   R   R   (    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyt   handle_subscription0   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

    so  Would you be willing, once your first certificate is successfully issued, 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   yesnoR	   (   t   promptt   display(    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyR   D   s    	c         C   sd   t  j } i d d 6|  d 6d d 6} t j d |  ƒ 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.   Subscribe to the EFF mailing list (email: %s).s   Sending POST request to %s:
%st   dataN(   R   t   EFF_SUBSCRIBE_URIt   loggert   infot   debugt   _check_responset   requestst   post(   R   t   urlR%   (    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyR   V   s    	

c         C   sƒ   t  j d |  j ƒ y+ |  j ƒ  |  j ƒ  d s= t d ƒ n  Wn> t j j k
 r^ 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+   t
   exceptionst	   HTTPErrort
   ValueErrort   KeyError(   t   response(    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyR*   f   s    


c         C   sY   d g } |  d k	 r2 | j d ƒ | j |  ƒ n  | j d ƒ t j d 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   appendt   display_utilt   notifyt   join(   t   reasont   msg(    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyR   {   s    		(   t   __doc__t   loggingR+   t   zope.componentR   t   acme.magic_typingR    t   certbotR   t   certbot.displayR   R8   t   certbot._internalR   t   certbot._internal.accountR   R   t   certbot.interfacesR   t	   getLoggert   __name__R'   R   R   R   R   R*   R   R   (    (    (    s9   /usr/lib/python2.7/site-packages/certbot/_internal/eff.pyt   <module>   s"   					