GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — vscode-python/pythonFiles/testing_tools/socket_manager.py at main · dafeda/vscode-python Expand file tree/ Copy pathsocket_manager.pyMore file actions 50 lines (39 loc) · 1.22 KB / Copy pathsocket_manager.pyFile metadata and controls50 lines (39 loc) · 1.22 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import socket import sys class SocketManager(object): """Create a socket and connect to the given address. The address is a (host: str, port: int) tuple. Example usage: ``` with SocketManager(("localhost", 6767)) as sock: request = json.dumps(payload) result = s.socket.sendall(request.encode("utf-8")) ``` """ def __init__(self, addr): self.addr = addr self.socket = None def __enter__(self): return self.connect() def __exit__(self, *_): self.close() def connect(self): self.socket = socket.socket( socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP ) if sys.platform == "win32": addr_use = socket.SO_EXCLUSIVEADDRUSE else: addr_use = socket.SO_REUSEADDR self.socket.setsockopt(socket.SOL_SOCKET, addr_use, 1) self.socket.connect(self.addr) return self def close(self): if self.socket: try: self.socket.shutdown(socket.SHUT_RDWR) except Exception: pass self.socket.close() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |