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@21699 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 19, 2019
1 parent 63b8685 commit 5bc0ec8
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 92 deletions.
8 changes: 5 additions & 3 deletions src/xpra/client/client_window_base.py
Expand Up @@ -590,7 +590,7 @@ def refresh_all_windows(self, *_args):
#the "ClientWindow"
self._client.send_refresh_all()

def draw_region(self, x, y, width, height, coding, img_data, rowstride, packet_sequence, options, callbacks):
def draw_region(self, x, y, width, height, coding, img_data, rowstride, _packet_sequence, options, callbacks):
""" Note: this runs from the draw thread (not UI thread) """
backing = self._backing
if not backing:
Expand All @@ -599,7 +599,8 @@ def draw_region(self, x, y, width, height, coding, img_data, rowstride, packet_s
fire_paint_callbacks(callbacks, -1, "no backing")
return
def after_draw_refresh(success, message=""):
plog("after_draw_refresh(%s, %s) %sx%s at %sx%s encoding=%s, options=%s", success, message, width, height, x, y, coding, options)
plog("after_draw_refresh(%s, %s) %sx%s at %sx%s encoding=%s, options=%s",
success, message, width, height, x, y, coding, options)
if success<=0:
return
backing = self._backing
Expand Down Expand Up @@ -718,7 +719,8 @@ def _button_action(self, button, event, depressed, *args):
return
pointer, relative_pointer, modifiers, buttons = self._pointer_modifiers(event)
wid = self.get_mouse_event_wid(*pointer)
mouselog("_button_action(%s, %s, %s) wid=%s / focus=%s / window wid=%i, device=%s, pointer=%s, modifiers=%s, buttons=%s", button, event, depressed, wid, self._client._focused, self._id, self._device_info(event), pointer, modifiers, buttons)
mouselog("_button_action(%s, %s, %s) wid=%s / focus=%s / window wid=%i, device=%s, pointer=%s, modifiers=%s, buttons=%s",
button, event, depressed, wid, self._client._focused, self._id, self._device_info(event), pointer, modifiers, buttons)
#map wheel buttons via translation table to support inverted axes:
server_button = button
if button>3:
Expand Down
10 changes: 3 additions & 7 deletions src/xpra/client/gtk_base/client_launcher.py
Expand Up @@ -142,8 +142,6 @@ def __init__(self):
fixup_options(self.config)
#what we save by default:
self.config_keys = set(SAVED_FIELDS)
def raise_exception(*args):
raise Exception(*args)
self.client = None
self.exit_launcher = False
self.exit_code = None
Expand Down Expand Up @@ -523,15 +521,15 @@ def validate(self, *args):
ssh_port = self.ssh_port_entry.get_text()
try:
ssh_port = int(ssh_port)
except:
except ValueError:
ssh_port = -1
errs.append((self.ssh_port_entry, ssh_port<0 or ssh_port>=2**16, "invalid SSH port number"))
if sshtossh:
#validate ssh port:
proxy_port = self.proxy_port_entry.get_text()
try:
proxy_port = int(proxy_port)
except:
except ValueError:
proxy_port = -1
errs.append((self.proxy_port_entry, proxy_port<0 or proxy_port>=2**16, "invalid SSH port number"))
port = self.port_entry.get_text()
Expand Down Expand Up @@ -1166,9 +1164,7 @@ def show_signal():
glib.timeout_add(1000, app.set_info_color, True)
#call from UI thread:
glib.idle_add(show_signal)
if sys.version_info[0]<3:
#breaks GTK3..
signal.signal(signal.SIGINT, app_signal)
signal.signal(signal.SIGINT, app_signal)
signal.signal(signal.SIGTERM, app_signal)
has_file = len(args) == 1
if has_file:
Expand Down
15 changes: 9 additions & 6 deletions src/xpra/client/mixins/clipboard.py
Expand Up @@ -35,10 +35,10 @@ def __init__(self):
self.server_clipboards = []
self.clipboard_helper = None

def init(self, opts, _extra_args=[]):
def init(self, opts, _extra_args=()):
self.client_clipboard_type = opts.clipboard
self.client_clipboard_direction = opts.clipboard_direction
self.client_supports_clipboard = not ((opts.clipboard or "").lower() in FALSE_OPTIONS)
self.client_supports_clipboard = (opts.clipboard or "").lower() not in FALSE_OPTIONS


def cleanup(self):
Expand Down Expand Up @@ -91,11 +91,12 @@ def parse_server_capabilities(self):
self.client_clipboard_direction = self.server_clipboard_direction
else:
log.warn("Warning: incompatible clipboard direction settings")
log.warn(" server setting: %s, client setting: %s", self.server_clipboard_direction, self.client_clipboard_direction)
log.warn(" server setting: %s, client setting: %s",
self.server_clipboard_direction, self.client_clipboard_direction)
self.server_clipboard_enable_selections = c.boolget("clipboard.enable-selections")
try:
from xpra.clipboard.clipboard_base import ALL_CLIPBOARDS
except:
except ImportError:
ALL_CLIPBOARDS = []
self.server_clipboards = c.strlistget("clipboards", ALL_CLIPBOARDS)
log("server clipboard: supported=%s, direction=%s, supports enable selection=%s",
Expand Down Expand Up @@ -177,7 +178,8 @@ def _process_clipboard_enabled_status(self, packet):
self.emit("clipboard-toggled")

def clipboard_toggled(self, *args):
log("clipboard_toggled%s clipboard_enabled=%s, server_clipboard=%s", args, self.clipboard_enabled, self.server_clipboard)
log("clipboard_toggled%s clipboard_enabled=%s, server_clipboard=%s",
args, self.clipboard_enabled, self.server_clipboard)
if self.server_clipboard:
self.send("set-clipboard-enabled", self.clipboard_enabled)
if self.clipboard_enabled:
Expand All @@ -189,7 +191,8 @@ def clipboard_toggled(self, *args):
pass #FIXME: todo!

def send_clipboard_selections(self, selections):
log("send_clipboard_selections(%s) server_clipboard_enable_selections=%s", selections, self.server_clipboard_enable_selections)
log("send_clipboard_selections(%s) server_clipboard_enable_selections=%s",
selections, self.server_clipboard_enable_selections)
if self.server_clipboard_enable_selections:
self.send("clipboard-enable-selections", selections)

Expand Down
34 changes: 21 additions & 13 deletions src/xpra/gtk_common/gobject_compat.py
Expand Up @@ -11,7 +11,15 @@

import sys

__all__ = ["is_gtk3", "get_xid", "import_gobject", "import_gtk", "import_gdk", "import_pango", "import_glib", "import_pixbufloader"]
__all__ = [
"is_gtk3",
"import_gobject",
"import_gtk",
"import_gdk",
"import_pango",
"import_glib",
"import_pixbufloader",
]

_is_gtk3 = None
if sys.version>='3':
Expand Down Expand Up @@ -59,7 +67,7 @@ def trygtk3():
try:
imported = import_method_gtk2()
_is_gtk3 = False
except:
except ImportError:
imported = trygtk3()
_is_gtk3 = True
return imported
Expand All @@ -75,21 +83,21 @@ def try_import_GdkX11():
gi.require_version('GdkX11', '3.0')
from gi.repository import GdkX11 #@UnresolvedImport @UnusedImport
return GdkX11
except:
except ImportError:
pass
return None


def import_gobject2():
import gobject
import gobject #@UnresolvedImport
gobject.threads_init()
return gobject
def import_gobject3():
from gi.repository import GObject #@UnresolvedImport
#silence a GTK3 warning about threads_init not beeing needed:
v = getattr(GObject, "pygobject_version", (0))
if v>=(3,10):
def noop(*args):
def noop(*_args):
pass
GObject.threads_init = noop
return GObject
Expand All @@ -100,16 +108,16 @@ def import_glib3():
from gi.repository import GLib #@UnresolvedImport
return GLib
def import_glib2():
import glib
import glib #@UnresolvedImport
glib.threads_init()
return glib
def import_glib():
return _try_import(import_glib3, import_glib2)

def import_gtk2():
import pygtk
import pygtk #@UnresolvedImport
pygtk.require("2.0")
import gtk
import gtk #@UnresolvedImport
return gtk
def import_gtk3():
gi_gtk()
Expand All @@ -120,7 +128,7 @@ def import_gtk():
return _try_import(import_gtk3, import_gtk2)

def import_gdk2():
from gtk import gdk
from gtk import gdk #@UnresolvedImport
return gdk
def import_gdk3():
gi_gtk()
Expand All @@ -131,7 +139,7 @@ def import_gdk():
return _try_import(import_gdk3, import_gdk2)

def import_pixbuf2():
from gtk.gdk import Pixbuf
from gtk.gdk import Pixbuf #@UnresolvedImport
return Pixbuf
def import_pixbuf3():
gi_gtk()
Expand All @@ -141,7 +149,7 @@ def import_pixbuf():
return _try_import(import_pixbuf3, import_pixbuf2)

def import_pixbufloader2():
from gtk.gdk import PixbufLoader
from gtk.gdk import PixbufLoader #@UnresolvedImport
return PixbufLoader
def import_pixbufloader3():
from gi.repository import GdkPixbuf #@UnresolvedImport
Expand All @@ -150,7 +158,7 @@ def import_pixbufloader():
return _try_import(import_pixbufloader3, import_pixbufloader2)

def import_pango2():
import pango
import pango #@UnresolvedImport
return pango
def import_pango3():
from gi.repository import Pango #@UnresolvedImport
Expand All @@ -159,7 +167,7 @@ def import_pango():
return _try_import(import_pango3, import_pango2)

def import_pangocairo2():
import pangocairo
import pangocairo #@UnresolvedImport
return pangocairo
def import_pangocairo3():
from gi.repository import PangoCairo #@UnresolvedImport
Expand Down
19 changes: 14 additions & 5 deletions src/xpra/gtk_common/gtk_util.py
Expand Up @@ -1003,17 +1003,26 @@ def visual(name, v):
"red_pixel_details" : {},
"green_pixel_details" : {},
"blue_pixel_details" : {},
"visual_type" : {STATIC_GRAY : "STATIC_GRAY", GRAYSCALE : "GRAYSCALE", STATIC_COLOR : "STATIC_COLOR", PSEUDO_COLOR : "PSEUDO_COLOR", TRUE_COLOR : "TRUE_COLOR", DIRECT_COLOR : "DIRECT_COLOR"},
"visual_type" : {
STATIC_GRAY : "STATIC_GRAY",
GRAYSCALE : "GRAYSCALE",
STATIC_COLOR : "STATIC_COLOR",
PSEUDO_COLOR : "PSEUDO_COLOR",
TRUE_COLOR : "TRUE_COLOR",
DIRECT_COLOR : "DIRECT_COLOR",
},
}.items():
val = None
try:
val = getattr(v, x.replace("visual_")) #ugly workaround for "visual_type" -> "type" for GTK2...
except:
#ugly workaround for "visual_type" -> "type" for GTK2...
val = getattr(v, x.replace("visual_"))
except AttributeError:
try:
fn = getattr(v, "get_"+x)
val = fn()
except:
except AttributeError:
pass
else:
val = fn()
if val is not None:
vinfo.setdefault(name, {})[x] = vdict.get(val, val)
try:
Expand Down
12 changes: 7 additions & 5 deletions src/xpra/notifications/dbus_notifier.py
Expand Up @@ -157,7 +157,7 @@ def ActionInvoked(self, actual_id, action):

def NotifyError(self, dbus_error, *_args):
try:
if type(dbus_error)==dbus.exceptions.DBusException:
if isinstance(dbus_error, dbus.exceptions.DBusException):
message = dbus_error.get_dbus_message()
dbus_error_name = dbus_error.get_dbus_name()
if dbus_error_name!="org.freedesktop.DBus.Error.ServiceUnknown":
Expand All @@ -176,7 +176,7 @@ def NotifyError(self, dbus_error, *_args):
#and retry:
self.show_notify(*self.last_notification)
except:
pass
log("cannot filter error", exc_info=True)
log.error("Error processing notification:")
log.error(" %s", dbus_error)
return False
Expand Down Expand Up @@ -205,11 +205,13 @@ def CloseNotificationError(dbus_error, *_args):


def main():
import glib
import gtk
from xpra.gtk_common.gobject_compat import import_glib, import_gtk
glib = import_glib()
gtk = import_gtk()
def show():
n = DBUS_Notifier_factory()
n.show_notify("", None, 0, "Test", 0, "", "Summary", "Body line1\nline2...", ["0", "Hello", "1", "Bye"], {}, 0, "")
n.show_notify("", None, 0, "Test", 0, "", "Summary", "Body line1\nline2...",
["0", "Hello", "1", "Bye"], {}, 0, "")
return False
glib.idle_add(show)
glib.timeout_add(20000, gtk.main_quit)
Expand Down
7 changes: 4 additions & 3 deletions src/xpra/notifications/pynotify_notifier.py
Expand Up @@ -33,7 +33,7 @@ def show_notify(self, dbus_id, _tray, nid, app_name, replaces_nid, app_icon, sum

def add_action(self, n, action_id, action_label):
#n.add_action("foo", "Foo!", foo_action)
def callback(*args):
def callback(*_args):
pass
n.add_action(action_id, action_label, callback)

Expand All @@ -42,8 +42,9 @@ def close_notify(self, nid):


def main():
import glib
import gtk
from xpra.gtk_common.gobject_compat import import_glib, import_gtk
glib = import_glib()
gtk = import_gtk()
def show():
n = PyNotify_Notifier()
n.show_notify("", None, 0, "Test", 0, "", "Summary", "Body...", ["0", "Hello", "1", "Bye"], {}, 0, "")
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/platform/darwin/info.py
Expand Up @@ -8,7 +8,7 @@ def get_pyobjc_version():
try:
import objc #@UnresolvedImport
return objc.__version__
except:
except ImportError:
return None

def get_version_info():
Expand Down
12 changes: 7 additions & 5 deletions src/xpra/platform/dotxpra.py
Expand Up @@ -12,6 +12,7 @@

from xpra.os_util import get_util_logger, osexpand, umask_context
from xpra.platform.dotxpra_common import PREFIX, LIVE, DEAD, UNKNOWN, INACCESSIBLE
from xpra.platform import platform_import


def norm_makepath(dirpath, name):
Expand Down Expand Up @@ -57,7 +58,7 @@ def mksockdir(self, d, mode=0o700, uid=None, gid=None):
os.lchown(d, uid, gid)

def socket_expand(self, path):
return self.osexpand(path, uid=self.uid, gid=self.gid)
return osexpand(path, self.username, uid=self.uid, gid=self.gid)

def norm_socket_paths(self, local_display_name):
return [norm_makepath(x, local_display_name) for x in self._sockdirs]
Expand Down Expand Up @@ -92,7 +93,7 @@ def get_server_state(self, sockpath, timeout=5):
finally:
try:
sock.close()
except:
except IOError:
debug("%s.close()", sock, exc_info=True)


Expand Down Expand Up @@ -120,7 +121,8 @@ def socket_details(self, check_uid=0, matching_state=None, matching_display=None
if self._sockdir!="undefined":
dirs.append(self._sockdir)
dirs += [x for x in self._sockdirs if x not in dirs]
debug("socket_details%s sockdir=%s, sockdirs=%s, testing=%s", (check_uid, matching_state, matching_display), self._sockdir, self._sockdirs, dirs)
debug("socket_details%s sockdir=%s, sockdirs=%s, testing=%s",
(check_uid, matching_state, matching_display), self._sockdir, self._sockdirs, dirs)
seen = set()
for d in dirs:
if not d or not os.path.exists(d):
Expand Down Expand Up @@ -149,7 +151,8 @@ def socket_details(self, check_uid=0, matching_state=None, matching_display=None
continue
local_display = ":"+sockpath[len(base):]
if matching_display and local_display!=matching_display:
debug("socket_details: '%s' display does not match (%s vs %s)", sockpath, local_display, matching_display)
debug("socket_details: '%s' display does not match (%s vs %s)",
sockpath, local_display, matching_display)
continue
state = self.get_server_state(sockpath)
if matching_state and state!=matching_state:
Expand All @@ -162,7 +165,6 @@ def socket_details(self, check_uid=0, matching_state=None, matching_display=None


#win32 re-defines DotXpra for namedpipes:
from xpra.platform import platform_import
platform_import(globals(), "dotxpra", False,
"DotXpra",
"norm_makepath")
4 changes: 2 additions & 2 deletions src/xpra/platform/gl_context.py
Expand Up @@ -5,13 +5,13 @@

import sys

from xpra.platform import platform_import

GLContext = None

def check_support():
return GLContext().check_support()


from xpra.platform import platform_import
platform_import(globals(), "gl_context", False, "GLContext", "check_support")


Expand Down

0 comments on commit 5bc0ec8

Please sign in to comment.