Spaces:
Running
Running
Download src/openenv/core/utils.py from shankerram3/wildfire_env: direct link, hf CLI and curl.
- Browser
- Download file 790 Bytes
-
https://huggingface.co/spaces/shankerram3/wildfire_env/resolve/main/src/openenv/core/utils.py
- Command line
-
hf download hf://spaces/shankerram3/wildfire_env/src/openenv/core/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/shankerram3/wildfire_env/resolve/main/src/openenv/core/utils.py
790 Bytes
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. | |
| # | |
| # This source code is licensed under the BSD-style license found in the | |
| # LICENSE file in the root directory of this source tree. | |
| """Utility functions for OpenEnv core.""" | |
| def convert_to_ws_url(url: str) -> str: | |
| """ | |
| Convert an HTTP/HTTPS URL to a WS/WSS URL. | |
| Args: | |
| url: The URL to convert. | |
| Returns: | |
| The converted WebSocket URL. | |
| """ | |
| ws_url = url.rstrip("/") | |
| if ws_url.startswith("http://"): | |
| ws_url = "ws://" + ws_url[7:] | |
| elif ws_url.startswith("https://"): | |
| ws_url = "wss://" + ws_url[8:] | |
| elif not ws_url.startswith("ws://") and not ws_url.startswith("wss://"): | |
| ws_url = "ws://" + ws_url | |
| return ws_url | |