U
    ÓZjB  ã                   @   sl   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 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   sB   | j dkr| jrtdƒ dS | jdkr.tƒ | _| jr>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	   úN/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/certbot/eff.pyÚhandle_subscription   s    	

r   c                  C   s    d} t 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. F)Údefault)ÚzopeÚ	componentÚ
getUtilityr   ZIDisplayZyesno)ÚpromptÚdisplayr	   r	   r
   r   !   s    ÿr   c                 C   s6   t j}d| ddœ}t d||¡ ttj||d�ƒ dS )zhSubscribe the user to the EFF mailing list.

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

    ÚjsonZ%eff_supporters_library_subscribe_form)Z	data_typer   Zform_idzSending POST request to %s:
%s)ÚdataN)r   ZEFF_SUBSCRIBE_URIÚloggerÚdebugÚ_check_responseÚrequestsÚpost)r   Úurlr   r	   r	   r
   r   2   s    þr   c              	   C   sp   t  d| j¡ z |  ¡  |  ¡ d s,tdƒ W n< tjjk
rL   tƒ  Y n  t	t
fk
rj   tdƒ Y nX d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:
%sÚstatusz)your e-mail address appears to be invalidz,there was a problem with the server responseN)r   r   ÚcontentÚraise_for_statusr   r   r   Ú
exceptionsÚ	HTTPErrorÚ
ValueErrorÚKeyError)Úresponser	   r	   r
   r   @   s    	
r   c                 C   sR   dg}| dk	r"|  d¡ |  | ¡ |  d¡ tj tj¡}| d |¡|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ÚmsgÚreporterr	   r	   r
   r   T   s    


r   )N)Ú__doc__Úloggingr   Zzope.componentr   Zcertbotr   r   Ú	getLoggerÚ__name__r   r   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   
