Skip to content

Commit

Permalink
fix more pylint warnings
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@21845 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 23, 2019
1 parent ae82ebc commit 3c991f6
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 85 deletions.
15 changes: 7 additions & 8 deletions src/xpra/client/mixins/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,8 @@ def parse_server_capabilities(self):
avsynclog("av-sync: server=%s, client=%s", self.server_av_sync, self.av_sync)
self.server_pulseaudio_id = c.strget("sound.pulseaudio.id")
self.server_pulseaudio_server = c.strget("sound.pulseaudio.server")
try:
self.server_sound_decoders = c.strlistget("sound.decoders", [])
self.server_sound_encoders = c.strlistget("sound.encoders", [])
except:
log("Error: cannot parse server sound codec data", exc_info=True)
self.server_sound_decoders = c.strlistget("sound.decoders", ())
self.server_sound_encoders = c.strlistget("sound.encoders", ())
self.server_sound_receive = c.boolget("sound.receive")
self.server_sound_send = c.boolget("sound.send")
self.server_sound_bundle_metadata = c.boolget("sound.bundle-metadata")
Expand Down Expand Up @@ -207,7 +204,7 @@ def init_audio_tagging(self, tray_icon):


def get_matching_codecs(self, local_codecs, server_codecs):
matching_codecs = [x for x in local_codecs if x in server_codecs]
matching_codecs = tuple(x for x in local_codecs if x in server_codecs)
log("get_matching_codecs(%s, %s)=%s", local_codecs, server_codecs, matching_codecs)
return matching_codecs

Expand Down Expand Up @@ -289,7 +286,9 @@ def sound_source_state_changed(*_args):
try:
from xpra.sound.wrapper import start_sending_sound
plugins = self.sound_properties.get("plugins")
ss = start_sending_sound(plugins, self.sound_source_plugin, device or self.microphone_device, None, 1.0, False, matching_codecs, self.server_pulseaudio_server, self.server_pulseaudio_id)
ss = start_sending_sound(plugins, self.sound_source_plugin, device or self.microphone_device,
None, 1.0, False, matching_codecs,
self.server_pulseaudio_server, self.server_pulseaudio_id)
if not ss:
return False
self.sound_source = ss
Expand Down Expand Up @@ -483,7 +482,7 @@ def new_sound_buffer(self, sound_source, data, metadata, packet_metadata=()):
packet_metadata = Compressed("packet metadata", packet_metadata, can_inline=True)
self.send_sound_data(sound_source, data, metadata, packet_metadata)

def send_sound_data(self, sound_source, data, metadata={}, packet_metadata=()):
def send_sound_data(self, sound_source, data, metadata={}, packet_metadata=None):
codec = sound_source.codec
packet_data = [codec, Compressed(codec, data), metadata]
if packet_metadata:
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/client/mixins/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def cleanup(self):
self.clipboard_helper = None
try:
ch.cleanup()
except:
except Exception:
log.error("error on clipboard helper '%s' cleanup", ch, exc_info=True)


Expand Down Expand Up @@ -159,7 +159,7 @@ def make_clipboard_helper(self):
log.error("Error: cannot instantiate %s:", helperclass)
log.error(" %s", e)
del e
except:
except Exception:
log.error("Error: cannot instantiate %s", helperclass, exc_info=True)
return None

Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def set_max_packet_size(self):
server_w, server_h = self.server_actual_desktop_size
maxw = max(root_w, server_w)
maxh = max(root_h, server_h)
except:
except ValueError:
pass
if maxw<=0 or maxh<=0 or maxw>=32768 or maxh>=32768:
message = "invalid maximum desktop size: %ix%i" % (maxw, maxh)
Expand Down
21 changes: 12 additions & 9 deletions src/xpra/client/mixins/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def init(self, opts, _extra_args=[]):
def cleanup(self):
try:
getVideoHelper().cleanup()
except:
except Exception:
log.error("error on video cleanup", exc_info=True)


