Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def configure(window):
window.configure(
width=100,
height=100,
x=0,
y=0,
border_width=1,
)
for i in range(20):
try:
conn = xcffib.connect(display=sys.argv[1])
except xcffib.ConnectionException:
time.sleep(0.1)
continue
except Exception as v:
print("Error opening test window: ", type(v), v, file=sys.stderr)
sys.exit(1)
break
else:
print("Could not open window on display %s" % (sys.argv[1]), file=sys.stderr)
sys.exit(1)
screen = conn.get_setup().roots[conn.pref_screen]
window = conn.generate_id()
background = conn.core.AllocColor(screen.default_colormap, 0x2828, 0x8383, 0xCECE).reply().pixel # Color "#2883ce"
conn.core.CreateWindow(xcffib.CopyFromParent, window, screen.root,
100, 100, 100, 100, 1,
if verbose:
xproc = subprocess.Popen(argv)
else:
with open(os.devnull, 'w') as devnull:
xproc = subprocess.Popen(argv,
stderr=subprocess.STDOUT, stdout=devnull)
# Wait for the process to die, start accepting connections, or for
# 5 seconds to pass
# TODO: Refactor to be cleaner
started = time.time()
while xproc.poll() is None and (time.time() - started < 5):
try:
conn = xcffib.connect(display=':%d' % display_num,
auth=b'MIT-MAGIC-COOKIE-1:' + magic_cookie)
except xcffib.ConnectionException:
time.sleep(0.1) # Limit spinning when the server is slow to start
continue
else:
if not xproc.poll():
conn.disconnect()
log.debug("X server on :%d accepting connections", display_num)
return xproc
if (time.time() - started) > 5:
log.warning("Timed out while waiting for X server")
if xproc.poll() is None:
return xproc
if xproc.returncode == 1 and os.path.exists(lock_path):
log.debug("Race condition on display number %d", display_num)
return None
def test_new_window(xdisplay):
conn = xcbq.Connection(xdisplay)
win = conn.create_window(1, 2, 640, 480)
assert isinstance(win, xcbq.Window)
geom = win.get_geometry()
assert geom.x == 1
assert geom.y == 2
assert geom.width == 640
assert geom.height == 480
win.kill_client()
with pytest.raises(xcffib.ConnectionException):
win.get_geometry()
def _waitForXephyr(self):
# Wait until Xephyr process dies
while self.xephyr.poll() is None:
try:
conn = xcffib.connect(self.display)
break
except xcffib.ConnectionException:
pass
time.sleep(0.1)
else:
(stdout_data, stderr_data) = self.xephyr.communicate()
raise AssertionError("Error launching Xephyr, quit with return code: {:d}\n"
"stderr: {}\n"
"stdout: {}".format(
self.xephyr.returncode,
stderr_data.decode(),
stdout_data.decode()
)
)
conn.disconnect()
del conn
def x_reader(conn, callback):
'''Try reading something from X connection to check if it's still alive.
In case it isn't, call *callback*.
'''
try:
conn.poll_for_event()
except xcffib.ConnectionException:
callback()