Skip to content

Commit

Permalink
#3592 safe to remove net_utf8 since we require rencodeplus
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 26, 2023
1 parent 79fe18c commit 34821ba
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 102 deletions.
4 changes: 2 additions & 2 deletions xpra/client/base/gobject_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from gi.repository import GLib, GObject # @UnresolvedImport

from xpra.util import (
u, net_utf8, nonl, sorted_nicely, print_nested_dict, envint, flatten_dict, typedict,
u, nonl, sorted_nicely, print_nested_dict, envint, flatten_dict, typedict,
disconnect_is_an_error, ellipsizer, first_time, csv,
repr_ellipsized, ConnectionMessage, stderr_print,
)
Expand Down Expand Up @@ -577,7 +577,7 @@ def _process_shell_reply(self, packet : PacketType) -> None:
stream = sys.stderr
else:
raise ValueError(f"invalid file descriptor f{fd}")
s = net_utf8(message)
s = str(message)
if s.endswith("\n"):
s = s[:-1]
stream.write("%s" % s)
Expand Down
5 changes: 2 additions & 3 deletions xpra/client/gtk3/gtk_client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from xpra.os_util import bytestostr, strtobytes, is_X11, WIN32, OSX, POSIX
from xpra.util import (
typedict, envint, envbool, csv, first_time, net_utf8, MoveResize,
typedict, envint, envbool, csv, first_time, MoveResize,
WORKSPACE_UNSET, WORKSPACE_ALL, WORKSPACE_NAMES, MOVERESIZE_DIRECTION_STRING, SOURCE_INDICATION_STRING,
)
from xpra.gtk_common.gobject_util import no_arg_signal, one_arg_signal
Expand Down Expand Up @@ -1089,8 +1089,7 @@ def cancel_send_iconifiy_timer(self) -> None:


def set_command(self, command) -> None:
v = net_utf8(command)
self.set_x11_property("WM_COMMAND", "latin1", v)
self.set_x11_property("WM_COMMAND", "latin1", command)

def set_x11_property(self, prop_name:str, dtype=None, value=None) -> None:
if not HAS_X11_BINDINGS:
Expand Down
8 changes: 4 additions & 4 deletions xpra/client/gtk3/open_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from time import monotonic
import gi

from xpra.util import envint, net_utf8
from xpra.util import envint
from xpra.os_util import bytestostr, WIN32, OSX
from xpra.gtk_common.gobject_compat import register_os_signals
from xpra.child_reaper import getChildReaper
Expand Down Expand Up @@ -103,14 +103,14 @@ def btn(self, label, callback, icon_name=None):
return btn


def add_request(self, cb_answer, send_id, dtype, url, filesize, printit, openit, timeout):
def add_request(self, cb_answer, send_id:str, dtype:str, url:str, filesize:int, printit:bool, openit:bool, timeout:int):
expires = monotonic()+timeout
self.requests.append((cb_answer, net_utf8(send_id), net_utf8(dtype), net_utf8(url), filesize, printit, openit, expires))
self.requests.append((cb_answer, send_id, dtype, url, filesize, printit, openit, expires))
self.populate_table()
if not self.populate_timer:
self.schedule_timer()

def update_expires_label(self):
def update_expires_label(self) -> bool:
expired = 0
for label, expiry in self.expire_labels.values():
seconds = max(0, expiry-monotonic())
Expand Down
21 changes: 6 additions & 15 deletions xpra/client/gtk3/start_new_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
add_close_accel, scaled_image, get_icon_pixbuf,
)
from xpra.gtk_common.gobject_compat import register_os_signals
from xpra.util import typedict, net_utf8
from xpra.util import typedict
from xpra.log import Logger, enable_debug_for

log = Logger("exec")
Expand All @@ -28,21 +28,12 @@ def getStartNewCommand(run_callback, can_share=False, xdg_menu=None):
_instance = StartNewCommand(run_callback, can_share, xdg_menu)
return _instance

def udict(d):
#with rencode, we may get bytes instead of strings:
t = typedict()
for k, v in d.items():
if isinstance(k, bytes):
k = net_utf8(k)
t[k] = v
return t


class StartNewCommand:

def __init__(self, run_callback=None, can_share=False, xdg_menu=None):
self.run_callback = run_callback
self.xdg_menu = udict(xdg_menu or {})
self.xdg_menu = typedict(xdg_menu or {})
self.window = Gtk.Window()
self.window.set_border_width(20)
self.window.connect("delete-event", self.close)
Expand Down Expand Up @@ -123,7 +114,7 @@ def accel_close(*_args):