Expand All @@ -96,8 +96,10 @@ def parse_server_capabilities(self):
c = self.server_capabilities
self.server_encodings = c.strlistget("encodings")
self.server_core_encodings = c.strlistget("encodings.core", self.server_encodings)
self.server_encodings_problematic = c.strlistget("encodings.problematic", PROBLEMATIC_ENCODINGS) #server is telling us to try to avoid those
self.server_encodings_with_speed = c.strlistget("encodings.with_speed", ("h264",)) #old servers only supported x264
#server is telling us to try to avoid those:
self.server_encodings_problematic = c.strlistget("encodings.problematic", PROBLEMATIC_ENCODINGS)
#old servers only supported x264:
self.server_encodings_with_speed = c.strlistget("encodings.with_speed", ("h264",))
self.server_encodings_with_quality = c.strlistget("encodings.with_quality", ("jpeg", "webp", "h264"))
self.server_encodings_with_lossless_mode = c.strlistget("encodings.with_lossless_mode", ())
self.server_auto_video_encoding = c.boolget("auto-video-encoding")
Expand All @@ -120,7 +122,7 @@ def get_batch_caps(self):
if evalue:
try:
caps["batch.%s" % bprop] = int(evalue)
except:
except ValueError:
log.error("Error: invalid environment value for %s: %s", bprop, evalue)
log("get_batch_caps()=%s", caps)
return caps
Expand Down Expand Up @@ -254,7 +256,8 @@ def do_get_core_encodings(self):
if encoding not in core_encodings:
core_encodings.append(encoding)
#remove duplicates and use prefered encoding order:
core_encodings = [x for x in PREFERED_ENCODING_ORDER if x in set(core_encodings) and x in self.allowed_encodings]
core_encodings = [x for x in PREFERED_ENCODING_ORDER
if x in set(core_encodings) and x in self.allowed_encodings]
return core_encodings

def set_encoding(self, encoding):
Expand All @@ -271,23 +274,23 @@ def set_encoding(self, encoding):
def send_quality(self):
q = self.quality
log("send_quality() quality=%s", q)
assert q==-1 or (q>=0 and q<=100), "invalid quality: %s" % q
assert q==-1 or 0<=q<=100, "invalid quality: %s" % q
self.send("quality", q)

def send_min_quality(self):
q = self.min_quality
log("send_min_quality() min-quality=%s", q)
assert q==-1 or (q>=0 and q<=100), "invalid min-quality: %s" % q
assert q==-1 or 0<=q<=100, "invalid min-quality: %s" % q
self.send("min-quality", q)

def send_speed(self):
s = self.speed
log("send_speed() min-speed=%s", s)
assert s==-1 or (s>=0 and s<=100), "invalid speed: %s" % s
assert s==-1 or 0<=s<=100, "invalid speed: %s" % s
self.send("speed", s)

def send_min_speed(self):
s = self.min_speed
log("send_min_speed() min-speed=%s", s)
assert s==-1 or (s>=0 and s<=100), "invalid min-speed: %s" % s
assert s==-1 or 0<=s<=100, "invalid min-speed: %s" % s
self.send("min-speed", s)
14 changes: 8 additions & 6 deletions src/xpra/client/mixins/fileprint_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def parse_printing_capabilities(self):
server_printing = self.server_capabilities.boolget("printing")
printlog("parse_printing_capabilities() server printing support=%s", server_printing)
if server_printing:
self.printer_attributes = self.server_capabilities.strlistget("printer.attributes", ["printer-info", "device-uri"])
self.printer_attributes = self.server_capabilities.strlistget("printer.attributes",
["printer-info", "device-uri"])
self.timeout_add(1000, self.init_printing)


Expand Down Expand Up @@ -156,18 +157,19 @@ def used_attrs(d):
printlog("do_send_printers() exported printers unchanged: %s", self.exported_printers)
return
#show summary of what has changed:
added = [k for k in exported_printers.keys() if k not in self.exported_printers]
added = tuple(k for k in exported_printers if k not in self.exported_printers)
if added:
printlog("do_send_printers() new printers: %s", added)
removed = [k for k in self.exported_printers.keys() if k not in exported_printers]
removed = tuple(k for k in self.exported_printers if k not in exported_printers)
if removed:
printlog("do_send_printers() printers removed: %s", removed)
modified = [k for k,v in exported_printers.items() if self.exported_printers.get(k)!=v and k not in added]
modified = (k for k,v in exported_printers.items() if
self.exported_printers.get(k)!=v and k not in added)
if modified:
printlog("do_send_printers() printers modified: %s", modified)
printlog("do_send_printers() printers=%s", exported_printers.keys())
printlog("do_send_printers() exported printers=%s", csv(str(x) for x in exported_printers.keys()))
printlog("do_send_printers() exported printers=%s", csv(str(x) for x in exported_printers))
self.exported_printers = exported_printers
self.send("printers", self.exported_printers)
except:
except Exception:
printlog.error("do_send_printers()", exc_info=True)
22 changes: 13 additions & 9 deletions src/xpra/client/mixins/network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def parse_server_capabilities(self):
self.server_start_time = min(time.time(), c.intget("start_time", -1))
self.server_bandwidth_limit_change = c.boolget("network.bandwidth-limit-change")
self.server_bandwidth_limit = c.intget("network.bandwidth-limit")
bandwidthlog("server_bandwidth_limit_change=%s, server_bandwidth_limit=%s", self.server_bandwidth_limit_change, self.server_bandwidth_limit)
bandwidthlog("server_bandwidth_limit_change=%s, server_bandwidth_limit=%s",
self.server_bandwidth_limit_change, self.server_bandwidth_limit)
return True

