forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.py
More file actions
72 lines (58 loc) · 1.82 KB
/
Copy pathprotocol.py
File metadata and controls
72 lines (58 loc) · 1.82 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2015-2025 NV Access Limited, Christopher Toth, Tyler Spivey, Babbage B.V., David Sexton and others.
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
import urllib.parse
from enum import StrEnum
PROTOCOL_VERSION: int = 2
class RemoteMessageType(StrEnum):
# Connection and Protocol Messages
PROTOCOL_VERSION = "protocol_version"
JOIN = "join"
CHANNEL_JOINED = "channel_joined"
CLIENT_JOINED = "client_joined"
CLIENT_LEFT = "client_left"
GENERATE_KEY = "generate_key"
# Control Messages
KEY = "key"
SPEAK = "speak"
CANCEL = "cancel"
PAUSE_SPEECH = "pause_speech"
TONE = "tone"
WAVE = "wave"
SEND_SAS = "send_SAS" # Send Secure Attention Sequence
INDEX = "index"
# Display and Braille Messages
DISPLAY = "display"
BRAILLE_INPUT = "braille_input"
SET_BRAILLE_INFO = "set_braille_info"
SET_DISPLAY_SIZE = "set_display_size"
# Clipboard Operations
SET_CLIPBOARD_TEXT = "set_clipboard_text"
# System Messages
MOTD = "motd"
VERSION_MISMATCH = "version_mismatch"
PING = "ping"
ERROR = "error"
NVDA_NOT_CONNECTED = (
"nvda_not_connected" # This was added in version 2 but never implemented on the server
)
SERVER_PORT = 6837
URL_PREFIX = "nvdaremote://"
def addressToHostPort(addr) -> tuple:
"""Converts an address such as google.com:80 into a tuple of (address, port).
If no port is given, use SERVER_PORT.
"""
addr = urllib.parse.urlparse("//" + addr)
port = addr.port or SERVER_PORT
return (addr.hostname, port)
def hostPortToAddress(hostPort: tuple) -> str:
"""Converts a tuple of (address, port) into a string such as google.com:80.
If the port is SERVER_PORT, it is omitted
"""
host, port = hostPort
if ":" in host:
host = f"[{host}]"
if port != SERVER_PORT:
return f"{host}:{port}"
return host