Skip to content

Commit

Permalink
#3930 replace HideStdErr with redirect_stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 28, 2023
1 parent ae90878 commit c99cdc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions xpra/server/source/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ def do_shell_exec(self, code) -> tuple[str,str]:
}
stdout = io.StringIO()
stderr = io.StringIO()
with redirect_stdout(stdout):
with redirect_stderr(stderr):
exec(code, _globals, {}) #pylint: disable=exec-used
with redirect_stdout(stdout), redirect_stderr(stderr):
exec(code, _globals, {}) #pylint: disable=exec-used
return stdout.getvalue(), stderr.getvalue()
except Exception as e:
log("shell_exec(..)", exc_info=True)
Expand Down
19 changes: 10 additions & 9 deletions xpra/x11/bindings/xwayland.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# later version. See the file COPYING for details.

import os
from xpra.os_util import HideStdErr
from io import StringIO
from contextlib import redirect_stderr
from xpra.x11.bindings.xlib cimport (
Success,
Display, Window, Atom, Status,
Expand All @@ -25,23 +26,23 @@ def isX11(display_name : str=os.environ.get("DISPLAY", "")):
b = display_name.encode()
cdef char* display = b
cdef Display *d = NULL
with HideStdErr():
with redirect_stderr(StringIO()) as f:
d = XOpenDisplay(display)
if not d:
log(f"isX11({display_name}) cannot open display")
return False
if not d:
log(f"isX11({display_name}) cannot open display: %s", f.getvalue())
return False
return True


def isxwayland(display_name : str=os.environ.get("DISPLAY", "")):
b = display_name.encode()
cdef char* display = b
cdef Display *d = NULL
with HideStdErr():
with redirect_stderr(StringIO()) as f:
d = XOpenDisplay(display)
if not d:
log(f"isxwayland({display_name}) cannot open display")
return False
if not d:
log(f"isxwayland({display_name}) cannot open display: %s", f.getvalue())
return False
cdef int opcode, event, error
try:
#the easy way:
Expand Down

0 comments on commit c99cdc6

Please sign in to comment.