def process_ui_capabilities(self):
Expand Down Expand Up @@ -183,7 +184,8 @@ def check_server_echo(self, ping_sent_time):
self.ping_echo_timeout_timer = self.timeout_add(PING_TIMEOUT*1000, self.check_echo_timeout, ping_sent_time)
else:
self.cancel_ping_echo_timeout_timer()
log("check_server_echo(%s) last=%s, server_ok=%s (last_ping_echoed_time=%s)", ping_sent_time, last, self._server_ok, self.last_ping_echoed_time)
log("check_server_echo(%s) last=%s, server_ok=%s (last_ping_echoed_time=%s)",
ping_sent_time, last, self._server_ok, self.last_ping_echoed_time)
if last!=self._server_ok:
self.server_connection_state_change()
return False
Expand All @@ -208,11 +210,12 @@ def send_ping(self):
now_ms = int(1000.0*monotonic_time())
self.send("ping", now_ms)
wait = 2.0
if len(self.server_ping_latency)>0:
l = [x for _,x in tuple(self.server_ping_latency)]
avg = sum(l) / len(l)
spl = tuple(x for _,x in self.server_ping_latency)
if spl:
avg = sum(spl) / len(spl)
wait = min(5, 1.0+avg*2.0)
log("send_ping() timestamp=%s, average server latency=%.1f, using max wait %.2fs", now_ms, 1000.0*avg, wait)
log("send_ping() timestamp=%s, average server latency=%.1f, using max wait %.2fs",
now_ms, 1000.0*avg, wait)
t = self.timeout_add(int(1000.0*wait), self.check_server_echo, now_ms)
self.ping_echo_timers[now_ms] = t
return True
Expand All @@ -237,9 +240,10 @@ def _process_ping(self, packet):
l1,l2,l3 = int(fl1*1000), int(fl2*1000), int(fl3*1000)
except (OSError, AttributeError):
pass
sl = -1
if len(self.server_ping_latency)>0:
_, sl = self.server_ping_latency[-1]
try:
sl = self.server_ping_latency[-1][1]
except IndexError:
sl = -1
self.send("ping_echo", echotime, l1, l2, l3, int(1000.0*sl))


Expand Down
26 changes: 16 additions & 10 deletions src/xpra/client/mixins/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from xpra.platform.paths import get_icon_filename
from xpra.platform.gui import get_native_notifier_classes
from xpra.os_util import bytestostr
from xpra.os_util import bytestostr, strtobytes
from xpra.util import envbool, repr_ellipsized, make_instance, updict
from xpra.client.mixins.stub_client_mixin import StubClientMixin
from xpra.log import Logger
Expand Down Expand Up @@ -53,7 +53,7 @@ def cleanup(self):
self.notifier = None
try:
n.cleanup()
except:
except Exception:
log.error("Error on notifier cleanup", exc_info=True)


Expand Down Expand Up @@ -85,7 +85,8 @@ def make_notifier(self):
return make_instance(nc, self.notification_closed, self.notification_action)

def notification_closed(self, nid, reason=3, text=""):
log("notification_closed(%i, %i, %s) server notification.close=%s", nid, reason, text, self.server_notifications_close)
log("notification_closed(%i, %i, %s) server notification.close=%s",
nid, reason, text, self.server_notifications_close)
if self.server_notifications_close:
self.send("notification-close", nid, reason, text)

Expand All @@ -102,7 +103,9 @@ def get_notifier_classes(self):
return get_native_notifier_classes()

