Skip to content

Commit

Permalink
Keep trying, you are nearly there.
Browse files Browse the repository at this point in the history
  • Loading branch information
mithrandi committed Oct 5, 2016
1 parent 78ead8c commit c99da60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/txacme/challenges/_libcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from txacme.errors import NotInZone, ZoneNotFound
from txacme.interfaces import IResponder
from txacme.util import const


def _daemon_thread(*a, **kw):
Expand Down Expand Up @@ -135,7 +136,7 @@ def create(cls, reactor, driver_name, username, password, zone_name=None,
"""
return cls(
reactor=reactor,
thread_pool=pool(lambda: 1, threadFactory=_daemon_thread),
thread_pool=pool(const(1), threadFactory=_daemon_thread),
driver=get_driver(driver_name)(username, password),
zone_name=zone_name,
settle_delay=settle_delay)
Expand Down
17 changes: 14 additions & 3 deletions src/txacme/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from txacme.test.matchers import ValidForName
from txacme.test.test_client import RSA_KEY_512, RSA_KEY_512_RAW
from txacme.util import (
cert_cryptography_to_pyopenssl, csr_for_names, decode_csr, encode_csr,
generate_private_key, generate_tls_sni_01_cert,
cert_cryptography_to_pyopenssl, const, csr_for_names, decode_csr,
encode_csr, generate_private_key, generate_tls_sni_01_cert,
key_cryptography_to_pyopenssl)


Expand Down Expand Up @@ -160,4 +160,15 @@ def test_common_name_too_long(self):
u'san.too.long.invalid')]))))


__all__ = ['GeneratePrivateKeyTests', 'GenerateCertTests', 'CSRTests']
class ConstTests(TestCase):
"""
`~txacme.util.const` returns a function that always returns a constant
value.
"""
@given(s.integers())
def test_const(self, x):
self.assertThat(const(x)(), Equals(x))


__all__ = [
'GeneratePrivateKeyTests', 'GenerateCertTests', 'CSRTests', 'ConstTests']
9 changes: 8 additions & 1 deletion src/txacme/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,15 @@ def check_directory_url_type(url):
'got {!r} instead'.format(url))


def const(x):
"""
Return a constant function.
"""
return lambda: x


__all__ = [
'generate_private_key', 'generate_tls_sni_01_cert',
'cert_cryptography_to_pyopenssl', 'key_cryptography_to_pyopenssl', 'tap',
'encode_csr', 'decode_csr', 'csr_for_names', 'clock_now',
'check_directory_url_type']
'check_directory_url_type', 'const']

0 comments on commit c99da60

Please sign in to comment.