# Path: tilenol/xcb/auth.py
# def read_auth(filename=os.path.expanduser("~/.Xauthority")):
#     def rstr():
#         val, = struct.unpack('>H', f.read(2))
#         return f.read(val)
#     with open(filename, 'rb') as f:
#         while True:
#             head = f.read(2)
#             if not head:
#                 break
#             family, = struct.unpack('<H', head)
#             yield Auth(family, rstr(), int(rstr()), rstr(), rstr())


import os.path
import socket
import re
import errno
import struct
import traceback
import logging
from math import ceil
from functools import partial
from collections import namedtuple, deque
from zorro import channel, Lock, gethub, Condition, Future
from zorro.util import setcloexec
from .auth import read_auth
                else:
                    ln = ln*4+32
                    if len(buf)-pos < ln:
                        break
                    val = buf[pos:pos+2] + buf[pos+8:pos+ln]
                    pos += ln
                self.produce(seq, val)


class Connection(object):

    def __init__(self, proto, display=None,
        auth_file=None, auth_type=None, auth_key=None):
        self.proto = proto
        if display is None:
            display = os.environ.get('DISPLAY', ':0')
        if auth_file is None and auth_type is None:
            auth_file = os.environ.get('XAUTHORITY')
            if auth_file is None:
                auth_file = os.path.expanduser('~/.XAuthority')
        host, port = display.split(':')
        if '.' in port:
            maj, min = map(int, port.split('.'))
        else:
            maj = int(port)
            min = 0
        assert min == 0, 'Subdisplays are not not supported so far'
        if auth_type is None:
            if host != "":
                haddr = socket.inet_aton(socket.gethostbyname(host))

# Path: tilenol/xcb/auth.py
# def read_auth(filename=os.path.expanduser("~/.Xauthority")):
#     def rstr():
#         val, = struct.unpack('>H', f.read(2))
#         return f.read(val)
#     with open(filename, 'rb') as f:
#         while True:
#             head = f.read(2)
#             if not head:
#                 break
#             family, = struct.unpack('<H', head)
#             yield Auth(family, rstr(), int(rstr()), rstr(), rstr())


# Path: tilenol/xcb/proto.py
import os.path
import socket
import re
import errno
import struct
import traceback
import logging
from math import ceil
from functools import partial
from collections import namedtuple, deque
from zorro import channel, Lock, gethub, Condition, Future
from zorro.util import setcloexec
from .auth import read_auth

                else:
                    ln = ln*4+32
                    if len(buf)-pos < ln:
                        break
                    val = buf[pos:pos+2] + buf[pos+8:pos+ln]
                    pos += ln
                self.produce(seq, val)


class Connection(object):

    def __init__(self, proto, display=None,
        auth_file=None, auth_type=None, auth_key=None):
        self.proto = proto
        if display is None:
            display = os.environ.get('DISPLAY', ':0')
        if auth_file is None and auth_type is None:
            auth_file = os.environ.get('XAUTHORITY')
            if auth_file is None:
                auth_file = os.path.expanduser('~/.XAuthority')
        host, port = display.split(':')
        if '.' in port:
            maj, min = map(int, port.split('.'))
        else:
            maj = int(port)
            min = 0
        assert min == 0, 'Subdisplays are not not supported so far'
        if auth_type is None:
            if host != "":
                haddr = socket.inet_aton(socket.gethostbyname(host))

            for auth in read_auth():