Skip to content

Commit

Permalink
more pylint warning fixes
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@21700 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 19, 2019
1 parent 5bc0ec8 commit f08b7d2
Show file tree
Hide file tree
Showing 32 changed files with 311 additions and 202 deletions.
7 changes: 3 additions & 4 deletions src/xpra/client/gl/window_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ def get_opengl_backends(option_str):
backend_str = option_str
if backend_str in ("native", "gtk") or backend_str.find(",")>0:
return backend_str.split(",")
elif PYTHON3:
return "native",
else:
return "native", "gtk"
if PYTHON3:
return ("native", )
return ("native", "gtk")

def get_gl_client_window_module(backends, force_enable=False):
gl_client_window_module = None
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/client/gtk_base/client_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def do_create_window(self):
self.bug_tool = None
if icon_pixbuf:
def bug(*_args):
if self.bug_tool==None:
if self.bug_tool is None:
from xpra.client.gtk_base.bug_report import BugReport
self.bug_tool = BugReport()
self.bug_tool.init(show_about=False)
Expand All @@ -225,7 +225,7 @@ def bug(*_args):
self.mdns_gui = None
if icon_pixbuf and has_mdns():
def mdns(*_args):
if self.mdns_gui==None:
if self.mdns_gui is None:
from xpra.client.gtk_base.mdns_gui import mdns_sessions
self.mdns_gui = mdns_sessions(self.config)
def close_mdns():
Expand Down Expand Up @@ -902,7 +902,7 @@ def handle_client_quit(exit_launcher=False):

def warn_and_quit_override(exit_code, warning):
log("warn_and_quit_override(%s, %s)", exit_code, warning)
if self.exit_code == None:
if self.exit_code is None:
self.exit_code = exit_code
password_warning = warning.find("invalid password")>=0
if password_warning:
Expand All @@ -916,7 +916,7 @@ def warn_and_quit_override(exit_code, warning):

def quit_override(exit_code):
log("quit_override(%s)", exit_code)
if self.exit_code == None:
if self.exit_code is None:
self.exit_code = exit_code
handle_client_quit(self.exit_code==0)

Expand Down
18 changes: 12 additions & 6 deletions src/xpra/clipboard/clipboard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
import re

from xpra.gtk_common.gobject_util import no_arg_signal, SIGNAL_RUN_LAST
from xpra.gtk_common.gtk_util import GetClipboard, selection_owner_set, selection_add_target, selectiondata_get_selection, selectiondata_get_target, selectiondata_get_data, selectiondata_get_data_type, selectiondata_get_format, selectiondata_set, clipboard_request_contents, set_clipboard_data, PROPERTY_CHANGE_MASK
from xpra.gtk_common.gtk_util import (
GetClipboard, PROPERTY_CHANGE_MASK,
selection_owner_set, selection_add_target, selectiondata_get_selection,
selectiondata_get_target, selectiondata_get_data,
selectiondata_get_data_type, selectiondata_get_format,
selectiondata_set, clipboard_request_contents,
set_clipboard_data,
)
from xpra.gtk_common.nested_main import NestedMainLoop
from xpra.net.compression import Compressible
from xpra.os_util import WIN32, POSIX, monotonic_time, strtobytes, bytestostr, hexstr, get_hex_uuid, is_X11, is_Wayland
from xpra.util import csv, envint, envbool, repr_ellipsized, typedict, first_time
from xpra.platform.features import CLIPBOARD_GREEDY
from xpra.platform.features import CLIPBOARD_GREEDY, CLIPBOARDS as PLATFORM_CLIPBOARDS
from xpra.gtk_common.gobject_compat import import_gobject, import_gtk, import_gdk, import_glib, is_gtk3
from xpra.log import Logger

Expand All @@ -30,7 +37,6 @@
MAX_CLIPBOARD_RECEIVE_SIZE = envint("XPRA_MAX_CLIPBOARD_RECEIVE_SIZE", -1)
MAX_CLIPBOARD_SEND_SIZE = envint("XPRA_MAX_CLIPBOARD_SEND_SIZE", -1)