def do_notify(self, nid, summary, body, actions=[], hints={}, expire_timeout=10*1000, icon_name=None):
log("do_notify%s client_supports_notifications=%s, notifier=%s", (nid, summary, body, actions, hints, expire_timeout, icon_name), self.client_supports_notifications, self.notifier)
log("do_notify%s client_supports_notifications=%s, notifier=%s",
(nid, summary, body, actions, hints, expire_timeout, icon_name),
self.client_supports_notifications, self.notifier)
n = self.notifier
if not self.client_supports_notifications or not n:
#just log it instead:
Expand Down Expand Up @@ -135,22 +138,25 @@ def _process_notify_show(self, packet):
actions, hints = packet[10], packet[11]
#note: if the server doesn't support notification forwarding,
#it can still send us the messages (via xpra control or the dbus interface)
log("_process_notify_show(%s) notifier=%s, server_notifications=%s", repr_ellipsized(str(packet)), self.notifier, self.server_notifications)
log("_process_notify_show(%s) notifier=%s, server_notifications=%s",
repr_ellipsized(str(packet)), self.notifier, self.server_notifications)
log("notification actions=%s, hints=%s", actions, hints)
assert self.notifier
#this one of the few places where we actually do care about character encoding:
try:
summary = summary.decode("utf8")
except:
summary = strtobytes(summary).decode("utf8")
except UnicodeDecodeError:
summary = bytestostr(summary)
try:
body = body.decode("utf8")
except:
body = strtobytes(body).decode("utf8")
except UnicodeDecodeError:
body = bytestostr(body)
app_name = bytestostr(app_name)
tray = self.get_tray_window(app_name, hints)
log("get_tray_window(%s)=%s", app_name, tray)
self.notifier.show_notify(dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon)
self.notifier.show_notify(dbus_id, tray, nid,
app_name, replaces_nid, app_icon,
summary, body, actions, hints, expire_timeout, icon)

def _process_notify_close(self, packet):
if not self.notifications_enabled:
Expand Down
10 changes: 5 additions & 5 deletions src/xpra/client/mixins/remote_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from xpra.scripts.config import parse_bool
from xpra.util import csv
from xpra.os_util import monotonic_time, strtobytes
from xpra.os_util import monotonic_time, strtobytes, bytestostr
from xpra.client.mixins.stub_client_mixin import StubClientMixin
from xpra.log import Logger, set_global_logging_handler

Expand Down Expand Up @@ -64,8 +64,8 @@ def remote_logging_handler(self, log, level, msg, *args, **kwargs):
self.in_remote_logging = True
def enc(x):
try:
return x.encode("utf8")
except:
return bytestostr(x).encode("utf8")
except UnicodeEncodeError:
return strtobytes(x)
try:
dtime = int(1000*(monotonic_time() - self.monotonic_start_time))
Expand All @@ -79,7 +79,7 @@ def enc(x):
self.send("logging", level, enc(x), dtime)
try:
etypeinfo = exc_info[0].__name__
except:
except AttributeError:
etypeinfo = str(exc_info[0])
self.send("logging", level, enc("%s: %s" % (etypeinfo, exc_info[1])), dtime)
if self.log_both:
Expand All @@ -93,7 +93,7 @@ def enc(x):
self.local_logging(log, logging.WARNING, " original unformatted message: %s", msg)
try:
self.local_logging(log, level, msg, *args, **kwargs)
except:
except Exception:
pass
try:
exc_info = sys.exc_info()
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/stub_client_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
Options are usually obtained by parsing the command line,
or using a default configuration object.
"""
def init(self, _opts, _extra_args=[]):
def init(self, _opts, _extra_args=()):
pass

"""
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/client/mixins/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def cleanup(self):
self.tray = None
try:
t.cleanup()
except:
except Exception:
log.error("error on tray cleanup", exc_info=True)


Expand Down Expand Up @@ -108,7 +108,8 @@ def xpra_tray_geometry(*args):
menu = None
if self.menu_helper:
menu = self.menu_helper.build()
tray = self.make_tray(XPRA_APP_ID, menu, self.get_tray_title(), tray_icon_filename, xpra_tray_geometry, xpra_tray_click, xpra_tray_mouseover, xpra_tray_exit)
tray = self.make_tray(XPRA_APP_ID, menu, self.get_tray_title(), tray_icon_filename,
xpra_tray_geometry, xpra_tray_click, xpra_tray_mouseover, xpra_tray_exit)
log("setup_xpra_tray(%s)=%s", tray_icon_filename, tray)
if tray:
def reset_tray_title():
Expand Down

0 comments on commit 3c991f6

Please sign in to comment.