Ejemplo n.º 1
0
def XConnect():

    name, host, displayno, screenno = xnet.get_X_display()
    xsock = xnet.get_X_socket(host, displayno)
    auth_name, auth_data = xnet.get_X_auth(xsock, name, host, displayno)
    byte_order = xnet.get_X_byteorder()

    rq = XConnectRequest(byte_order, 11, 0, auth_name, auth_data)

    xreply = Xchange(xsock, rq)

    if xreply[0] == '\x00':
        repobj = XConnectRefusedReply(xreply)
        raise xnet.XConnectionError(repobj.reason)

    elif xreply[0] == '\x01':
        repobj = XConnectAcceptedReply(xreply)

    elif xreply[0] == '\x02':
        repobj = XConnectAuthenticateReply(xreply)
        raise xnet.XConnectionError(repobj.reason)

    else:
        raise xnet.XConnectionError('Unknown connection failure')

    return xsock, repobj
Ejemplo n.º 2
0
def Xchange(xsock, rq):
    xreply = ''
    try:
        xsock.send(rq.encoding)
        xreply = xsock.recv(65535)  # TODO make sure it fits

    except socket.error, err:
        raise xnet.XConnectionError('Network error: %s' % err[1])