Skip to content

Commit 27f5e16

Browse files
committed
enable running on platforms without ssl
1 parent 09e5431 commit 27f5e16

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

adafruit_httpserver/server.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
except ImportError:
1313
pass
1414

15-
from ssl import SSLContext, create_default_context
1615
from errno import EAGAIN, ECONNRESET, ETIMEDOUT
1716
from sys import implementation
1817
from time import monotonic, sleep
@@ -34,8 +33,20 @@
3433
from .route import Route
3534
from .status import BAD_REQUEST_400, UNAUTHORIZED_401, FORBIDDEN_403, NOT_FOUND_404
3635

37-
if implementation.name != "circuitpython":
38-
from ssl import Purpose, CERT_NONE, SSLError # pylint: disable=ungrouped-imports
36+
try:
37+
from ssl import SSLContext, create_default_context
38+
39+
try: # ssl imports for C python
40+
from ssl import (
41+
Purpose,
42+
CERT_NONE,
43+
SSLError,
44+
) # pylint: disable=ungrouped-imports
45+
except ImportError:
46+
pass
47+
SSL_AVAILABLE = True
48+
except ImportError:
49+
SSL_AVAILABLE = False
3950

4051

4152
NO_REQUEST = "no_request"
@@ -129,6 +140,8 @@ def __init__(
129140
self.https = https
130141

131142
if https:
143+
if not SSL_AVAILABLE:
144+
raise NotImplementedError("SSL not available on this platform")
132145
self._validate_https_cert_provided(certfile, keyfile)
133146
self._ssl_context = self._create_ssl_context(certfile, keyfile)
134147
else:

0 commit comments

Comments
 (0)