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@21822 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 22, 2019
1 parent fd1e228 commit f325ea9
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 100 deletions.
20 changes: 14 additions & 6 deletions src/xpra/platform/printing.py
Expand Up @@ -4,7 +4,8 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import sys, os
import os
import sys

#default implementation uses pycups
from xpra.util import envbool, print_nested_dict
Expand Down Expand Up @@ -87,7 +88,14 @@ def default_get_info():
if not WIN32:
#pycups is not available on win32
try:
from xpra.platform.pycups_printing import get_printers, print_files, printing_finished, init_printing, cleanup_printing, get_info
from xpra.platform.pycups_printing import (
get_printers,
print_files,
printing_finished,
init_printing,
cleanup_printing,
get_info,
)
assert get_printers and print_files and printing_finished and init_printing, cleanup_printing
except Exception as e:
log("cannot load pycups", exc_info=True)
Expand All @@ -113,11 +121,11 @@ def main():
enable_debug_for("printing")
try:
sys.argv.remove("-v")
except:
except ValueError:
pass
try:
sys.argv.remove("--verbose")
except:
except ValueError:
pass

from xpra.util import nonl, pver
Expand All @@ -126,7 +134,7 @@ def dump_dict(d):
try:
for pk,pv in d.items():
try:
if type(pv)==unicode:
if isinstance(pv, unicode):
sv = pv.encode("utf8")
else:
sv = nonl(pver(pv))
Expand Down Expand Up @@ -166,7 +174,7 @@ def dump_printers(d):
dump_info(get_info())
return 0
printers = get_printers()
if len(printers)==0:
if not printers:
print("Cannot print: no printers found")
return 1
if len(sys.argv)==2:
Expand Down
8 changes: 5 additions & 3 deletions src/xpra/platform/win32/__init__.py
Expand Up @@ -90,7 +90,9 @@ def set_prgname(name):

def fix_unicode_out():
if PYTHON3:
unicode = str
_unicode = str
else:
_unicode = unicode
#code found here:
#http://stackoverflow.com/a/3259271/428751
import codecs
Expand Down Expand Up @@ -188,11 +190,11 @@ def flush(self):
def write(self, text):
try:
if self._hConsole is None:
if isinstance(text, unicode):
if isinstance(text, _unicode):
text = text.encode('utf-8')
self._stream.write(text)
else:
if not isinstance(text, unicode):
if not isinstance(text, _unicode):
text = str(text).decode('utf-8')
remaining = len(text)
while remaining:
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/server/proxy/proxy_dbus_server.py
Expand Up @@ -6,12 +6,13 @@

import os

import dbus.service

from xpra.dbus.helper import native_to_dbus
from xpra.dbus.common import init_system_bus, init_session_bus
from xpra.server.dbus.dbus_server import DBUS_Server_Base, INTERFACE, BUS_NAME
import dbus.service

from xpra.log import Logger

log = Logger("dbus", "server")


