Skip to content

Commit

Permalink
py3k strings byte us again, also simplify error handling and fix pyli…
Browse files Browse the repository at this point in the history
…nt warnings

git-svn-id: https://xpra.org/svn/Xpra/trunk@21923 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 1, 2019
1 parent 00f1405 commit 33fe842
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/xpra/platform/displayfd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# This file is part of Xpra.
# Copyright (C) 2017-2018 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2017-2019 Antoine Martin <antoine@xpra.org>
# 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 os

from xpra.os_util import monotonic_time
from xpra.os_util import monotonic_time, strtobytes
from xpra.util import envint

DISPLAY_FD_TIMEOUT = envint("XPRA_DISPLAY_FD_TIMEOUT", 20)


def eerrno(e):
try:
#python3:
Expand All @@ -21,19 +22,16 @@ def eerrno(e):
def write_displayfd(w_pipe, display, timeout=10):
import select #@UnresolvedImport
import errno
buf = b"%s\n" % display
buf = b"%s\n" % strtobytes(display)
limit = monotonic_time()+timeout
while buf and monotonic_time()<limit:
try:
timeout = max(0, limit-monotonic_time())
_, w, _ = select.select([], [w_pipe], [], timeout)
w = select.select([], [w_pipe], [], timeout)[1]
if w_pipe in w:
count = os.write(w_pipe, buf)
buf = buf[count:]
except select.error as e:
if eerrno(e)!=errno.EINTR:
raise
except (OSError, IOError) as e:
except (select.error, OSError, IOError) as e:
if eerrno(e)!=errno.EINTR:
raise
return len(buf)==0
Expand All @@ -48,29 +46,26 @@ def read_displayfd(r_pipe, timeout=DISPLAY_FD_TIMEOUT, proc=None):
while monotonic_time()<limit and len(buf)<8 and (proc is None or proc.poll() is None):
try:
timeout = max(0, limit-monotonic_time())
r, _, _ = select.select([r_pipe], [], [], timeout)
r = select.select([r_pipe], [], [], timeout)[0]
if r_pipe in r:
buf += os.read(r_pipe, 8)
if buf and (buf[-1]==b'\n' or len(buf)>=8):
break
except select.error as e:
if eerrno(e)!=errno.EINTR:
raise
except (OSError, IOError) as e:
except (select.error, OSError, IOError) as e:
if eerrno(e)!=errno.EINTR:
raise
return buf

def parse_displayfd(buf, err):
if len(buf) == 0:
if not buf:
err("did not provide a display number using displayfd")
return None
if buf[-1] not in (b'\n', ord(b"\n")):
err("output not terminated by newline: %s" % buf)
return None
try:
n = int(buf[:-1])
except:
except ValueError:
err("display number is not a valid number: %s" % buf[:-1])
if n<0 or n>=2**16:
err("provided an invalid display number: %s" % n)
Expand Down

0 comments on commit 33fe842

Please sign in to comment.