from xpra.platform.features import CLIPBOARDS as PLATFORM_CLIPBOARDS
ALL_CLIPBOARDS = [strtobytes(x) for x in PLATFORM_CLIPBOARDS]
CLIPBOARDS = PLATFORM_CLIPBOARDS
CLIPBOARDS_ENV = os.environ.get("XPRA_CLIPBOARDS")
Expand Down Expand Up @@ -385,7 +391,7 @@ def got_targets(dtype, dformat, targets):
send_now = [x for x in targets if x in TEXT_TARGETS]
def send_targets_only():
send_token(rsel, targets)
if len(send_now)==0:
if not send_now:
send_targets_only()
return
target = send_now[0]
Expand Down Expand Up @@ -546,7 +552,7 @@ def _may_compress(self, dtype, dformat, wire_data):
log.warn("Warning: clipboard contents are too big and have not been sent")
log.warn(" %s compressed bytes dropped (maximum is %s)", len(wire_data), self.max_clipboard_packet_size)
return None
if type(wire_data)==str and len(wire_data)>=MIN_CLIPBOARD_COMPRESSION_SIZE:
if isinstance(wire_data, str) and len(wire_data)>=MIN_CLIPBOARD_COMPRESSION_SIZE:
return Compressible("clipboard: %s / %s" % (dtype, dformat), wire_data)
return wire_data

Expand Down Expand Up @@ -853,7 +859,7 @@ def do_selection_clear_event(self, event):
if self._enabled and not self._block_owner_change:
#if greedy_client is set, do_owner_changed will fire the token
#so don't bother sending it now (same if we don't have it)
send = (self._greedy_client and not self._block_owner_change) or self._have_token
send = self._have_token or (self._greedy_client and not self._block_owner_change)
self._have_token = False

# Emit a signal -> send a note to the other side saying "hey its
Expand Down
6 changes: 4 additions & 2 deletions src/xpra/clipboard/gdk_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def _do_munge_raw_selection_to_wire(self, target, datatype, dataformat, data):
# not actual X atoms, but an array of GdkAtom's reinterpreted
# as a byte buffer.
atoms = gdk_atoms.gdk_atom_objects_from_gdk_atom_array(data)
log("_do_munge_raw_selection_to_wire(%s, %s, %s, %s:%s) atoms=%s", target, datatype, dataformat, type(data), len(data), tuple(atoms))
log("_do_munge_raw_selection_to_wire(%s, %s, %s, %s:%s) atoms=%s",
target, datatype, dataformat, type(data), len(data), tuple(atoms))
atom_names = [str(atom) for atom in atoms]
if target==b"TARGETS":
atom_names = _filter_targets(atom_names)
Expand All @@ -58,6 +59,7 @@ def _munge_wire_selection_to_raw(self, encoding, datatype, dataformat, data):
if encoding==b"atoms" and gdk_atoms:
atom_array = gdk_atoms.gdk_atom_array_from_atoms(data)
bdata = struct.pack(b"@" + b"L" * len(atom_array), *atom_array)
log("_munge_wire_selection_to_raw(%s, %s, %s, %s:%s)=%s=%s=%s", encoding, datatype, dataformat, type(data), len(data or ""), data, atom_array, tuple(bdata))
log("_munge_wire_selection_to_raw(%s, %s, %s, %s:%s)=%s=%s=%s",
encoding, datatype, dataformat, type(data), len(data or ""), data, atom_array, tuple(bdata))
return bdata
return ClipboardProtocolHelperBase._munge_wire_selection_to_raw(self, encoding, datatype, dataformat, data)
6 changes: 4 additions & 2 deletions src/xpra/clipboard/translated_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def __repr__(self):


