'Output the QR Code using ASCII characters.
:param tty: use fixed TTY color codes (forces invert=True)
:param invert: invert the ASCII characters (solid <-> transparent)'

def print_ascii(self, out=None, tty=False, invert=False):

    if (out is None):
        import sys
        if (sys.version_info < (2, 7)):
            import codecs
            out = codecs.getwriter(sys.stdout.encoding)(sys.stdout)
        else:
            out = sys.stdout
    if (tty and (not out.isatty())):
        raise OSError('Not    a    tty')
    if (self.data_cache is None):
        self.make()
    modcount = self.modules_count
    codes = [six.int2byte(code).decode('cp437') for code in (255, 223, 220, 219)]
    if tty:
        invert = True
    if invert:
        codes.reverse()
    def get_module(x, y):
        if (invert and self.border and (max(x, y) >= (modcount + self.border))):
            return 1
        if ((min(x, y) < 0) or (max(x, y) >= modcount)):
            return 0
        return self.modules[x][y]
    for r in range((- self.border), (modcount + self.border), 2):
        if tty:
            if ((not invert) or (r < ((modcount + self.border) - 1))):
                out.write('\x1b[48;5;232m')
            out.write('\x1b[38;5;255m')
        for c in range((- self.border), (modcount + self.border)):
            pos = (get_module(r, c) + (get_module((r + 1), c) << 1))
            out.write(codes[pos])
        if tty:
            out.write('\x1b[0m')
        out.write('\n')
    out.flush()
