# 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
                socket.SOCK_STREAM, socket.IPPROTO_TCP)
        setcloexec(self._sock)
        self._sock.setblocking(0)
        try:
            if unixsock:
                self._sock.connect(unixsock)
            else:
                self._sock.connect((host, port))
        except socket.error as e:
            if e.errno == errno.EINPROGRESS:
                gethub().do_write(self._sock)
            else:
                raise
        self._start()

    def connect(self, auth_type, auth_key):
        buf = bytearray()
        buf.extend(struct.pack('<BxHHHH2x',
            0o154, #little endian
            self.MAJOR_VERSION,
            self.MINOR_VERSION,
            len(auth_type),
            len(auth_key)))
        if isinstance(auth_type, str):
            auth_type = auth_type.encode('ascii')
        buf.extend(auth_type)
        buf.extend(b'\x00'*(4 - len(auth_type) % 4))
        buf.extend(auth_key)
        return self.request(buf, None).get()


# 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

                socket.SOCK_STREAM, socket.IPPROTO_TCP)
        setcloexec(self._sock)
        self._sock.setblocking(0)
        try:
            if unixsock:
                self._sock.connect(unixsock)
            else:
                self._sock.connect((host, port))
        except socket.error as e:
            if e.errno == errno.EINPROGRESS:
                gethub().do_write(self._sock)
            else:
                raise
        self._start()

    def connect(self, auth_type, auth_key):
        buf = bytearray()
        buf.extend(struct.pack('<BxHHHH2x',
            0o154, #little endian
            self.MAJOR_VERSION,
            self.MINOR_VERSION,
            len(auth_type),
            len(auth_key)))
        if isinstance(auth_type, str):
            auth_type = auth_type.encode('ascii')
        buf.extend(auth_type)
        buf.extend(b'\x00'*(4 - len(auth_type) % 4))
        buf.extend(auth_key)
        return self.request(buf, None).get()


    def request(self, input, reply):