'Format as a C string including surrounding double quotes'

def _fmt_c_string(self, v):

    if isinstance(v, self._basestring):
        op = ['"']
        for c in v:
            if (c == '\\'):
                op.append('\\\\')
            elif (c == '\r'):
                op.append('\\r')
            elif (c == '\n'):
                op.append('\\n')
            elif (c == ' DCTB '):
                op.append('\\t')
            elif (ord(c) not in self._printable):
                op.append(('\\' + c))
            else:
                op.append(c)
        op.append('"')
        return ''.join(op)
    elif (v is None):
        return (('"' + self.nullvalue) + '"')
    elif isinstance(v, self._binary_type):
        if (sys.version_info < (3, 0)):
            o = (lambda x: ord(x))
            fromc = (lambda x: x)
        else:
            o = (lambda x: x)
            fromc = (lambda x: chr(x))
        res = ['"']
        for c in v:
            if (o(c) in self._printable):
                res.append(fromc(c))
            else:
                res.append(('\\x%02X' % (o(c),)))
        res.append('"')
        return ''.join(res)
    else:
        return ('"%s"' % (v,))
