'Initializes and opens a socket. Performs authentication if needed.'

def connect(self):

    if self._path:
        self._s = lsocket(socket.AF_UNIX)
        self._s.settimeout(self._timeout)
        self._s.connect(self._path)
    else:
        ai = socket.getaddrinfo(self._host, self._port, 0, socket.SOCK_STREAM)[0]
        self._s = lsocket(ai[0], ai[1], ai[2])
        self._s.settimeout(self._timeout)
        self._s.connect((self._host, self._port))
    if (self._s.peekb(len(PASSWORD_PROMPT)) == PASSWORD_PROMPT):
        self._s.recvb(len(PASSWORD_PROMPT))
        self._s.sendl(self._password)
        if (self._s.peekb(len(PASSWORD_PROMPT)) == PASSWORD_PROMPT):
            self._s.recvb(len(PASSWORD_PROMPT))
            raise Exception('Authentication    error')
        else:
            self._s.recvl()
