(u)
return u
Fix invalid symbols in unicode string.
Fix invalid symbols in unicode string.
Fix invalid symbols in unicode string .
def sanitize_unicode(u):
    """Fix invalid symbols in unicode string."""
    global _urc

    assert isinstance(u, unicode)

    # regex for finding invalid chars, works on unicode string
    if not _urc:
        rx = u"[\uD800-\uDBFF] [\uDC00-\uDFFF]? | [\0\uDC00-\uDFFF]"
        _urc = re.compile(rx, re.X)

    # now find and fix UTF16 surrogates
    m = _urc.search(u)
    if m:
        u = _urc.sub(_fix_utf8, u)
    return u
def sanitize_unicode ( u ) : global _urc assert isinstance ( u , unicode ) # regex for finding invalid chars, works on unicode string if not _urc : rx = u"[\uD800-\uDBFF] [\uDC00-\uDFFF]? | [\0\uDC00-\uDFFF]" _urc = re . compile ( rx , re . X ) # now find and fix UTF16 surrogates m = _urc . search ( u ) if m : u = _urc . sub ( _fix_utf8 , u ) return u