Move tls_verbose_logging extraction from __init__ to from_settings.

This commit is contained in:
Andrey Rakhmatullin 2019-07-18 20:49:25 +05:00
parent a96a07bc76
commit 42743fd9dd
3 changed files with 10 additions and 9 deletions

View File

@ -440,8 +440,8 @@ or even enable client-side authentication (and various other things).
If you do use a custom ContextFactory, make sure its ``__init__`` method
accepts a ``method`` parameter (this is the ``OpenSSL.SSL`` method mapping
:setting:`DOWNLOADER_CLIENT_TLS_METHOD`) and a ``settings`` parameter (this is
the Scrapy :class:`~scrapy.settings.Settings` object).
:setting:`DOWNLOADER_CLIENT_TLS_METHOD`) and a ``tls_verbose_logging``
parameter (``bool``).
.. setting:: DOWNLOADER_CLIENT_TLS_METHOD

View File

@ -29,17 +29,18 @@ if twisted_version >= (14, 0, 0):
understand the SSLv3, TLSv1, TLSv1.1 and TLSv1.2 protocols.'
"""
def __init__(self, method=SSL.SSLv23_METHOD, settings=None, *args, **kwargs):
def __init__(self, method=SSL.SSLv23_METHOD, tls_verbose_logging=False, *args, **kwargs):
super(ScrapyClientContextFactory, self).__init__(*args, **kwargs)
self._ssl_method = method
if settings:
self.tls_verbose_logging = settings['DOWNLOADER_CLIENT_TLS_VERBOSE_LOGGING']
else:
self.tls_verbose_logging = False
self.tls_verbose_logging = tls_verbose_logging
@classmethod
def from_settings(cls, settings, method=SSL.SSLv23_METHOD, *args, **kwargs):
return cls(method=method, settings=settings, *args, **kwargs)
if settings:
tls_verbose_logging = settings.getbool('DOWNLOADER_CLIENT_TLS_VERBOSE_LOGGING')
else:
tls_verbose_logging = False
return cls(method=method, tls_verbose_logging=tls_verbose_logging, *args, **kwargs)
def getCertificateOptions(self):
# setting verify=True will require you to provide CAs

View File

@ -51,7 +51,7 @@ class HTTP11DownloadHandler(object):
self._contextFactory = create_instance(self._contextFactoryClass, settings=settings, crawler=None)
msg = """
'%s' does not accept `method` argument (type OpenSSL.SSL method,\
e.g. OpenSSL.SSL.SSLv23_METHOD) and/or `settings` argument.\
e.g. OpenSSL.SSL.SSLv23_METHOD) and/or `tls_verbose_logging` argument.\
Please upgrade your context factory class to handle them or ignore them.""" % (
settings['DOWNLOADER_CLIENTCONTEXTFACTORY'],)
warnings.warn(msg)