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@21854 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 24, 2019
1 parent ddcef7d commit 8c14842
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 30 deletions.
61 changes: 41 additions & 20 deletions src/xpra/client/keyboard_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

class KeyboardHelper(object):

def __init__(self, net_send, keyboard_sync=True, shortcut_modifiers="auto", key_shortcuts=[], raw=False, layout="", layouts=[], variant="", variants=[], options=""):
def __init__(self, net_send, keyboard_sync=True,
shortcut_modifiers="auto", key_shortcuts=(),
raw=False, layout="", layouts=(),
variant="", variants=(), options=""):
self.reset_state()
self.send = net_send
self.locked = False
Expand All @@ -35,7 +38,9 @@ def __init__(self, net_send, keyboard_sync=True, shortcut_modifiers="auto", key_
#the platform class which allows us to map the keys:
from xpra.platform.keyboard import Keyboard
self.keyboard = Keyboard()
log("KeyboardHelper(%s) keyboard=%s", (net_send, keyboard_sync, key_shortcuts, raw, layout, layouts, variant, variants, options), self.keyboard)
log("KeyboardHelper(%s) keyboard=%s",
(net_send, keyboard_sync, key_shortcuts,
raw, layout, layouts, variant, variants, options), self.keyboard)
key_repeat = self.keyboard.get_keyboard_repeat()
if key_repeat:
self.key_repeat_delay, self.key_repeat_interval = key_repeat
Expand Down Expand Up @@ -72,7 +77,7 @@ def reset_state(self):

def cleanup(self):
self.reset_state()
def nosend(*args):
def nosend(*_args):
pass
self.send = nosend

Expand All @@ -82,7 +87,7 @@ def keymap_changed(self, *args):

def parse_shortcuts(self, strs):
#TODO: maybe parse with re instead?
if len(strs)==0:
if not strs:
""" if none are defined, add this as default
it would be nicer to specify it via OptionParser in main
but then it would always have to be there with no way of removing it
Expand Down Expand Up @@ -159,13 +164,13 @@ def mod_defaults():
args = []
for x in all_args.split(","):
x = x.strip()
if len(x)==0:
if not x:
continue
if (x[0]=='"' and x[-1]=='"') or (x[0]=="'" and x[-1]=="'"):
args.append(x[1:-1])
elif x=="None":
if x=="None":
args.append(None)
elif x.find("."):
if x.find("."):
args.append(float(x))
else:
args.append(int(x))
Expand Down Expand Up @@ -232,15 +237,15 @@ def key_handled_as_shortcut(self, window, key_name, modifiers, depressed):
return False

def _check_shortcut(self, window, key_name, modifiers, depressed, shortcut):
(req_mods, action, args) = shortcut
req_mods, action, args = shortcut
extra_modifiers = list(modifiers)
for rm in req_mods:
if rm not in modifiers:
#modifier is missing, bail out
return False
try:
extra_modifiers.remove(rm)
except:
except ValueError:
pass #same modifier listed twice?
kmod = self.keyboard.get_keymap_modifiers()[0]
if not kmod and self.keyboard.modifier_keys:
Expand All @@ -258,17 +263,19 @@ def _check_shortcut(self, window, key_name, modifiers, depressed, shortcut):
return False
log("matched shortcut %s", shortcut)
if not depressed:
""" when the key is released, just ignore it - do NOT send it to the server! """
#when the key is released, just ignore it - do NOT send it to the server!
return True
try:
method = getattr(window, action)
log("key_handled_as_shortcut(%s,%s,%s,%s) found shortcut=%s, will call %s%s", window, key_name, modifiers, depressed, shortcut, method, args)
log("key_handled_as_shortcut(%s,%s,%s,%s) found shortcut=%s, will call %s%s",
window, key_name, modifiers, depressed, shortcut, method, args)
except AttributeError as e:
log.error("key dropped, invalid method name in shortcut %s: %s", action, e)
return True
try:
method(*args)
log("key_handled_as_shortcut(%s,%s,%s,%s) has been handled: %s", window, key_name, modifiers, depressed, method)
log("key_handled_as_shortcut(%s,%s,%s,%s) has been handled: %s",
window, key_name, modifiers, depressed, method)
except Exception as e:
log.error("key_handled_as_shortcut(%s,%s,%s,%s)", window, key_name, modifiers, depressed)
log.error(" failed to execute shortcut=%s", shortcut)
Expand Down Expand Up @@ -303,7 +310,7 @@ def inl(v, l):
if v in l or v is None:
return l
return [v]+list(l)
except:
except Exception:
if v is not None:
return [v]
return []
Expand Down Expand Up @@ -338,13 +345,22 @@ def get_keymap_spec(self):
return _print, query, query_struct

def query_xkbmap(self):
self.xkbmap_layout, self.xkbmap_layouts, self.xkbmap_variant, self.xkbmap_variants, self.xkbmap_options = self.get_layout_spec()
(
self.xkbmap_layout, self.xkbmap_layouts,
self.xkbmap_variant, self.xkbmap_variants,
self.xkbmap_options,
) = self.get_layout_spec()
self.xkbmap_print, self.xkbmap_query, self.xkbmap_query_struct = self.get_keymap_spec()
self.xkbmap_keycodes = self.get_full_keymap()
self.xkbmap_x11_keycodes = self.keyboard.get_x11_keymap()
self.xkbmap_mod_meanings, self.xkbmap_mod_managed, self.xkbmap_mod_pointermissing = self.keyboard.get_keymap_modifiers()
(
self.xkbmap_mod_meanings,
self.xkbmap_mod_managed,
self.xkbmap_mod_pointermissing,
) = self.keyboard.get_keymap_modifiers()
self.update_hash()
log("layout=%s, layouts=%s, variant=%s, variants=%s", self.xkbmap_layout, self.xkbmap_layouts, self.xkbmap_variant, self.xkbmap_variants)
log("layout=%s, layouts=%s, variant=%s, variants=%s",
self.xkbmap_layout, self.xkbmap_layouts, self.xkbmap_variant, self.xkbmap_variants)
log("print=%s, query=%s, struct=%s", nonl(self.xkbmap_print), nonl(self.xkbmap_query), self.xkbmap_query_struct)
log("keycodes=%s", repr_ellipsized(str(self.xkbmap_keycodes)))
log("x11 keycodes=%s", repr_ellipsized(str(self.xkbmap_x11_keycodes)))
Expand All @@ -358,12 +374,17 @@ def update(self):
self.query_xkbmap()

def layout_str(self):
return " / ".join([bytestostr(x) for x in (self.layout_option or self.xkbmap_layout, self.variant_option or self.xkbmap_variant) if bool(x)])
return " / ".join([bytestostr(x) for x in (
self.layout_option or self.xkbmap_layout, self.variant_option or self.xkbmap_variant) if bool(x)])


def send_layout(self):
log("send_layout() layout_option=%s, xkbmap_layout=%s, variant_option=%s, xkbmap_variant=%s, xkbmap_options=%s", self.layout_option, self.xkbmap_layout, self.variant_option, self.xkbmap_variant, self.xkbmap_options)
self.send("layout-changed", self.layout_option or self.xkbmap_layout or "", self.variant_option or self.xkbmap_variant or "", self.xkbmap_options or "")
log("send_layout() layout_option=%s, xkbmap_layout=%s, variant_option=%s, xkbmap_variant=%s, xkbmap_options=%s",
self.layout_option, self.xkbmap_layout, self.variant_option, self.xkbmap_variant, self.xkbmap_options)
self.send("layout-changed",
self.layout_option or self.xkbmap_layout or "",
self.variant_option or self.xkbmap_variant or "",
self.xkbmap_options or "")

def send_keymap(self):
log("send_keymap()")
Expand Down Expand Up @@ -419,7 +440,7 @@ def log_keyboard_info(self):
kb_info[x] = v
if self.xkbmap_layout:
kb_info["layout"] = self.xkbmap_layout
if len(kb_info)==0:
if not kb_info:
log.info(" using default keyboard settings")
else:
log.info(" keyboard settings: %s", csv("%s=%s" % (std(k), std(v)) for k,v in kb_info.items()))
8 changes: 4 additions & 4 deletions src/xpra/client/scaling_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ def parse_item(v):
if v.endswith("%"):
div = 100
v = v[:-1]
except:
except ValueError:
pass
if div==1:
try:
return int(v) #ie: desktop-scaling=2
except:
except ValueError:
pass
try:
return float(v)/div #ie: desktop-scaling=1.5
except:
except (ValueError, ZeroDivisionError):
pass
#ie: desktop-scaling=3/2, or desktop-scaling=3:2
pair = v.replace(":", "/").split("/", 1)
try:
return float(pair[0])/float(pair[1])
except:
except (ValueError, ZeroDivisionError):
pass
log.warn("Warning: failed to parse scaling value '%s'", v)
return None
Expand Down
22 changes: 16 additions & 6 deletions src/xpra/client/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def process_delta(self, raw_data, width, height, rowstride, options):
raise Exception("delta region bucket %s references pixmap data we do not have!" % bucket)
lwidth, lheight, lrgb_format, seq, ldata = self._delta_pixel_data[bucket]
assert width==lwidth and height==lheight and delta==seq, \
"delta bucket %s data does not match: expected %s but got %s" % (bucket, (width, height, delta), (lwidth, lheight, seq))
"delta bucket %s data does not match: expected %s but got %s" % (
bucket, (width, height, delta), (lwidth, lheight, seq))
assert lrgb_format==rgb_format, "delta region uses %s format, was expecting %s" % (rgb_format, lrgb_format)
deltalog("delta: xoring with bucket %i", bucket)
rgb_data = xor_str(img_data, ldata)
Expand Down Expand Up @@ -305,7 +306,11 @@ def paint_webp(self, img_data, x, y, width, height, options, callbacks):
return self.paint_image("webp", img_data, x, y, width, height, options, callbacks)
rgb_format = options.strget("rgb_format")
has_alpha = options.boolget("has_alpha", False)
buffer_wrapper, width, height, stride, has_alpha, rgb_format = self.webp_decoder.decompress(img_data, has_alpha, rgb_format, self.RGB_MODES)
(
buffer_wrapper,
width, height, stride, has_alpha,
rgb_format,
) = self.webp_decoder.decompress(img_data, has_alpha, rgb_format, self.RGB_MODES)
def free_buffer(*_args):
buffer_wrapper.free()
callbacks.append(free_buffer)
Expand Down Expand Up @@ -395,7 +400,8 @@ def make_csc(self, src_width, src_height, src_format,
return csc
except Exception as e:
log("make_csc%s",
(src_width, src_height, src_format, dst_width, dst_height, dst_format_options, speed), exc_info=True)
(src_width, src_height, src_format, dst_width, dst_height, dst_format_options, speed),
exc_info=True)
log.error("Error: failed to create csc instance %s", spec.codec_class)
log.error(" for %s to %s: %s", src_format, dst_format, e)
log.error("Error: no matching CSC module found")
Expand Down Expand Up @@ -493,7 +499,9 @@ def paint_with_video_decoder(self, decoder_module, coding, img_data, x, y, width
#and this frame references those, so assume all is well:
fire_paint_callbacks(callbacks)
else:
fire_paint_callbacks(callbacks, False, "video decoder %s failed to decode %i bytes of %s data" % (vd.get_type(), len(img_data), coding))
fire_paint_callbacks(callbacks, False,
"video decoder %s failed to decode %i bytes of %s data" % (
vd.get_type(), len(img_data), coding))
log.error("Error: decode failed on %s bytes of %s data", len(img_data), coding)
log.error(" %sx%s pixels using %s", width, height, vd.get_type())
log.error(" frame options:")
Expand Down Expand Up @@ -585,7 +593,7 @@ def draw_region(self, x, y, width, height, coding, img_data, rowstride, options,
deltalog("passed compressed data integrity checks: len=%s, md5=%s (type=%s)", l, md5, type(img_data))
if coding == "mmap":
self.idle_add(self.paint_mmap, img_data, x, y, width, height, rowstride, options, callbacks)
elif coding == "rgb24" or coding == "rgb32":
elif coding in ("rgb24", "rgb32"):
#avoid confusion over how many bytes-per-pixel we may have:
rgb_format = options.strget(b"rgb_format")
if rgb_format:
Expand All @@ -600,7 +608,9 @@ def draw_region(self, x, y, width, height, coding, img_data, rowstride, options,
rowstride = width * Bpp
self.paint_rgb(rgb_format, img_data, x, y, width, height, rowstride, options, callbacks)
elif coding in VIDEO_DECODERS:
self.paint_with_video_decoder(VIDEO_DECODERS.get(coding), coding, img_data, x, y, width, height, options, callbacks)
self.paint_with_video_decoder(VIDEO_DECODERS.get(coding),
coding,
img_data, x, y, width, height, options, callbacks)
elif self.jpeg_decoder and coding=="jpeg":
self.paint_jpeg(img_data, x, y, width, height, options, callbacks)
elif coding == "webp":
Expand Down

0 comments on commit 8c14842

Please sign in to comment.