Merge pull request #102 from kuba/pep8

PEP8
This commit is contained in:
James Kasten 2014-11-29 16:29:35 -08:00
commit add0351d20
5 changed files with 75 additions and 28 deletions

View file

@ -0,0 +1 @@
"""Let's Encrypt."""

View file

@ -0,0 +1 @@
"""Let's Encrypt client."""

View file

@ -1,33 +1,41 @@
"""Recovery Contact Identifier Validation Challenge."""
import time
import dialog
import requests
import time
from letsencrypt.client import challenge
class RecoveryContact(challenge.Challenge):
"""Recovery Contact Identitifier Validation Challange.
def __init__(self, activationURL = "", successURL = "", contact = "", poll_delay = 3):
Based on draft-barnes-acme, section 6.3.
"""
def __init__(self, activation_url="", success_url="", contact="",
poll_delay=3):
self.token = ""
self.activationURL = activationURL
self.successURL = successURL
self.activation_url = activation_url
self.success_url = success_url
self.contact = contact
self.poll_delay = poll_delay
def perform(self, quiet = True):
def perform(self, quiet=True):
d = dialog.Dialog()
if quiet:
if self.successURL:
if self.success_url:
d.infobox(self.get_display_string())
return self.poll(10, quiet)
else:
exit, self.token = d.inputbox(self.get_display_string())
if exit != d.OK:
code, self.token = d.inputbox(self.get_display_string())
if code != d.OK:
return False
else:
print self.get_display_string()
if self.successURL:
if self.success_url:
return self.poll(10, quiet)
else:
self.token = raw_input("Enter the recovery token:")
@ -38,18 +46,35 @@ class RecoveryContact(challenge.Challenge):
return
def get_display_string(self):
string = "Recovery Contact Challenge: "
if self.activationURL:
string += "Proceed to the URL to continue " + self.activationURL
"""Create information message for the user.
if self.activationURL and self.contact:
string += " or respond to the recovery email sent to " + self.contact
:returns: Message to be displayed to the user.
:rtype: str
"""
msg = "Recovery Contact Challenge: "
if self.activation_url:
msg += "Proceed to the URL to continue " + self.activation_url
if self.activation_url and self.contact:
msg += " or respond to the recovery email sent to " + self.contact
elif self.contact:
string += "Recovery email sent to" + self.contact
msg += "Recovery email sent to" + self.contact
def poll(self, rounds = 10, quiet = True):
for i in range(rounds):
if requests.get(self.successURL).status_code != 200:
return msg
def poll(self, rounds=10, quiet=True):
"""Poll the server.
:param int rounds: Number of poll attempts.
:param bool quiet: Display dialog box if True, raw prompt otherwise.
:returns:
:rtype: bool
"""
for _ in xrange(rounds):
if requests.get(self.success_url).status_code != 200:
time.sleep(self.poll_delay)
else:
return True
@ -57,8 +82,18 @@ class RecoveryContact(challenge.Challenge):
return self.poll(rounds, quiet)
else:
return False
def prompt_continue(self, quiet = True):
prompt = "You have not completed the challenge yet, would you like to continue?"
def prompt_continue(self, quiet=True):
"""Prompt user for continuation.
:param bool quiet: Display dialog box if True, raw prompt otherwise.
:returns: True if user agreed, False otherwise.
:rtype: bool
"""
prompt = ("You have not completed the challenge yet, "
"would you like to continue?")
if quiet:
ans = dialog.Dialog().yesno(prompt, width=70)
else:
@ -68,6 +103,9 @@ class RecoveryContact(challenge.Challenge):
def generate_response(self):
if self.token == "":
return {"type":"recoveryContact"}
return {"type":"recoveryContact", "token":self.token}
if not self.token:
return {"type": "recoveryContact"}
return {
"type": "recoveryContact",
"token": self.token,
}

View file

@ -1,9 +1,15 @@
"""Recovery Token Identifier Validation Challenge."""
import dialog
from letsencrypt.client import challenge
class RecoveryToken(challenge.Challenge):
"""Recovery Token Identifier Validation Challenge.
Based on draft-barnes-acme, section 6.4.
"""
def __init__(self, configurator):
super(RecoveryToken, self).__init__(configurator)
@ -12,13 +18,13 @@ class RecoveryToken(challenge.Challenge):
def perform(self, quiet=True):
cancel, self.token = dialog.generic_input(
"Please Input Recovery Token: ")
if cancel == 1:
return False
return True
return cancel != 1
def cleanup(self):
pass
def generate_response(self):
return {"type": "recoveryToken", "token": self.token}
return {
"type": "recoveryToken",
"token": self.token,
}

View file

@ -0,0 +1 @@
"""Let's Encrypt scripts."""