(self, v)
Format a value.
Format a value.
Format a value .
def _fmt_json_value(self, v):
        "Format a value."
        if isinstance(v, self._basestring):
            # we assume utf8 so only some characters need to be escaed
            op = ['"']
            for c in v:
                if c == "\\":
                    op.append("\\\\")
                elif c == "\r":
                    op.append("\\r")
                elif c == "\n":
                    op.append("\\n")
                elif c == "\t":
                    op.append("\\t")
                elif c == "/":  # yes you have to escape forward slash for some reason
                    op.append("\\/")
                elif c == '"':
                    op.append("\\" + c)
                elif c == "\\b":
                    op.append("\\b")
                elif c == "\\f":
                    op.append("\\f")
                else:
                    # It isn't clear when \u sequences *must* be used.
                    # Assuming not needed due to utf8 output which
                    # corresponds to what rfc4627 implies.
                    op.append(c)
            op.append('"')
            return "".join(op)
        elif v is None:
            return 'null'
        elif isinstance(v, self._binary_type):
            if sys.version_info < (3, 0):
                o = base64.encodestring(v)
            else:
                o = base64.encodebytes(v).decode("ascii")
            if o[-1] == "\n":
                o = o[:-1]
            return '"' + o + '"'
        else:
            # number of some kind
            return '%s' % (v, )
def _fmt_json_value ( self , v ) : if isinstance ( v , self . _basestring ) : # we assume utf8 so only some characters need to be escaed op = [ '"' ] for c in v : if c == "\\" : op . append ( "\\\\" ) elif c == "\r" : op . append ( "\\r" ) elif c == "\n" : op . append ( "\\n" ) elif c == "\t" : op . append ( "\\t" ) elif c == "/" : # yes you have to escape forward slash for some reason op . append ( "\\/" ) elif c == '"' : op . append ( "\\" + c ) elif c == "\\b" : op . append ( "\\b" ) elif c == "\\f" : op . append ( "\\f" ) else : # It isn't clear when \u sequences *must* be used. # Assuming not needed due to utf8 output which # corresponds to what rfc4627 implies. op . append ( c ) op . append ( '"' ) return "" . join ( op ) elif v is None : return 'null' elif isinstance ( v , self . _binary_type ) : if sys . version_info < ( 3 , 0 ) : o = base64 . encodestring ( v ) else : o = base64 . encodebytes ( v ) . decode ( "ascii" ) if o [ - 1 ] == "\n" : o = o [ : - 1 ] return '"' + o + '"' else : # number of some kind return '%s' % ( v , )