def category_changed(self, *args):
category = self.category_combo.get_active_text()
entries = udict(udict(self.xdg_menu.dictget(category, {})).dictget("Entries", {}))
entries = typedict(typedict(self.xdg_menu.dictget(category, {})).dictget("Entries", {}))
log("category_changed(%s) category=%s, entries=%s", args, category, entries)
self.command_combo.get_model().clear()
for name in entries.keys():
Expand All @@ -135,14 +126,14 @@ def command_changed(self, *args):
if not self.entry:
return
category = self.category_combo.get_active_text()
entries = udict(udict(self.xdg_menu.dictget(category, {})).dictget("Entries", {}))
entries = typedict(typedict(self.xdg_menu.dictget(category, {})).dictget("Entries", {}))
command_name = self.command_combo.get_active_text()
log("command_changed(%s) category=%s, entries=%s, command_name=%s", args, category, entries, command_name)
command = ""
if entries and command_name:
command_props = udict(udict(entries).dictget(command_name, {}))
command_props = typedict(typedict(entries).dictget(command_name, {}))
log("command properties=%s", command_props)
command = udict(command_props).strget("command", "")
command = typedict(command_props).strget("command", "")
self.entry.set_text(command)

def show(self):
Expand Down
6 changes: 3 additions & 3 deletions xpra/client/gui/client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from xpra.scaling_parser import scaleup_value, scaledown_value
from xpra.os_util import bytestostr, OSX, WIN32, is_Wayland
from xpra.common import GravityStr
from xpra.util import net_utf8, typedict, envbool, envint, std, WORKSPACE_UNSET, WORKSPACE_NAMES
from xpra.util import typedict, envbool, envint, std, WORKSPACE_UNSET, WORKSPACE_NAMES
from xpra.log import Logger

log = Logger("window")
Expand Down Expand Up @@ -356,7 +356,7 @@ def getvar(var):
value = metadata.get(var) or self._metadata.get(var)
if value is None:
return default_values.get(var, "<unknown %s>" % var)
return net_utf8(value)
return str(value)
def metadata_replace(match):
atvar = match.group(0) #ie: '@title@'
var = atvar[1:len(atvar)-1] #ie: 'title'
Expand Down Expand Up @@ -390,7 +390,7 @@ def set_metadata(self, metadata:typedict):

if "icon-title" in metadata:
icon_title = metadata.strget("icon-title", "")
self.set_icon_name(net_utf8(icon_title))
self.set_icon_name(icon_title)
#the DE may have reset the icon now,
#force it to use the one we really want:
self.reset_icon()
Expand Down
8 changes: 4 additions & 4 deletions xpra/client/mixins/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from xpra.platform.paths import get_icon_filename
from xpra.platform.gui import get_native_notifier_classes
from xpra.net.common import PacketType
from xpra.util import envbool, repr_ellipsized, make_instance, updict, typedict, net_utf8
from xpra.util import envbool, repr_ellipsized, make_instance, updict, typedict
from xpra.client.base.stub_client_mixin import StubClientMixin
from xpra.log import Logger

Expand Down Expand Up @@ -157,11 +157,11 @@ def _process_notify_show(self, packet : PacketType):
self._ui_event()
dbus_id = packet[1]
nid = int(packet[2])
app_name = net_utf8(packet[3])
app_name = str(packet[3])
replaces_nid = int(packet[4])
app_icon = packet[5]
summary = net_utf8(packet[6])
body = net_utf8(packet[7])
summary = str(packet[6])
body = str(packet[7])
expire_timeout = int(packet[8])
icon = None
actions, hints = [], {}
Expand Down
6 changes: 3 additions & 3 deletions xpra/client/mixins/remote_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from time import monotonic
from threading import Lock

