Coverage for src/system/xauth.py: 100.00%

21 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-18 15:02 +0000

1#!/usr/bin/env python3 

2 

3# Standard libraries 

4from os import environ 

5from pathlib import Path 

6from subprocess import CalledProcessError, check_output, DEVNULL 

7 

8# Components 

9from ..system.platform import Platform 

10 

11# Xauth class 

12class Xauth: 

13 

14 # Members 

15 BINARY: str = 'xauth' 

16 

17 # Display 

18 @staticmethod 

19 def display() -> str: 

20 

21 # Variables 

22 result: str = '' 

23 

24 # Acquire display configuration 

25 if Platform.ENV_DISPLAY in environ: # pragma: no cover 

26 result = environ[Platform.ENV_DISPLAY] 

27 

28 # Result 

29 return result 

30 

31 # Magic 

32 @staticmethod 

33 def magic() -> str: 

34 

35 # Variables 

36 display: str 

37 result: str = '' 

38 xauthority_path: str = '' 

39 

40 # Acquire display configuration 

41 display = Xauth.display() 

42 

43 # Specific Xauthority path 

44 if environ.get(Platform.ENV_XAUTHORITY, '') and Path( 

45 environ[Platform.ENV_XAUTHORITY]).exists(): # pragma: no cover 

46 xauthority_path = environ[Platform.ENV_XAUTHORITY] 

47 

48 # Acquire Xauthority 

49 if Platform.IS_LINUX: 

50 try: 

51 result = check_output( 

52 [Xauth.BINARY] + ([ 

53 '-f', 

54 xauthority_path, 

55 ] if xauthority_path else []) + [ 

56 'list', 

57 display, 

58 ], 

59 shell=False, 

60 stderr=DEVNULL, 

61 ).strip().decode().splitlines()[0] 

62 except (CalledProcessError, FileNotFoundError): 

63 result = '' 

64 

65 # Result 

66 return result