Expand Down
46 changes: 26 additions & 20 deletions src/xpra/server/proxy/proxy_instance_process.py
Expand Up @@ -87,7 +87,8 @@ def __init__(self, uid, gid, env_options, session_options, socket_dir,
self.caps = caps
log("ProxyProcess%s", (uid, gid, env_options, session_options, socket_dir,
video_encoder_modules, csc_modules,
client_conn, disp_desc, repr_ellipsized(str(client_state)), cipher, encryption_key, server_conn,
client_conn, disp_desc, repr_ellipsized(str(client_state)),
cipher, encryption_key, server_conn,
"%s: %s.." % (type(caps), repr_ellipsized(str(caps))), message_queue))
self.client_protocol = None
self.server_protocol = None
Expand Down Expand Up @@ -121,7 +122,7 @@ def server_message_queue(self):
if m=="stop":
self.stop("proxy server request")
return
elif m=="socket-handover-complete":
if m=="socket-handover-complete":
log("setting sockets to blocking mode: %s", (self.client_conn, self.server_conn))
#set sockets to blocking mode:
set_blocking(self.client_conn)
Expand All @@ -147,7 +148,7 @@ def source_remove(self, tid):
del self.timers[tid]
if timer:
timer.cancel()
except:
except KeyError:
pass

def idle_add(self, fn, *args, **kwargs):
Expand Down Expand Up @@ -195,7 +196,7 @@ def timeout_repeat_call(self, tid, timeout, fn, fn_args, fn_kwargs, **kwargs):
else:
try:
del self.timers[tid]
except:
except KeyError:
pass
#we do the scheduling via timers, so always return False here
#so that the main queue won't re-schedule this function call itself:
Expand Down Expand Up @@ -253,9 +254,11 @@ def run(self):
self.client_packets = Queue(PROXY_QUEUE_SIZE)
client_protocol_class = get_client_protocol_class(self.client_conn.socktype)
server_protocol_class = get_server_protocol_class(self.server_conn.socktype)
self.client_protocol = client_protocol_class(self, self.client_conn, self.process_client_packet, self.get_client_packet)
self.client_protocol = client_protocol_class(self, self.client_conn,
self.process_client_packet, self.get_client_packet)
self.client_protocol.restore_state(self.client_state)
self.server_protocol = server_protocol_class(self, self.server_conn, self.process_server_packet, self.get_server_packet)
self.server_protocol = server_protocol_class(self, self.server_conn,
self.process_server_packet, self.get_server_packet)
#server connection tweaks:
for x in (b"input-devices", b"draw", b"window-icon", b"keymap-changed", b"server-settings"):
self.server_protocol.large_packets.append(x)
Expand Down Expand Up @@ -422,10 +425,10 @@ def is_req(mode):
proto.send_now(("hello", self.get_proxy_info(proto)))
self.timeout_add(5*1000, self.send_disconnect, proto, CLIENT_EXIT_TIMEOUT, "info sent")
return
elif is_req("stop"):
if is_req("stop"):
self.stop("socket request", None)
return
elif is_req("version"):
if is_req("version"):
version = XPRA_VERSION
if caps.boolget("full-version-request"):
version = full_version_str()
Expand Down Expand Up @@ -553,7 +556,8 @@ def run_queue(self):
if i==0:
log.info("waiting for network connections to close")
else:
log("still waiting %i/10 - client.closed=%s, server.closed=%s", i+1, self.client_protocol._closed, self.server_protocol._closed)
log("still waiting %i/10 - client.closed=%s, server.closed=%s",
i+1, self.client_protocol._closed, self.server_protocol._closed)
sleep(0.1)
log.info("proxy instance %s stopped", os.getpid())

Expand Down Expand Up @@ -602,26 +606,27 @@ def process_client_packet(self, proto, packet):
if packet_type==Protocol.CONNECTION_LOST:
self.stop("client connection lost", proto)
return
elif packet_type=="disconnect":
if packet_type=="set_deflate":
#echo it back to the client:
self.client_packets.put(packet)
self.client_protocol.source_has_more()
return
if packet_type=="hello":
log.warn("Warning: invalid hello packet received after initial authentication (dropped)")
return
#the packet types below are forwarded:
if packet_type=="disconnect":
log("got disconnect from client: %s", packet[1])
if self.exit:
self.client_protocol.close()
else:
self.stop("disconnect from client: %s" % packet[1])
elif packet_type=="set_deflate":
#echo it back to the client:
self.client_packets.put(packet)
self.client_protocol.source_has_more()
return
elif packet_type==b"send-file":
if packet[6]:
packet[6] = Compressed("file-data", packet[6])
elif packet_type==b"send-file-chunk":
if packet[3]:
packet[3] = Compressed("file-chunk-data", packet[3])
elif packet_type=="hello":
log.warn("Warning: invalid hello packet received after initial authentication (dropped)")
return
self.queue_server_packet(packet)


Expand Down Expand Up @@ -826,7 +831,8 @@ def send_updated(encoding, compressed_data, updated_client_options):
return (wid not in self.lost_windows)

def passthrough(strip_alpha=True):
enclog("proxy draw: %s passthrough (rowstride: %s vs %s, strip alpha=%s)", rgb_format, rowstride, client_options.intget("rowstride", 0), strip_alpha)
enclog("proxy draw: %s passthrough (rowstride: %s vs %s, strip alpha=%s)",
rgb_format, rowstride, client_options.intget("rowstride", 0), strip_alpha)
if strip_alpha:
#passthrough as plain RGB:
Xindex = rgb_format.upper().find("X")
Expand All @@ -853,7 +859,7 @@ def passthrough(strip_alpha=True):
if PASSTHROUGH and (encoding in ("rgb32", "rgb24") or proxy_video):
#we are dealing with rgb data, so we can pass it through:
return passthrough(proxy_video)
elif not self.video_encoder_types or not client_options or not proxy_video:
if not self.video_encoder_types or not client_options or not proxy_video:
#ensure we don't try to re-compress the pixel data in the network layer:
#(re-add the "compressed" marker that gets lost when we re-assemble packets)
packet[7] = Compressed("%s pixels" % encoding, packet[7])
Expand Down
19 changes: 13 additions & 6 deletions src/xpra/server/proxy/proxy_server.py
Expand Up @@ -200,7 +200,7 @@ def is_req(mode):
def force_exit_request_client():
try:
self._requests.remove(proto)
except:
except KeyError:
pass
if not proto._closed:
self.send_disconnect(proto, "timeout")
Expand Down Expand Up @@ -279,8 +279,9 @@ def disconnect(reason, *extras):
socket_path = None
display = None
sns = c.dictget("start-new-session")
authlog("proxy_session: displays=%s, start_sessions=%s, start-new-session=%s", displays, self._start_sessions, sns)
if len(displays)==0 or sns:
authlog("proxy_session: displays=%s, start_sessions=%s, start-new-session=%s",
displays, self._start_sessions, sns)
if not displays or sns:
if not self._start_sessions:
disconnect(SESSION_NOT_FOUND, "no displays found")
return
Expand All @@ -295,7 +296,8 @@ def disconnect(reason, *extras):
return
if display is None:
display = c.strget("display")
authlog("proxy_session: proxy-virtual-display=%s (ignored), user specified display=%s, found displays=%s", proxy_virtual_display, display, displays)
authlog("proxy_session: proxy-virtual-display=%s (ignored), user specified display=%s, found displays=%s",
proxy_virtual_display, display, displays)
if display==proxy_virtual_display:
disconnect(SESSION_NOT_FOUND, "invalid display")
return
Expand Down Expand Up @@ -387,7 +389,8 @@ def do_start_proxy():
client_conn.set_active(True)
process = ProxyInstanceProcess(uid, gid, env_options, session_options, self._socket_dir,
self.video_encoders, self.csc_modules,
client_conn, disp_desc, client_state, cipher, encryption_key, server_conn, c, message_queue)
client_conn, disp_desc, client_state,
cipher, encryption_key, server_conn, c, message_queue)
log("starting %s from pid=%s", process, os.getpid())
self.processes[process] = (display, message_queue)
process.start()
Expand Down Expand Up @@ -489,7 +492,11 @@ def start_win32_shadow(self, username, new_session_dict):
#hwinstaold = set_window_station("winsta0")
def exec_command(command):
log("exec_command(%s)", command)
from xpra.platform.win32.create_process_lib import Popen, CREATIONINFO, CREATION_TYPE_TOKEN, LOGON_WITH_PROFILE, CREATE_NEW_PROCESS_GROUP, STARTUPINFO
from xpra.platform.win32.create_process_lib import (
Popen,
CREATIONINFO, CREATION_TYPE_TOKEN,
LOGON_WITH_PROFILE, CREATE_NEW_PROCESS_GROUP, STARTUPINFO,
)
creation_info = CREATIONINFO()
creation_info.dwCreationType = CREATION_TYPE_TOKEN
creation_info.dwLogonFlags = LOGON_WITH_PROFILE
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/server/rfb/rfb_const.py
Expand Up @@ -310,7 +310,7 @@ class RFBAuth(object):
0xff9e : "KP_Insert",
0xff9c : "KP_End",
0xff9b : "KP_Down",
0xffb3 : "KP_Next",
#0xffb3 : "KP_Next",
0xff96 : "KP_Left",
0xff9d : "KP_Begin",
0xff98 : "KP_Right",
Expand Down
10 changes: 7 additions & 3 deletions src/xpra/server/rfb/rfb_protocol.py
Expand Up @@ -68,7 +68,8 @@ def _parse_protocol_handshake(self, packet):
return 0
#ie: packet==b'RFB 003.008\n'
self._protocol_version = tuple(int(x) for x in packet[4:11].split(b"."))
log.info("RFB version %s connection from %s", ".".join(str(x) for x in self._protocol_version), self._conn.target)
log.info("RFB version %s connection from %s",
".".join(str(x) for x in self._protocol_version), self._conn.target)
if self._protocol_version!=(3, 8):
msg = "unsupported protocol version"
log.error("Error: %s", msg)
Expand All @@ -91,7 +92,7 @@ def _parse_security_handshake(self, packet):
log("parse_security_handshake(%s)", hexstr(packet))
try:
auth = struct.unpack(b"B", packet)[0]
except:
except struct.error:
self._internal_error(packet, "cannot parse security handshake response '%s'" % hexstr(packet))
return 0
auth_str = RFBAuth.AUTH_STR.get(auth, auth)
Expand Down Expand Up @@ -145,7 +146,10 @@ def _parse_security_result(self, packet):
#send ClientInit
self._packet_parser = self._parse_rfb
w, h, bpp, depth, bigendian, truecolor, rmax, gmax, bmax, rshift, bshift, gshift = self._get_rfb_pixelformat()
packet = struct.pack(b"!HH"+PIXEL_FORMAT+b"I", w, h, bpp, depth, bigendian, truecolor, rmax, gmax, bmax, rshift, bshift, gshift, 0, 0, 0, len(self.session_name))+strtobytes(self.session_name)
packet = struct.pack(b"!HH"+PIXEL_FORMAT+b"I",
w, h, bpp, depth, bigendian, truecolor,
rmax, gmax, bmax, rshift, bshift, gshift,
0, 0, 0, len(self.session_name))+strtobytes(self.session_name)
self.send(packet)
self._process_packet_cb(self, [b"authenticated"])
return 1
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/server/rfb/rfb_server.py
Expand Up @@ -45,7 +45,7 @@ def _get_rfb_desktop_model(self):
if not models:
log.error("RFB: no window models to export, dropping connection")
return None
elif len(models)!=1:
if len(models)!=1:
log.error("RFB can only handle a single desktop window, found %i", len(self._window_to_id))
return None
return models[0]
Expand All @@ -69,7 +69,8 @@ def rfb_protocol_class(conn):
auth = None
if len(auths)==1:
auth = auths[0]
return RFBProtocol(self, conn, auth, self.process_rfb_packet, self.get_rfb_pixelformat, self.session_name or "Xpra Server")
return RFBProtocol(self, conn, auth,
self.process_rfb_packet, self.get_rfb_pixelformat, self.session_name or "Xpra Server")
p = self.do_make_protocol("rfb", conn, rfb_protocol_class)
p.send_protocol_handshake()