def local_to_remote(self, selection):
log("local_to_remote(%s) local_clipboard=%s, remote_clipboard=%s", selection, self.local_clipboard, self.remote_clipboard)
log("local_to_remote(%s) local_clipboard=%s, remote_clipboard=%s",
selection, self.local_clipboard, self.remote_clipboard)
if selection==self.local_clipboard:
return self.remote_clipboard
return selection

def remote_to_local(self, selection):
log("remote_to_local(%s) local_clipboard=%s, remote_clipboard=%s", selection, self.local_clipboard, self.remote_clipboard)
log("remote_to_local(%s) local_clipboard=%s, remote_clipboard=%s",
selection, self.local_clipboard, self.remote_clipboard)
if selection==self.remote_clipboard:
return self.local_clipboard
return selection
15 changes: 10 additions & 5 deletions src/xpra/codecs/codec_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def make_test_image(pixel_format, w, h):
#l = len(rgb_data)
else:
raise Exception("don't know how to create a %s image" % pixel_format)
#log("make_test_image%30s took %3ims for %6iMBytes", (pixel_format, w, h), 1000*(monotonic_time()-start), l//1024//1024)
#log("make_test_image%30s took %3ims for %6iMBytes",
# (pixel_format, w, h), 1000*(monotonic_time()-start), l//1024//1024)
return image


Expand All @@ -80,7 +81,8 @@ def testdecoder(decoder_module, full):
del e
codecs.remove(encoding)
if not codecs:
log.error("%s: all the codecs have failed! (%s)", decoder_module.get_type(), csv(decoder_module.get_encodings()))
log.error("%s: all the codecs have failed! (%s)",
decoder_module.get_type(), csv(decoder_module.get_encodings()))
return codecs

def testdecoding(decoder_module, encoding, full):
Expand All @@ -96,7 +98,8 @@ def testdecoding(decoder_module, encoding, full):
e.init_context(encoding, W, H, cs)
test_data = test_data_set.get(cs)
if test_data:
log("%s: testing %s / %s with %s bytes of data", decoder_module.get_type(), encoding, cs, len(test_data))
log("%s: testing %s / %s with %s bytes of data",
decoder_module.get_type(), encoding, cs, len(test_data))
image = e.decompress_image(test_data, {})
assert image is not None, "failed to decode test data for encoding '%s' with colorspace '%s'" % (encoding, cs)
assert image.get_width()==W, "expected image of width %s but got %s" % (W, image.get_width())
Expand Down Expand Up @@ -125,7 +128,8 @@ def testencoder(encoder_module, full):
del e
codecs.remove(encoding)
if not codecs:
log.error("%s: all the codecs have failed! (%s)", encoder_module.get_type(), csv(encoder_module.get_encodings()))
log.error("%s: all the codecs have failed! (%s)",
encoder_module.get_type(), csv(encoder_module.get_encodings()))
return codecs

