diff --git a/xpra/net/bytestreams.py b/xpra/net/bytestreams.py index 1c24aa6795..9f6ae49ed4 100644 --- a/xpra/net/bytestreams.py +++ b/xpra/net/bytestreams.py @@ -8,7 +8,7 @@ import os import errno import socket -from typing import Dict, Any, Optional, Union +from typing import Dict, Any, Optional, Union, Callable from xpra.net.common import ConnectionClosedException, IP_SOCKTYPES, TCP_SOCKTYPES from xpra.util import envint, envbool, hasenv, csv @@ -77,7 +77,7 @@ def can_retry(e) -> Union[bool,str]: raise ConnectionClosedException(e) from None return False -def untilConcludes(is_active_cb, can_retry_cb, f, *a, **kw): +def untilConcludes(is_active_cb:Callable, can_retry_cb:Callable, f:Callable, *a, **kw): while is_active_cb(): try: return f(*a, **kw) diff --git a/xpra/net/file_transfer.py b/xpra/net/file_transfer.py index 96e76794c5..c33b782e26 100644 --- a/xpra/net/file_transfer.py +++ b/xpra/net/file_transfer.py @@ -10,7 +10,7 @@ import uuid from time import monotonic from dataclasses import dataclass -from typing import Dict, Any, Optional, Callable, Set +from typing import Dict, Any, Optional, Callable, Set, Tuple from xpra.child_reaper import getChildReaper from xpra.os_util import bytestostr, strtobytes, umask_context, POSIX, WIN32 @@ -40,7 +40,7 @@ ACCEPT = 1 #the file / URL will be sent OPEN = 2 #don't send, open on sender -def osclose(fd): +def osclose(fd:int) -> None: try: os.close(fd) except OSError as e: @@ -48,7 +48,7 @@ def osclose(fd): filelog.error("Error closing file download:") filelog.estr(e) -def basename(filename): +def basename(filename:str) -> str: #we can't use os.path.basename, #because the remote end may have sent us a filename #which is using a different pathsep @@ -66,7 +66,7 @@ def basename(filename): tmp += char return tmp -def safe_open_download_file(basefilename, mimetype): +def safe_open_download_file(basefilename:str, mimetype:str): from xpra.platform.paths import get_download_dir # pylint: disable=import-outside-toplevel dd = os.path.expanduser(get_download_dir()) filename = os.path.abspath(os.path.join(dd, basename(basefilename))) @@ -124,13 +124,13 @@ class FileTransferAttributes: def __init__(self): self.init_attributes() - def init_opts(self, opts, can_ask=True): + def init_opts(self, opts, can_ask=True) -> None: #get the settings from a config object self.init_attributes(opts.file_transfer, opts.file_size_limit, opts.printing, opts.open_files, opts.open_url, opts.open_command, can_ask) def init_attributes(self, file_transfer="no", file_size_limit=10, printing="no", - open_files="no", open_url="no", open_command=None, can_ask=True): + open_files="no", open_url="no", open_command=None, can_ask=True) -> None: filelog("file transfer: init_attributes%s", (file_transfer, file_size_limit, printing, open_files, open_url, open_command, can_ask)) def pbool(name, v): @@ -206,7 +206,7 @@ class FileTransferHandler(FileTransferAttributes): used by both clients and server to share the common code and attributes """ - def init_attributes(self, *args): + def init_attributes(self, *args) -> None: super().init_attributes(*args) self.remote_file_transfer = False self.remote_file_transfer_ask = False @@ -230,7 +230,7 @@ def init_attributes(self, *args): self.idle_add = GLib.idle_add self.source_remove = GLib.source_remove - def cleanup(self): + def cleanup(self) -> None: for t in self.pending_send_data_timers.values(): self.source_remove(t) self.pending_send_data_timers = {} @@ -247,7 +247,7 @@ def cleanup(self): self.init_attributes() - def parse_file_transfer_caps(self, c): + def parse_file_transfer_caps(self, c) -> None: fc = c.dictget("file") if fc: fc = typedict(fc) @@ -278,7 +278,7 @@ def parse_file_transfer_caps(self, c): self.remote_file_chunks = max(0, min(self.remote_file_size_limit, c.intget("file-chunks"))) self.dump_remote_caps() - def dump_remote_caps(self): + def dump_remote_caps(self) -> None: filelog("file transfer remote caps: file-transfer=%-5s (ask=%s)", self.remote_file_transfer, self.remote_file_transfer_ask) filelog("file transfer remote caps: printing=%-5s (ask=%s)", @@ -306,7 +306,7 @@ def get_info(self) -> Dict[str,Any]: return info - def digest_mismatch(self, filename:str, digest, expected_digest): + def digest_mismatch(self, filename:str, digest, expected_digest) -> None: filelog.error(f"Error: data does not match, invalid {digest.name} file digest") filelog.error(f" for {filename!r}") filelog.error(f" received {digest.hexdigest()}") @@ -318,7 +318,7 @@ def digest_mismatch(self, filename:str, digest, expected_digest): filelog.error(f"Error: failed to delete uploaded file {filename}") - def _check_chunk_receiving(self, chunk_id:int, chunk_no:int): + def _check_chunk_receiving(self, chunk_id:int, chunk_no:int) -> None: chunk_state = self.receive_chunks_in_progress.get(chunk_id) filelog("_check_chunk_receiving(%s, %s) chunk_state=%s", chunk_id, chunk_no, chunk_state) if not chunk_state: @@ -332,7 +332,7 @@ def _check_chunk_receiving(self, chunk_id:int, chunk_no:int): filelog.error(f"Error: chunked file transfer f{chunk_id} timed out") self.receive_chunks_in_progress.pop(chunk_id, None) - def cancel_download(self, send_id:str, message="Cancelled"): + def cancel_download(self, send_id:str, message="Cancelled") -> None: filelog("cancel_download(%s, %s)", send_id, message) for chunk_id, chunk_state in dict(self.receive_chunks_in_progress).items(): if chunk_state.send_id==send_id: @@ -340,7 +340,7 @@ def cancel_download(self, send_id:str, message="Cancelled"): return filelog.error("Error: cannot cancel download %s, entry not found!", u(send_id)) - def cancel_file(self, chunk_id:int, message:str, chunk:int=0): + def cancel_file(self, chunk_id:int, message:str, chunk:int=0) -> None: filelog("cancel_file%s", (chunk_id, message, chunk)) chunk_state = self.receive_chunks_in_progress.get(chunk_id) if chunk_state: @@ -366,7 +366,7 @@ def clean_receive_state(): filelog.error(f" {filename!r} : {e}") self.send("ack-file-chunk", chunk_id, False, message, chunk) - def _process_send_file_chunk(self, packet): + def _process_send_file_chunk(self, packet) -> None: chunk_id, chunk, file_data, has_more = packet[1:5] chunk_id = net_utf8(chunk_id) #if len(file_data)<1024: @@ -452,7 +452,7 @@ def progress(position, error=None): self.process_downloaded_file(filename, chunk_state.mimetype, chunk_state.printit, chunk_state.openit, chunk_state.filesize, options) - def accept_data(self, send_id:str, dtype, basefilename:str, printit:bool, openit:bool): + def accept_data(self, send_id:str, dtype, basefilename:str, printit:bool, openit:bool) -> Tuple[bool,bool]: #subclasses should check the flags, #and if ask is True, verify they have accepted this specific send_id filelog("accept_data%s", (send_id, dtype, basefilename, printit, openit)) @@ -477,7 +477,7 @@ def accept_data(self, send_id:str, dtype, basefilename:str, printit:bool, openit openit = False return (printit, openit) - def _process_send_file(self, packet): + def _process_send_file(self, packet) -> None: #the remote end is sending us a file start = monotonic() basefilename, mimetype, printit, openit, filesize, file_data, options = packet[1:8] @@ -569,7 +569,7 @@ def _process_send_file(self, packet): self.process_downloaded_file(filename, mimetype, printit, openit, filesize, options) - def process_downloaded_file(self, filename, mimetype, printit, openit, filesize, options): + def process_downloaded_file(self, filename:str, mimetype:str, printit:bool, openit:bool, filesize:int, options) -> None: filelog.info("downloaded %s bytes to %s file%s:", filesize, (mimetype or "temporary"), ["", " for printing"][int(printit)]) filelog.info(" '%s'", filename) @@ -665,11 +665,11 @@ def get_open_env(self) -> Dict[str,str]: env["XPRA_XDG_OPEN"] = "1" return env - def _open_file(self, url:str): + def _open_file(self, url:str) -> None: filelog("_open_file(%s)", url) self.exec_open_command(url) - def _open_url(self, url:str): + def _open_url(self, url:str) -> None: filelog("_open_url(%s)", url) if POSIX: #we can't use webbrowser, @@ -680,7 +680,7 @@ def _open_url(self, url:str): import webbrowser #pylint: disable=import-outside-toplevel webbrowser.open_new_tab(url) - def exec_open_command(self, url:str): + def exec_open_command(self, url:str) -> None: filelog("exec_open_command(%s)", url) try: import shlex #pylint: disable=import-outside-toplevel @@ -705,12 +705,12 @@ def open_done(*_args): cr = getChildReaper() cr.add_process(proc, f"Open file {url}", command, True, True, open_done) - def file_size_warning(self, action:str, location:str, basefilename:str, filesize:int, limit:int): + def file_size_warning(self, action:str, location:str, basefilename:str, filesize:int, limit:int) -> None: filelog.warn("Warning: cannot %s the file '%s'", action, basefilename) filelog.warn(" this file is too large: %sB", std_unit(filesize)) filelog.warn(" the %s file size limit is %sB", location, std_unit(limit)) - def check_file_size(self, action:str, filename:str, filesize:int): + def check_file_size(self, action:str, filename:str, filesize:int) -> bool: basefilename = os.path.basename(filename) if filesize>self.file_size_limit: self.file_size_warning(action, "local", basefilename, filesize, self.file_size_limit) diff --git a/xpra/net/libproxy.py b/xpra/net/libproxy.py index 39d0a3f57d..68e75e01b5 100644 --- a/xpra/net/libproxy.py +++ b/xpra/net/libproxy.py @@ -73,7 +73,7 @@ class ProxyResolutionError(RuntimeError): def __init__(self): self._pf = _libproxy.px_proxy_factory_new() - def getProxies(self, url): + def getProxies(self, url:str): """Given a URL, returns a list of proxies in priority order to be used to reach that URL. @@ -121,14 +121,13 @@ def getProxies(self, url): i=0 while array[i]: proxy_bytes = cast(array[i], c_char_p).value - proxies.append(proxy_bytes.decode('utf-8', errors='replace')) + if proxy_bytes: + proxies.append(proxy_bytes.decode('utf-8', errors='replace')) i += 1 _libproxy.px_proxy_factory_free_proxies(array) - return proxies def __del__(self): if _libproxy: _libproxy.px_proxy_factory_free(self._pf) - diff --git a/xpra/net/mdns/avahi_listener.py b/xpra/net/mdns/avahi_listener.py index 829b9440d0..654fca498e 100755 --- a/xpra/net/mdns/avahi_listener.py +++ b/xpra/net/mdns/avahi_listener.py @@ -38,10 +38,11 @@ def __init__(self, service_type=XPRA_TCP_MDNS_TYPE, mdns_found=None, mdns_add=No #self.mdns_update = mdns_update self.server = None - def resolve_error(self, *args): + def resolve_error(self, *args) -> None: log.error("AvahiListener.resolve_error%s", args) - def service_resolved(self, interface, protocol, name, stype, domain, host, x, address, port, text_array, v): + def service_resolved(self, interface, protocol, name:str, stype:str, + domain:str, host:str, x, address, port:int, text_array, v) -> None: log("AvahiListener.service_resolved%s", (interface, protocol, name, stype, domain, host, x, address, port, "..", v)) if self.mdns_add: @@ -61,7 +62,7 @@ def service_resolved(self, interface, protocol, name, stype, domain, host, x, ad nargs = (dbus_to_native(x) for x in (interface, protocol, name, stype, domain, host, address, port, text)) self.mdns_add(*nargs) - def service_found(self, interface, protocol, name, stype, domain, flags): + def service_found(self, interface, protocol, name:str, stype:str, domain:str, flags:int) -> None: log("service_found%s", (interface, protocol, name, stype, domain, flags)) if flags & avahi.LOOKUP_RESULT_LOCAL: # local service, skip @@ -72,14 +73,14 @@ def service_found(self, interface, protocol, name, stype, domain, flags): domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), reply_handler=self.service_resolved, error_handler=self.resolve_error) - def service_removed(self, interface, protocol, name, stype, domain, flags): + def service_removed(self, interface, protocol, name:str, stype:str, domain, flags:int) -> None: log("service_removed%s", (interface, protocol, name, stype, domain, flags)) if self.mdns_remove: nargs = (dbus_to_native(x) for x in (interface, protocol, name, stype, domain, flags)) self.mdns_remove(*nargs) - def start(self): + def start(self) -> None: self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, '/'), 'org.freedesktop.Avahi.Server') log("AvahiListener.start() server=%s", self.server) @@ -93,7 +94,7 @@ def start(self): s = self.sbrowser.connect_to_signal("ItemRemove", self.service_removed) self.signal_match.append(s) - def stop(self): + def stop(self) -> None: sm = self.signal_match self.signal_match = [] for s in sm: diff --git a/xpra/net/mdns/avahi_publisher.py b/xpra/net/mdns/avahi_publisher.py index 640e6f97e5..cae1892daf 100755 --- a/xpra/net/mdns/avahi_publisher.py +++ b/xpra/net/mdns/avahi_publisher.py @@ -22,7 +22,7 @@ log = Logger("network", "mdns") -def get_interface_index(host): +def get_interface_index(host) -> int: log("get_interface_index(%s)", host) if host in ("0.0.0.0", "", "*", "::"): return avahi.IF_UNSPEC @@ -52,7 +52,7 @@ class AvahiPublishers: and to convert the text dict into a TXT string. """ - def __init__(self, listen_on, service_name, service_type=XPRA_TCP_MDNS_TYPE, text_dict=None): + def __init__(self, listen_on, service_name:str, service_type:str=XPRA_TCP_MDNS_TYPE, text_dict=None): log("AvahiPublishers%s", (listen_on, service_name, service_type, text_dict)) self.publishers = [] try: @@ -93,7 +93,7 @@ def __init__(self, listen_on, service_name, service_type=XPRA_TCP_MDNS_TYPE, tex service_type, domain="", host=fqdn, text=txt, interface=iface_index)) - def start(self): + def start(self) -> None: log("avahi:starting: %s", self.publishers) if not self.publishers: return @@ -105,12 +105,12 @@ def start(self): log.warn(" to avoid this warning, disable mdns support ") log.warn(" using the 'mdns=no' option") - def stop(self): + def stop(self) -> None: log("stopping: %s", self.publishers) for publisher in self.publishers: publisher.stop() - def update_txt(self, txt): + def update_txt(self, txt) -> None: for publisher in self.publishers: publisher.update_txt(txt) @@ -132,7 +132,7 @@ def __init__(self, bus, name, port, stype=XPRA_TCP_MDNS_TYPE, domain="", host="" self.server = None self.group = None - def iface(self): + def iface(self) -> str: if self.interface>0: return "interface %i" % self.interface return "all interfaces" @@ -143,7 +143,7 @@ def host_str(self) -> str: def __repr__(self): return "AvahiPublisher(%s)" % self.host_str() - def start(self): + def start(self) -> bool: try: self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) @@ -157,7 +157,7 @@ def start(self): self.server.connect_to_signal("StateChanged", self.server_state_changed) return self.server_state_changed(self.server.GetState()) - def server_state_changed(self, state, error=None): + def server_state_changed(self, state, error=None) -> bool: log("server_state_changed(%s, %s) on %s", state, error, self.server) if state == avahi.SERVER_COLLISION: log.error("Error: mdns server name collision") @@ -179,7 +179,7 @@ def server_state_changed(self, state, error=None): log.warn(" for name '%s' and port %i on %s", self.name, self.port, self.iface()) return False - def add_service(self): + def add_service(self) -> None: if not self.group: return try: @@ -207,7 +207,7 @@ def add_service(self): log.error(" %s", x) self.stop() - def stop(self): + def stop(self) -> None: group = self.group log("%s.stop() group=%s", self, group) if group: @@ -220,7 +220,7 @@ def stop(self): self.server = None - def update_txt(self, txt): + def update_txt(self, txt) -> None: if not self.server: log("update_txt(%s) ignored, already stopped", txt) return @@ -257,7 +257,7 @@ def main(): name = "test service" bus = init_system_bus() publishers = [] - def add(service_type=XPRA_TCP_MDNS_TYPE): + def add(service_type:str=XPRA_TCP_MDNS_TYPE): publisher = AvahiPublisher(bus, name, port, stype=service_type, host=host, text=("somename=somevalue",)) publishers.append(publisher) def start(): diff --git a/xpra/net/mdns/zeroconf_listener.py b/xpra/net/mdns/zeroconf_listener.py index d16e5f4efc..04d9500be7 100755 --- a/xpra/net/mdns/zeroconf_listener.py +++ b/xpra/net/mdns/zeroconf_listener.py @@ -29,18 +29,18 @@ def __init__(self, service_type, mdns_found=None, mdns_add=None, mdns_remove=Non def __repr__(self): return "ZeroconfListener(%s)" % self.service_type - def update_service(self, zeroconf, stype, name): + def update_service(self, zeroconf, stype:str, name:str) -> None: log("update_service%s", (zeroconf, stype, name)) if self.mdns_update: self.mdns_update(name, stype) - def remove_service(self, zeroconf, stype, name): + def remove_service(self, zeroconf, stype:str, name:str) -> None: log("remove_service%s", (zeroconf, stype, name)) if self.mdns_remove: domain = "local" self.mdns_remove(0, 0, name, stype, domain, 0) - def add_service(self, zeroconf, stype, name): + def add_service(self, zeroconf, stype:str, name:str): log("add_service%s", (zeroconf, stype, name)) info = zeroconf.get_service_info(stype, name) log("service info: %s", info) @@ -61,11 +61,11 @@ def add_service(self, zeroconf, stype, name): saddress = socket.inet_ntoa(address) self.mdns_add(interface, protocol, name, stype, domain, server, saddress, port, props) - def start(self): + def start(self) -> None: self.browser = ServiceBrowser(self.zeroconf, self.service_type, listener=self) log("ServiceBrowser%s=%s", (self.zeroconf, self.service_type, self), self.browser) - def stop(self): + def stop(self) -> None: b = self.browser if b: self.browser = None diff --git a/xpra/net/mdns/zeroconf_publisher.py b/xpra/net/mdns/zeroconf_publisher.py index 854b62194b..d4012e100c 100755 --- a/xpra/net/mdns/zeroconf_publisher.py +++ b/xpra/net/mdns/zeroconf_publisher.py @@ -5,6 +5,7 @@ # later version. See the file COPYING for details. import socket +from typing import Dict from zeroconf import ServiceInfo, Zeroconf, __version__ as zeroconf_version #@UnresolvedImport from xpra.log import Logger @@ -42,7 +43,7 @@ class ZeroconfPublishers: """ Expose services via python zeroconf """ - def __init__(self, listen_on, service_name, service_type=XPRA_TCP_MDNS_TYPE, text_dict=None): + def __init__(self, listen_on, service_name:str, service_type:str=XPRA_TCP_MDNS_TYPE, text_dict=None): log("ZeroconfPublishers%s", (listen_on, service_name, service_type, text_dict)) self.services = [] self.ports = {} @@ -105,15 +106,15 @@ def add_address(host, port, af=socket.AF_INET): host = "127.0.0.1" add_address(host, port, af) - def start(self): + def start(self) -> None: for s in self.services: s.start() - def stop(self): + def stop(self) -> None: for s in self.services: s.stop() - def update_txt(self, txt): + def update_txt(self, txt) -> None: for s in self.services: s.update_txt(txt) @@ -158,7 +159,7 @@ def __init__(self, address, host, port, service_name, service_type=XPRA_TCP_MDNS log.error(" for port %i", port) log.estr(e) - def start(self): + def start(self) -> None: try: self.zeroconf = Zeroconf(interfaces=[self.host]) except OSError: @@ -172,13 +173,13 @@ def start(self): else: self.registered = True - def stop(self): + def stop(self) -> None: log("ZeroConfPublishers.stop(): %s", self.service) if self.registered: self.zeroconf.unregister_service(self.service) self.zeroconf = None - def txt_rec(self, text_dict): + def txt_rec(self, text_dict) -> Dict: #prevent zeroconf from mangling our ints into booleans: new_dict = {} for k,v in text_dict.items(): @@ -188,7 +189,7 @@ def txt_rec(self, text_dict): new_dict[k] = v return new_dict - def update_txt(self, txt): + def update_txt(self, txt) -> None: if not hasattr(self.zeroconf, "update_service"): log("no update_service with zeroconf version %s", zeroconf_version) return diff --git a/xpra/net/mmap_pipe.py b/xpra/net/mmap_pipe.py index 2ac83d4c1f..8f6bd2d46f 100644 --- a/xpra/net/mmap_pipe.py +++ b/xpra/net/mmap_pipe.py @@ -26,7 +26,7 @@ def get_socket_group(socket_filename) -> int: if isinstance(socket_filename, str) and os.path.exists(socket_filename): s = os.stat(socket_filename) return s.st_gid - log.warn("Warning: missing valid socket filename to set mmap group") + log.warn(f"Warning: missing valid socket filename {socket_filename!r} to set mmap group") return -1 def xpra_group() -> int: @@ -42,7 +42,7 @@ def xpra_group() -> int: return 0 -def init_client_mmap(mmap_group=None, socket_filename=None, size=128*1024*1024, filename=None): +def init_client_mmap(mmap_group=None, socket_filename:str="", size:int=128*1024*1024, filename:str=""): """ Initializes an mmap area, writes the token in it and returns: (success flag, mmap_area, mmap_size, temp_file, mmap_filename) @@ -169,7 +169,7 @@ def validate_size(size : int): clean_mmap(mmap_filename) return rerr() -def clean_mmap(mmap_filename): +def clean_mmap(mmap_filename:str): log("clean_mmap(%s)", mmap_filename) if mmap_filename and os.path.exists(mmap_filename): try: @@ -180,7 +180,7 @@ def clean_mmap(mmap_filename): DEFAULT_TOKEN_BYTES : int = 128 -def write_mmap_token(mmap_area, token, index, count=DEFAULT_TOKEN_BYTES): +def write_mmap_token(mmap_area, token, index:int, count:int=DEFAULT_TOKEN_BYTES): assert count>0 #write the token one byte at a time - no endianness log("write_mmap_token(%s, %#x, %#x, %#x)", mmap_area, token, index, count) @@ -191,7 +191,7 @@ def write_mmap_token(mmap_area, token, index, count=DEFAULT_TOKEN_BYTES): v = v>>8 assert v==0, "token value is too big" -def read_mmap_token(mmap_area, index, count=DEFAULT_TOKEN_BYTES) -> int: +def read_mmap_token(mmap_area, index:int, count:int=DEFAULT_TOKEN_BYTES) -> int: assert count>0 v = 0 for i in range(0, count): @@ -202,7 +202,7 @@ def read_mmap_token(mmap_area, index, count=DEFAULT_TOKEN_BYTES) -> int: return v -def init_server_mmap(mmap_filename:str, mmap_size=0): +def init_server_mmap(mmap_filename:str, mmap_size:int=0): """ Reads the mmap file provided by the client and verifies the token if supplied. @@ -242,7 +242,7 @@ def init_server_mmap(mmap_filename:str, mmap_size=0): mmap_area.close() return None, 0 -def int_from_buffer(mmap_area, pos) -> c_uint32: +def int_from_buffer(mmap_area, pos:int) -> c_uint32: return c_uint32.from_buffer(mmap_area, pos) #@UndefinedVariable diff --git a/xpra/net/socket_util.py b/xpra/net/socket_util.py index 23fff6712d..f3585ffb97 100644 --- a/xpra/net/socket_util.py +++ b/xpra/net/socket_util.py @@ -48,7 +48,7 @@ def get_network_logger(): return network_logger -def create_unix_domain_socket(sockpath:str, socket_permissions=0o600): +def create_unix_domain_socket(sockpath:str, socket_permissions:int=0o600): assert POSIX #convert this to a umask! umask = (0o777-socket_permissions) & 0o777 diff --git a/xpra/net/upnp.py b/xpra/net/upnp.py index dfdba1b2e2..cfbe464b8e 100644 --- a/xpra/net/upnp.py +++ b/xpra/net/upnp.py @@ -6,7 +6,7 @@ from xpra.util import csv -def upnp_add(socktype, info, options): +def upnp_add(socktype:str, info, options): from xpra.log import Logger log = Logger("network", "upnp") log("upnp_add%s", (socktype, info, options)) diff --git a/xpra/net/websockets/common.py b/xpra/net/websockets/common.py index 23ca6cc5b7..fedb0de272 100644 --- a/xpra/net/websockets/common.py +++ b/xpra/net/websockets/common.py @@ -44,7 +44,7 @@ def make_websocket_accept_hash(key:str) -> bytes: accept = sha1(strtobytes(key) + GUID).digest() return b64encode(accept) -def get_headers(host:str, port:int): +def get_headers(host:str, port:int) -> Dict: headers = {} for mod_name in HEADERS_MODULES: try: diff --git a/xpra/net/websockets/headers/browser_cookie.py b/xpra/net/websockets/headers/browser_cookie.py index 551add445b..2c1951d995 100644 --- a/xpra/net/websockets/headers/browser_cookie.py +++ b/xpra/net/websockets/headers/browser_cookie.py @@ -3,12 +3,13 @@ # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. +from typing import Dict import browser_cookie3 # @UnresolvedImport from xpra.os_util import strtobytes -def get_headers(host, port): #pylint: disable=unused-argument +def get_headers(host:str, port:int) -> Dict[bytes,bytes]: #pylint: disable=unused-argument headers = {} cookie_domain = host cookie_string = '' diff --git a/xpra/net/websockets/headers/default.py b/xpra/net/websockets/headers/default.py index 545d97c4a6..b0bfd37562 100644 --- a/xpra/net/websockets/headers/default.py +++ b/xpra/net/websockets/headers/default.py @@ -1,8 +1,9 @@ # This file is part of Xpra. -# Copyright (C) 2019-2020 Antoine Martin +# Copyright (C) 2019-2023 Antoine Martin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. +from typing import Dict from xpra.os_util import strtobytes @@ -14,7 +15,7 @@ } -def get_headers(host, port): +def get_headers(host:str, port:int) -> Dict[bytes,bytes]: #pylint: disable=unused-argument headers = HEADERS.copy() if host: headers[b"Host"] = strtobytes(f"{host}:{port}") diff --git a/xpra/net/websockets/headers/env_cookie.py b/xpra/net/websockets/headers/env_cookie.py index 25a6024b65..a665d9b85e 100644 --- a/xpra/net/websockets/headers/env_cookie.py +++ b/xpra/net/websockets/headers/env_cookie.py @@ -1,15 +1,16 @@ # This file is part of Xpra. -# Copyright (C) 2020 Antoine Martin +# Copyright (C) 2020-2023 Antoine Martin # Copyright (C) 2020 mjharkin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. import os +from typing import Dict from xpra.os_util import strtobytes -def get_headers(host, port): #pylint: disable=unused-argument +def get_headers(host:str, port:int) -> Dict[bytes,bytes]: #pylint: disable=unused-argument cookie = os.environ.get("XPRA_WS_COOKIE") if cookie: return { b"Cookie" : strtobytes(cookie) } diff --git a/xpra/net/websockets/protocol.py b/xpra/net/websockets/protocol.py index fbe49e52a6..e95e66547d 100644 --- a/xpra/net/websockets/protocol.py +++ b/xpra/net/websockets/protocol.py @@ -1,5 +1,5 @@ # This file is part of Xpra. -# Copyright (C) 2019-2022 Antoine Martin +# Copyright (C) 2019-2023 Antoine Martin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. @@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs): def __repr__(self): return f"WebSocket({self._conn})" - def close(self, message=None): + def close(self, message=None) -> None: if self._closed: return self.send_ws_close(reason=message) @@ -48,7 +48,7 @@ def close(self, message=None): self.ws_data = b"" self.ws_payload = [] - def send_ws_close(self, code:int=1000, reason:str="closing"): + def send_ws_close(self, code:int=1000, reason:str="closing") -> None: data = close_packet(code, reason) self.flush_then_close(None, data) @@ -66,7 +66,7 @@ def make_wsframe_header(self, packet_type, items) -> ByteString: return header+mask return header - def parse_ws_frame(self, buf:ByteString): + def parse_ws_frame(self, buf:ByteString) -> None: if not buf: self._read_queue_put(buf) return