Changeset 4338:b9187f8ba0ff in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/14/11 16:58:42 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Escape backspace and all other control characters.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/misc.py

    r4337 r4338  
    516516    elif isinstance(obj, basestring): 
    517517        v = [] 
    518         specialchars = {u"\r": u"\\r", u"\n": u"\\n", u"\t": u"\\t", u"\f": u"\\f", u'"': u'\\"', u"\\": u"\\\\"} 
     518        specialchars = {u"\r": u"\\r", u"\n": u"\\n", u"\t": u"\\t", u"\f": u"\\f", u"\b": u"\\b", u'"': u'\\"', u"\\": u"\\\\"} 
    519519        for c in obj: 
    520520            try: 
     
    522522            except KeyError: 
    523523                oc = ord(c) 
    524                 v.append(u"\\u{:04x}".format(oc) if oc >= 128 else c) 
     524                v.append(u"\\u{:04x}".format(oc) if oc >= 128 or oc <= 31 else c) 
    525525        return u'"{}"'.format(u"".join(v)) 
    526526    elif isinstance(obj, datetime.datetime): # check ``datetime`` before ``date``, as ``datetime`` is a subclass of ``date``