def testencoding(encoder_module, encoding, full):
Expand Down Expand Up @@ -269,7 +273,8 @@ def get_csc_max_size(colorspace_converter, test_cs_in=None, test_cs_out=None, li
log("%s can handle %ix%i", colorspace_converter, tw, th)
MAX_WIDTH, MAX_HEIGHT = tw, th
except:
log("%s is limited to %ix%i for %s", colorspace_converter, MAX_WIDTH, MAX_HEIGHT, (test_cs_in, test_cs_out), exc_info=True)
log("%s is limited to %ix%i for %s",
colorspace_converter, MAX_WIDTH, MAX_HEIGHT, (test_cs_in, test_cs_out), exc_info=True)
break
v *= 2
log("%s max dimensions: %ix%i", colorspace_converter, MAX_WIDTH, MAX_HEIGHT)
Expand Down
34 changes: 22 additions & 12 deletions src/xpra/colorstreamhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ class _AnsiColorStreamHandler(logging.StreamHandler):

@classmethod
def _get_color(cls, level):
if level >= logging.CRITICAL: return cls.CRITICAL
elif level >= logging.ERROR: return cls.ERROR
elif level >= logging.WARNING: return cls.WARNING
elif level >= logging.INFO: return cls.INFO
elif level >= logging.DEBUG: return cls.DEBUG
else: return cls.DEFAULT
if level >= logging.CRITICAL:
return cls.CRITICAL
if level >= logging.ERROR:
return cls.ERROR
if level >= logging.WARNING:
return cls.WARNING
if level >= logging.INFO:
return cls.INFO
if level >= logging.DEBUG:
return cls.DEBUG
return cls.DEFAULT

def __init__(self, stream=None):
logging.StreamHandler.__init__(self, stream)
Expand Down Expand Up @@ -89,12 +94,17 @@ class _WinColorStreamHandler(logging.StreamHandler):

@classmethod
def _get_color(cls, level):
if level >= logging.CRITICAL: return cls.CRITICAL
elif level >= logging.ERROR: return cls.ERROR
elif level >= logging.WARNING: return cls.WARNING
elif level >= logging.INFO: return cls.INFO
elif level >= logging.DEBUG: return cls.DEBUG
else: return cls.DEFAULT
if level >= logging.CRITICAL:
return cls.CRITICAL
if level >= logging.ERROR:
return cls.ERROR
if level >= logging.WARNING:
return cls.WARNING
if level >= logging.INFO:
return cls.INFO
if level >= logging.DEBUG:
return cls.DEBUG
return cls.DEFAULT

def _set_color(self, code):
import ctypes
Expand Down
10 changes: 4 additions & 6 deletions src/xpra/dbus/gtk_menuactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def set_actions(self, actions):
if oldaction[0]!=newaction[0]:
v = dbus.Dictionary({ds(action) : dbus.Boolean(newaction[0])}, signature="sb")
enabled_changed.append(v)
self.log(".set_actions(..) enabled changed for %s from %s to %s", action, oldaction[0], newaction[0])
self.log(".set_actions(..) enabled changed for %s from %s to %s",
action, oldaction[0], newaction[0])
if oldaction[2]!=newaction[2]:
v = dbus.Dictionary({ds(action) : newaction[2]}, signature="sv")
state_changed.append(v)
Expand Down Expand Up @@ -207,7 +208,8 @@ def set_menus(self, menus):
menu = group.get(menu_id, [])
if menu==oldmenu:
continue
self.log(".set_menus(..) found change at group=%i, menu_id=%i : from %s to %s", group_id, menu_id, oldmenu, menu)
self.log(".set_menus(..) found change at group=%i, menu_id=%i : from %s to %s",
group_id, menu_id, oldmenu, menu)
delcount = len(oldmenu) #remove all
insert = [self._make_menu_item(menu[i]) for i in range(len(menu))]
changed.append(dbus.Struct(di(group_id), di(menu_id), di(0), di(delcount), dbus.Array(dbus.Array(insert))))
Expand Down Expand Up @@ -311,10 +313,6 @@ def get_actions_interface(bus_name, object_path):

def query_actions(bus_name, object_path, actions_cb=None, error_cb=None):
actions_iface = get_actions_interface(bus_name, object_path)
def actions_changed(*args):
log("actions_changed%s", args)
if actions_cb:
actions_iface.DescribeAll(reply_handler=describe_all_actions, error_handler=describe_all_error)
def actions_list(*args):
log("actions_list%s", args)
def actions_error(*args):
Expand Down
32 changes: 16 additions & 16 deletions src/xpra/dbus/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,42 @@ def dbus_to_native(value):
#log("dbus_to_native(%s) type=%s", value, type(value))
if value is None:
return None
elif isinstance(value, int):
if isinstance(value, int):
return int(value)
elif isinstance(value, long):
if isinstance(value, long):
return long(value)
elif isinstance(value, dict):
if isinstance(value, dict):
d = {}
for k,v in value.items():
d[dbus_to_native(k)] = dbus_to_native(v)
return d
elif isinstance(value, basestring):
if isinstance(value, basestring):
return str(value)
elif isinstance(value, float):
if isinstance(value, float):
return float(value)
elif isinstance(value, list):
if isinstance(value, list):
return [dbus_to_native(x) for x in value]
elif isinstance(value, dbus.Struct):
if isinstance(value, dbus.Struct):
return [dbus_to_native(value[i]) for i in range(len(value))]
return value

def native_to_dbus(value):
if value is None:
return None
elif isinstance(value, int):
if isinstance(value, int):
return dbus.types.Int64(value)
elif isinstance(value, long):
if isinstance(value, long):
return dbus.types.Int64(value)
elif isinstance(value, unicode):
if isinstance(value, unicode):
return dbus.types.String(value)
elif isinstance(value, basestring):
if isinstance(value, basestring):
return dbus.types.String(value)
elif isinstance(value, float):
if isinstance(value, float):
return dbus.types.Double(value)
elif isinstance(value, (tuple, list, bytearray)):
if isinstance(value, (tuple, list, bytearray)):
if not value:
return dbus.Array(signature="s")
keytypes = set([type(x) for x in value])
keytypes = set(type(x) for x in value)
sig = None
if len(keytypes)==1:
#just one type of key:
Expand All @@ -77,10 +77,10 @@ def native_to_dbus(value):
#use strings as keys
value = [native_to_dbus(str(v)) for v in value]
return dbus.types.Array(value)
elif isinstance(value, dict):
if isinstance(value, dict):
if not value:
return dbus.types.Dictionary({}, signature="sv")
keytypes = set([type(x) for x in value.keys()])
keytypes = set(type(x) for x in value.keys())
sig = None
if len(keytypes)==1:
#just one type of key:
Expand Down
10 changes: 8 additions & 2 deletions src/xpra/dbus/notifications_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ def Notify(self, app_name, replaces_nid, app_icon, summary, body, actions, hints
nid = self.next_id()
else:
nid = int(replaces_nid)
log("Notify%s counter=%i, callback=%s", (app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout), self.counter, self.notify_callback)
log("Notify%s counter=%i, callback=%s",
(app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout), self.counter, self.notify_callback)
self.active_notifications.add(nid)
if self.notify_callback:
try:
actions = tuple(str(x) for x in actions)
hints = self.parse_hints(hints)
args = self.dbus_id, int(nid), str(app_name), int(replaces_nid), str(app_icon), str(summary), str(body), actions, hints, int(expire_timeout)
args = (
self.dbus_id, int(nid), str(app_name),
int(replaces_nid), str(app_icon),
str(summary), str(body),
actions, hints, int(expire_timeout),
)
except Exception as e:
log.error("Error: failed to parse Notify arguments:")
log.error(" %s", e)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/gtk_common/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __str__(self):
xerror_to_name = None
def get_X_error(xerror):
global xerror_to_name
if type(xerror)!=int:
if not isinstance(xerror, int):
return xerror
try:
from xpra.x11.bindings.window_bindings import constants #@UnresolvedImport
Expand Down
1 change: 0 additions & 1 deletion src/xpra/gtk_common/gobject_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,3 @@ def import_gtkosx_application3():
return GtkosxApplication
def import_gtkosx_application():
return _try_import(import_gtkosx_application3, import_gtkosx_application2)

2 changes: 1 addition & 1 deletion src/xpra/gtk_common/gtk_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def close_notify(self, nid):
x.hide_notification()

def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, timeout, icon):
self.new_popup(nid, summary, body, actions, icon, timeout, timeout>0 and timeout<=600)
self.new_popup(nid, summary, body, actions, icon, timeout, 0<timeout<=600)

def new_popup(self, nid, summary, body, actions, icon, timeout=10*1000, show_timeout=False):
"""Create a new Popup instance."""
Expand Down

0 comments on commit f08b7d2

Please sign in to comment.