Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test_dcl_server.py for Python 3.10+ compatibility (#37549) #37589

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: test_dcl_server",
"type": "debugpy",
"request": "launch",
"program": "/workspace/connectedhomeip/examples/chip-tool/commands/dcl/test_dcl_server.py",
"args": [],
"console": "integratedTerminal"
},
{
"name": "Attach to running process",
"type": "lldb",
Expand Down
32 changes: 19 additions & 13 deletions examples/chip-tool/commands/dcl/test_dcl_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,25 @@ def handle_tc_request(self, vendor_id, product_id):


def run_https_server(cert_file="cert.pem", key_file="key.pem"):
httpd = http.server.HTTPServer(
(DEFAULT_HOSTNAME, DEFAULT_PORT), RESTRequestHandler)

httpd.socket = ssl.wrap_socket(
httpd.socket,
server_side=True,
certfile=cert_file,
keyfile=key_file,
ssl_version=ssl.PROTOCOL_TLS,
)

print(f"Serving on https://{DEFAULT_HOSTNAME}:{DEFAULT_PORT}")
httpd.serve_forever()
# Creates a basic HTTP server instance that listens on DEFAULT_HOSTNAME and DEFAULT_PORT
# RESTRequestHandler handles incoming HTTP requests
httpd = http.server.HTTPServer((DEFAULT_HOSTNAME, DEFAULT_PORT), RESTRequestHandler)

# Creates an SSL context using TLS protocol for secure communications
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)

# Loads the SSL certificate and private key for the server
# cert_file: contains the server's public certificate
# key_file: contains the server's private key
context.load_cert_chain(certfile=cert_file, keyfile=key_file)

# Uses a context manager (with statement) to wrap the HTTP server's socket with SSL
# server_side=True indicates this is a server socket
# The wrapped socket is automatically closed when exiting the with block
with context.wrap_socket(httpd.socket, server_side=True) as httpd.socket:
print(f"Serving on https://{DEFAULT_HOSTNAME}:{DEFAULT_PORT}")
# Starts the server and runs indefinitely, handling incoming HTTPS requests
httpd.serve_forever()


# Generate self-signed certificates if needed
Expand Down
Loading