| 1016 | |
| 1017 | if _have_ssl: |
| 1018 | class NNTP_SSL(NNTP): |
| 1019 | |
| 1020 | def __init__(self, host, port=NNTP_SSL_PORT, |
| 1021 | user=None, password=None, ssl_context=None, |
| 1022 | readermode=None, usenetrc=False, |
| 1023 | timeout=_GLOBAL_DEFAULT_TIMEOUT): |
| 1024 | """This works identically to NNTP.__init__, except for the change |
| 1025 | in default port and the `ssl_context` argument for SSL connections. |
| 1026 | """ |
| 1027 | self.ssl_context = ssl_context |
| 1028 | super().__init__(host, port, user, password, readermode, |
| 1029 | usenetrc, timeout) |
| 1030 | |
| 1031 | def _create_socket(self, timeout): |
| 1032 | sock = super()._create_socket(timeout) |
| 1033 | try: |
| 1034 | sock = _encrypt_on(sock, self.ssl_context, self.host) |
| 1035 | except: |
| 1036 | sock.close() |
| 1037 | raise |
| 1038 | else: |
| 1039 | return sock |
| 1040 | |
| 1041 | __all__.append("NNTP_SSL") |
| 1042 | |