Expand Down
1 change: 1 addition & 0 deletions src/xpra/server/rfb/rfb_source.py
Expand Up @@ -11,6 +11,7 @@
from xpra.os_util import memoryview_to_bytes, strtobytes
from xpra.util import AtomicInteger
from xpra.log import Logger

log = Logger("rfb")

counter = AtomicInteger()
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/server/shadow/gtk_shadow_server_base.py
Expand Up @@ -246,7 +246,7 @@ def make_tray_widget(self):
try:
from xpra.client.gtk_base.statusicon_tray import GTKStatusIconTray
classes.append(GTKStatusIconTray)
except:
except ImportError:
traylog("no GTKStatusIconTray", exc_info=True)
traylog("tray classes: %s", classes)
if not classes:
Expand All @@ -255,7 +255,8 @@ def make_tray_widget(self):
errs = []
for c in classes:
try:
w = c(self, XPRA_APP_ID, self.tray, "Xpra Shadow Server", None, None, self.tray_click_callback, mouseover_cb=None, exit_cb=self.tray_exit_callback)
w = c(self, XPRA_APP_ID, self.tray, "Xpra Shadow Server",
None, None, self.tray_click_callback, mouseover_cb=None, exit_cb=self.tray_exit_callback)
return w
except Exception as e:
errs.append((c, e))
Expand Down

0 comments on commit f325ea9

Please sign in to comment.