from xpra.util import csv, typedict, repr_ellipsized, net_utf8
from xpra.util import csv, typedict, repr_ellipsized
from xpra.client.base.stub_client_mixin import StubClientMixin
from xpra.log import Logger, set_global_logging_handler
from xpra.net.common import PacketType
Expand Down Expand Up @@ -93,9 +93,9 @@ def _process_logging(self, packet : PacketType) -> None:
prefix += "@%02i.%03i " % ((dtime//1000)%60, dtime%1000)
try:
if isinstance(msg, (tuple, list)):
dmsg = " ".join(net_utf8(x) for x in msg)
dmsg = " ".join(str(x) for x in msg)
else:
dmsg = net_utf8(msg)
dmsg = str(msg)
for l in dmsg.splitlines():
self.do_log(level, prefix+l)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion xpra/clipboard/clipboard_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def _may_compress(self, dtype:str, dformat:int, wire_data):
if isinstance(wire_data, (str, bytes)) and l>=MIN_CLIPBOARD_COMPRESS_SIZE:
if isinstance(wire_data, str):
#compression requires bytes:
#but this would require the receiving end to use net_utf8()
#but this would require the receiving end to know it needs to decode the bytes
wire_data = wire_data.encode("utf8")
log("encoded %i characters to %i utf8 bytes", l, len(wire_data))
return Compressible(f"clipboard: {dtype} / {dformat}", wire_data)
Expand Down
4 changes: 2 additions & 2 deletions xpra/gtk_common/gtk_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ClipboardProxyCore, TEXT_TARGETS,
)
from xpra.clipboard.clipboard_timeout_helper import ClipboardTimeoutHelper
from xpra.util import ellipsizer, envint, net_utf8
from xpra.util import ellipsizer, envint
from xpra.log import Logger


Expand Down Expand Up @@ -78,7 +78,7 @@ def got_token(self, targets, target_data=None, claim=True, synchronous_client=Fa
dtype, dformat, data = target_data.get(text_target)
if dformat!=8:
continue
text = net_utf8(data)
text = str(data)
log("setting text data %s / %s of size %i: %s",
dtype, dformat, len(text), ellipsizer(text))
self._owner_change_embargo = monotonic()
Expand Down
24 changes: 8 additions & 16 deletions xpra/net/file_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from xpra.child_reaper import getChildReaper
from xpra.os_util import bytestostr, strtobytes, umask_context, POSIX, WIN32
from xpra.util import typedict, csv, envint, envbool, engs, net_utf8, u
from xpra.util import typedict, csv, envint, envbool, engs, u
from xpra.scripts.config import parse_bool, parse_with_unit
from xpra.net.common import PacketType
from xpra.simple_stats import std_unit
Expand Down Expand Up @@ -369,7 +369,6 @@ def clean_receive_state():

def _process_send_file_chunk(self, packet : PacketType) -> None:
chunk_id, chunk, file_data, has_more = packet[1:5]
chunk_id = net_utf8(chunk_id)
#if len(file_data)<1024:
# from xpra.os_util import hexstr
# filelog.warn("file_data=%s", hexstr(file_data))
Expand Down Expand Up @@ -484,10 +483,7 @@ def _process_send_file(self, packet : PacketType) -> None:
basefilename, mimetype, printit, openit, filesize, file_data, options = packet[1:8]
send_id = ""
if len(packet)>=9:
send_id = net_utf8(packet[8])
#basefilename should be utf8:
basefilename = net_utf8(basefilename)
mimetype = net_utf8(mimetype)
send_id = str(packet[8])
if filesize<=0:
filelog.error("Error: invalid file size: %s", filesize)
filelog.error(" file transfer aborted for %r", basefilename)
Expand Down Expand Up @@ -728,8 +724,8 @@ def send_request_file(self, filename:str, openit:bool=True):


def _process_open_url(self, packet : PacketType):
send_id = net_utf8(packet[2])
url = net_utf8(packet[1])
send_id = str(packet[2])
url = str(packet[1])
if not self.open_url:
filelog.warn("Warning: received a request to open URL '%s'", url)
filelog.warn(" but opening of URLs is disabled")
Expand Down Expand Up @@ -820,9 +816,6 @@ def _process_send_data_request(self, packet : PacketType) -> None:
if len(packet)>=9:
options = packet[8]
#filenames and url are always sent encoded as utf8:
url = net_utf8(url)
dtype = net_utf8(dtype)
send_id = net_utf8(send_id)
self.do_process_send_data_request(dtype, send_id, url, _, filesize, printit, openit, typedict(options))


Expand Down Expand Up @@ -880,7 +873,6 @@ def ask_data_request(self, cb_answer:Callable, send_id:str, dtype:str, url:str,

def _process_send_data_response(self, packet : PacketType) -> None:
send_id, accept = packet[1:3]
send_id = net_utf8(send_id)
filelog("process send-data-response: send_id=%s, accept=%s", send_id, accept)
timer = self.pending_send_data_timers.pop(send_id, None)
if timer:
Expand All @@ -889,8 +881,8 @@ def _process_send_data_response(self, packet : PacketType) -> None:
if v is None:
filelog.warn("Warning: cannot find send-file entry")
return
dtype = net_utf8(v[0])
url = net_utf8(v[1])
dtype = str(v[0])
url = str(v[1])
if accept==DENY:
filelog.info("the request to send %s '%s' has been denied", dtype, url)
return
Expand Down Expand Up @@ -994,10 +986,10 @@ def _process_ack_file_chunk(self, packet : PacketType) -> None:
#send some more file data
filelog("ack-file-chunk: %s", packet[1:])
chunk_id, state, error_message, chunk = packet[1:5]
chunk_id = net_utf8(chunk_id)
chunk_id = str(chunk_id)
if not state:
filelog.info("the remote end is cancelling the file transfer:")
filelog.info(" %s", net_utf8(error_message))
filelog.info(" %s", error_message)
self.cancel_sending(chunk_id)
return
chunk_state = self.send_chunks_in_progress.get(chunk_id)
Expand Down
4 changes: 2 additions & 2 deletions xpra/platform/darwin/osx_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
_filter_targets, ClipboardProxyCore, TEXT_TARGETS,
)
from xpra.platform.ui_thread_watcher import get_UI_watcher
from xpra.util import csv, net_utf8, ellipsizer
from xpra.util import csv, ellipsizer
from xpra.os_util import bytestostr
from xpra.log import Logger

Expand Down Expand Up @@ -188,7 +188,7 @@ def got_contents(self, target, dtype=None, dformat=None, data=None):
return
if dformat==8 and dtype in TEXT_TARGETS:
log("we got a byte string: %s", ellipsizer(data))
self.set_clipboard_text(net_utf8(data))
self.set_clipboard_text(bytestostr(data))
if dformat==8 and dtype in IMAGE_FORMATS:
log("we got a %s image", dtype)
self.set_image_data(dtype, data)
Expand Down
5 changes: 2 additions & 3 deletions xpra/platform/posix/remotedesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from gi.repository import Gdk
from dbus.types import UInt32, Int32

from xpra.util import net_utf8
from xpra.dbus.helper import native_to_dbus
from xpra.net.common import PacketType
from xpra.platform.posix.fd_portal import REMOTEDESKTOP_IFACE
Expand Down Expand Up @@ -78,10 +77,10 @@ def do_process_button_action(self, proto, device_id:int, wid:int, button:int, pr
def _process_key_action(self, proto, packet : PacketType) -> None:
if self.readonly or not self.input_devices or not self.keymap:
return
keyname = net_utf8(packet[2])
keyname = str(packet[2])
pressed = bool(packet[3])
keyval = int(packet[5])
keystr = net_utf8(packet[6])
keystr = str(packet[6])
ss = self.get_server_source(proto)
if ss is None:
return
Expand Down
4 changes: 2 additions & 2 deletions xpra/platform/win32/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
ClipboardProxyCore, log, _filter_targets,
TEXT_TARGETS, MAX_CLIPBOARD_PACKET_SIZE,
)
from xpra.util import net_utf8, csv, ellipsizer, envint, envbool, roundup
from xpra.util import csv, ellipsizer, envint, envbool, roundup
from xpra.os_util import bytestostr
from xpra.platform.win32.constants import PROCESS_QUERY_INFORMATION

Expand Down Expand Up @@ -570,7 +570,7 @@ def got_contents(self, target, dtype=None, dformat=None, data=None):
self.send_clipboard_request_handler(self, self._selection, image_formats[0])
elif dformat==8 and dtype in TEXT_TARGETS:
log("we got a byte string: %s", ellipsizer(data))
self.set_clipboard_text(net_utf8(data))
self.set_clipboard_text(bytestostr(data))
elif dformat==8 and dtype.startswith("image/"):
img_format = dtype.split("/")[-1] #ie: 'png'
self.set_clipboard_image(img_format, data)
Expand Down
3 changes: 1 addition & 2 deletions xpra/server/mixins/controlcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from time import monotonic
from typing import List

from xpra.util import parse_scaling_value, csv, from0to100, net_utf8, typedict, ConnectionMessage
from xpra.util import parse_scaling_value, csv, from0to100, typedict, ConnectionMessage
from xpra.os_util import load_binary_file
from xpra.net.common import PacketType
from xpra.simple_stats import std_unit
Expand Down Expand Up @@ -319,7 +319,6 @@ def control_command_send_file(self, filename:str, openit:str="open", client_uuid
#we always get the values as strings from the command interface,
#but those may actually be utf8 encoded binary strings,
#so we may have to do an ugly roundtrip:
filename = net_utf8(filename)
openit = str(openit).lower() in ("open", "true", "1")
return self.do_control_file_command("send file", client_uuids, filename, "file_transfer", (False, openit))

Expand Down
8 changes: 4 additions & 4 deletions xpra/server/mixins/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import List, Dict, Any, Optional

from xpra.os_util import bytestostr
from xpra.util import typedict, net_utf8, envbool
from xpra.util import typedict, envbool
from xpra.net.common import PacketType
from xpra.server.mixins.stub_server_mixin import StubServerMixin
from xpra.log import Logger
Expand Down Expand Up @@ -171,9 +171,9 @@ def _process_key_action(self, proto, packet : PacketType) -> None:
ss = self.get_server_source(proto)
if ss is None:
return
keyname = net_utf8(keyname)
keystr = net_utf8(keystr)
modifiers = list(net_utf8(x) for x in modifiers)
keyname = str(keyname)
keystr = str(keystr)
modifiers = list(str(x) for x in modifiers)
self.set_ui_driver(ss)
keycode, group = self.get_keycode(ss, client_keycode, keyname, pressed, modifiers, keyval, keystr, group)
keylog("process_key_action(%s) server keycode=%s, group=%i", packet, keycode, group)
Expand Down
Loading

0 comments on commit 34821ba

Please sign in to comment.