Skip to content

Commit 095495e

Browse files
committed
Backward-compatibility for common Scrapy context factory patterns
1 parent 3f946b5 commit 095495e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

scrapy/core/downloader/contextfactory.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ def __init__(self, method=SSL.SSLv23_METHOD, *args, **kwargs):
3030
def getCertificateOptions(self):
3131
# setting verify=True will require you to provide CAs
3232
# to verify against; in other words: it's not that simple
33-
return CertificateOptions(verify=False, method=self._ssl_method)
33+
34+
# backward-compatible SSL/TLS method:
35+
#
36+
# * this will respect `method` attribute in often recommended
37+
# `ScrapyClientContextFactory` subclass
38+
# (https://github.com/scrapy/scrapy/issues/1429#issuecomment-131782133)
39+
#
40+
# * getattr() for `_ssl_method` attribute for context factories
41+
# not calling super(..., self).__init__
42+
return CertificateOptions(verify=False,
43+
method=getattr(self, 'method',
44+
getattr(self, '_ssl_method', None)))
3445

3546
# kept for old-style HTTP/1.0 downloader context twisted calls,
3647
# e.g. connectSSL()

scrapy/core/downloader/tls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
METHOD_TLSv12 = 'TLSv1.2'
99

1010
openssl_methods = {
11-
METHOD_TLS: SSL.SSLv23_METHOD, # protocol negotiation (recommended)
12-
METHOD_SSLv3: SSL.SSLv3_METHOD, # SSL 3 (NOT recommended)
11+
METHOD_TLS: SSL.SSLv23_METHOD, # protocol negotiation (recommended)
12+
METHOD_SSLv3: SSL.SSLv3_METHOD, # SSL 3 (NOT recommended)
1313
METHOD_TLSv10: SSL.TLSv1_METHOD, # TLS 1.0 only
1414
METHOD_TLSv11: getattr(SSL, 'TLSv1_1_METHOD', 5), # TLS 1.1 only
1515
METHOD_TLSv12: getattr(SSL, 'TLSv1_2_METHOD', 6), # TLS 1.2 only

0 commit comments

Comments
 (0)