def __init__(self, filename = None): if filename is None: filename = os.environ.get('XAUTHORITY') if filename is None: try: filename = os.path.join(os.environ['HOME'], '.Xauthority') except KeyError: raise error.XauthError( '$HOME not set, cannot find ~/.Xauthority') try: raw = open(filename, 'rb').read() except OSError as err: raise error.XauthError('~/.Xauthority: %s' % err) self.entries = [] # entry format (all shorts in big-endian) # short family; # short addrlen; # char addr[addrlen]; # short numlen; # char num[numlen]; # short namelen; # char name[namelen]; # short datalen; # char data[datalen]; n = 0 try: while n < len(raw): family, = struct.unpack('>H', raw[n:n+2]) n = n + 2 length, = struct.unpack('>H', raw[n:n+2]) n = n + length + 2 addr = raw[n - length : n] length, = struct.unpack('>H', raw[n:n+2]) n = n + length + 2 num = raw[n - length : n] length, = struct.unpack('>H', raw[n:n+2]) n = n + length + 2 name = raw[n - length : n] length, = struct.unpack('>H', raw[n:n+2]) n = n + length + 2 data = raw[n - length : n] if len(data) != length: break self.entries.append((family, addr, num, name, data, )) except struct.error as e: print("Xlib.xauth: warning, failed to parse part of xauthority file (%s), aborting all further parsing" % filename) if len(self.entries) == 0: print("Xlib.xauth: warning, no xauthority details available")
def __init__(self, filename=None): if filename is None: filename = os.environ.get('XAUTHORITY') if filename is None: try: filename = os.path.join(os.environ['HOME'], '.Xauthority') except KeyError: raise error.XauthError( '$HOME not set, cannot find ~/.Xauthority') try: raw = open(filename, 'rb').read() except IOError, err: raise error.XauthError('~/.Xauthority: %s' % err)