diff --git a/gunicorn/config.py b/gunicorn/config.py index f272bcc9..cfafe081 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -143,17 +143,9 @@ class Config(object): @property def ssl_options(self): opts = {} - - for attr in('certfile', 'keyfile', 'cert_reqs', 'ssl_version', \ - 'ca_certs', 'suppress_ragged_eofs', 'do_handshake_on_connect', - 'ciphers'): - - # suppress_ragged_eofs/do_handshake_on_connect are booleans that can - # be False hence we use hasattr instead of getattr(self, attr, None). - if hasattr(self, attr): - value = getattr(self, attr) - opts[attr] = value - + for name, value in self.settings.items(): + if value.section == 'Ssl': + opts[name] = value.get() return opts @property @@ -1552,12 +1544,13 @@ class DoHandshakeOnConnect(Setting): Whether to perform SSL handshake on socket connect (see stdlib ssl module's) """ -class Ciphers(Setting): - name = "ciphers" - section = "Ssl" - cli = ["--ciphers"] - validator = validate_string - default = 'TLSv1' - desc = """\ - Ciphers to use (see stdlib ssl module's) - """ +if sys.version_info >= (2, 7): + class Ciphers(Setting): + name = "ciphers" + section = "Ssl" + cli = ["--ciphers"] + validator = validate_string + default = 'TLSv1' + desc = """\ + Ciphers to use (see stdlib ssl module's) + """ diff --git a/tests/test_007-ssl.py b/tests/test_007-ssl.py index 54a001c1..b61788d8 100644 --- a/tests/test_007-ssl.py +++ b/tests/test_007-ssl.py @@ -8,13 +8,17 @@ # stdlib import inspect import ssl +import sys from unittest import TestCase # gunicorn from gunicorn.config import KeyFile, CertFile, SSLVersion, CACerts, \ - SuppressRaggedEOFs, DoHandshakeOnConnect, Ciphers, Setting, validate_bool, validate_string, \ + SuppressRaggedEOFs, DoHandshakeOnConnect, Setting, validate_bool, validate_string, \ validate_pos_int +if sys.version_info >= (2, 7): + from gunicorn.config import Ciphers + class SSLTestCase(TestCase): def test_settings_classes(self): """ Tests all settings options and their defaults. @@ -59,8 +63,10 @@ class SSLTestCase(TestCase): self.assertEquals(DoHandshakeOnConnect.action, 'store_true') self.assertEquals(DoHandshakeOnConnect.default, False) - self.assertTrue(issubclass(Ciphers, Setting)) - self.assertEquals(Ciphers.name, 'ciphers') - self.assertEquals(Ciphers.section, 'Ssl') - self.assertEquals(Ciphers.cli, ['--ciphers']) - self.assertEquals(Ciphers.default, 'TLSv1') + + if sys.version_info >= (2, 7): + self.assertTrue(issubclass(Ciphers, Setting)) + self.assertEquals(Ciphers.name, 'ciphers') + self.assertEquals(Ciphers.section, 'Ssl') + self.assertEquals(Ciphers.cli, ['--ciphers']) + self.assertEquals(Ciphers.default, 'TLSv1')