
    M/e                     2   d Z ddlZddlm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  ej                  e      Zd	ej$                  d
e
ddfdZd	ej$                  d
ee
   ddfdZdefdZdeddfdZdej2                  ddfdZddee   ddfdZy)z'Subscribes users to the EFF newsletter.    N)Optional)configuration)	constants)Account)AccountFileStorage)utilconfigaccreturnc                    | j                   du ry| j                   du rD| j                  t        d       nm|j                  j	                  | j                        |_        nA| j                  r5t               r+|j                  j	                  | j                        |_        |j                  j                  rt        |       }|j                  |       yy)a  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 configuration.NamespaceConfig config: Client configuration.
    :param Account acc: Current client account.

    FNTz$you didn't provide an e-mail addressregister_to_eff)		eff_emailemail_report_failuremetaupdate_want_subscriptionr   r   update_metar	   r
   storages      7/usr/lib/python3/dist-packages/certbot/_internal/eff.pyprepare_subscriptionr      s     5 4<<BCxxv||DCH	,.88??6<<?@
xx$V,C       c                    | j                   s|sy|j                  j                  r]t        |j                  j                         |j                  j	                  d      |_        t        |       }|j                  |       yy)a   High level function to take care of EFF newsletter subscriptions.

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

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

    Nr   )dry_runr   r   	subscriber   r   r   r   s      r   handle_subscriptionr   ,   sb     ~~S
xx#((**+88??4?8$V,C   r   c                  4    d} t        j                  | d      S )zDoes the user want to be subscribed to the EFF newsletter?

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

    ao  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. F)default)display_utilyesno)prompts    r   r   r   ?   s"    	N  fe44r   r   c                     t         j                  }d| dd}t        j                  d|        t        j	                  d||       t        t        j                  ||d             y)	zhSubscribe the user to the EFF mailing list.

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

    json%eff_supporters_library_subscribe_form)	data_typer   form_idz.Subscribe to the EFF mailing list (email: %s).zSending POST request to %s:
%s<   )datatimeoutN)r   EFF_SUBSCRIBE_URIloggerinfodebug_check_responserequestspost)r   urlr*   s      r   r   r   O   sW     
%
%C>@D KK@%H
LL2C>HMM#D"=>r   responsec                 4   t         j                  d| j                         	 | j                          | j	                         d   st        d       yy# t        j                  j                  $ r t                Y yt        t        f$ r t        d       Y yw xY w)zCheck 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   r1   
exceptions	HTTPError
ValueErrorKeyError)r4   s    r   r0   r0   ^   s     LL)8+;+;<H!!#}}x(GH )(( ! HFGHs   .A 'B;BBreasonc                     dg}| "|j                  d       |j                  |        |j                  d       t        j                  dj                  |             y)zNotify 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!   notifyjoin)r=   msgs     r   r   r   r   sN     B
BC

;

6JJKL%r   )N)__doc__loggingtypingr   r1   certbotr   certbot._internalr   certbot._internal.accountr   r   certbot.displayr   r!   	getLogger__name__r-   NamespaceConfigr   r   boolr   strr   Responser0   r    r   r   <module>rR      s    -    ! ' - 8 0			8	$!!>!> !W !QU !8! = = !HWDU !Z^ !&5D 5 ?S ?T ?Hh// HD H(&HSM &T &r   