def clean_ascii_chars(txt, charlist=None):
 if (not txt):
  return ''
 global _ascii_pat
 if (_ascii_pat is None):
  chars = set(xrange(32))
  chars.add(127)
  for x in (9, 10, 13):
   chars.remove(x)
  _ascii_pat = re.compile(u'|'.join(map(unichr, chars)))
 if (charlist is None):
  pat = _ascii_pat
 else:
  pat = re.compile(u'|'.join(map(unichr, charlist)))
 return pat.sub('', txt)

def clean_ascii_chars ( txt , charlist = None ) : if ( not txt ) : return '' global _ascii_pat if ( _ascii_pat is None ) : chars = set ( xrange ( 32 ) ) chars . add ( 127 ) for x in ( 9 , 10 , 13 ) : chars . remove ( x ) _ascii_pat = re . compile ( u'|' . join ( map ( unichr , chars ) ) ) if ( charlist is None ) : pat = _ascii_pat else : pat = re . compile ( u'|' . join ( map ( unichr , charlist ) ) ) return pat . sub ( '' , txt )
remove ascii control chars .