
¡\\G  ã               @   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 d „  Z d d „  Z d	 d
 „  Z d d „  Z d d d „ Z d S)z'Subscribes users to the EFF newsletter.é    N)Ú	constants)Ú
interfacesc             C   s[   |  j  d k r& |  j r" t d ƒ d S|  j d k rA t ƒ  |  _ |  j rW t |  j  ƒ d S)zè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.

    Nz$you didn't provide an e-mail address)ÚemailZ	eff_emailÚ_report_failureÚ_want_subscriptionÚ	subscribe)Úconfig© r	   ú-/usr/lib/python3/dist-packages/certbot/eff.pyÚhandle_subscription   s    		
	r   c              C   s.   d }  t  j j t j ƒ } | j |  d d ƒS)z—Does the user want to be subscribed to the EFF newsletter?

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

    a:  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. ÚdefaultF)ÚzopeÚ	componentÚ
getUtilityr   ZIDisplayZyesno)ÚpromptZdisplayr	   r	   r
   r   !   s    r   c             C   sQ   t  j } d d d |  d d i } t j d | | ƒ t t j | d | ƒƒ d S)	zhSubscribe the user to the EFF mailing list.

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

    Z	data_typeÚjsonr   Zform_idZ%eff_supporters_library_subscribe_formzSending POST request to %s:
%sÚdataN)r   ZEFF_SUBSCRIBE_URIÚloggerÚdebugÚ_check_responseÚrequestsZpost)r   Zurlr   r	   r	   r
   r   2   s    	r   c             C   sˆ   t  j d |  j ƒ y. |  j ƒ  |  j ƒ  d d k r@ t d ƒ Wn@ t j j k
 rb t ƒ  Yn" t	 t
 f k
 rƒ t d ƒ Yn Xd S)zÎ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

    zReceived response:
%sZstatusFz)your e-mail address appears to be invalidz,there was a problem with the server responseN)r   r   ZcontentZraise_for_statusr   r   r   Ú
exceptionsZ	HTTPErrorÚ
ValueErrorÚKeyError)Zresponser	   r	   r
   r   @   s    	
r   c             C   sq   d g } |  d k	 r/ | j  d ƒ | j  |  ƒ | j  d ƒ t j j t j ƒ } | j d j | ƒ | j ƒ d S)zè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`

    z4We were unable to subscribe you the EFF mailing listNz	 because z:. You can try again later by visiting https://act.eff.org.Ú )	Úappendr   r   r   r   Z	IReporterZadd_messageÚjoinZLOW_PRIORITY)ÚreasonÚmsgZreporterr	   r	   r
   r   T   s    	r   )Ú__doc__Zloggingr   Zzope.componentr   Zcertbotr   r   Z	getLoggerÚ__name__r   r   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   