def makePrintable(data, charset, quote=None, to_unicode=False, smart=True):
 if data:
  if (not isinstance(data, unicode)):
   data = unicode(data, 'ISO-8859-1')
   charset = 'ASCII'
  data = regex_control_code.sub((lambda regs: controlchars[ord(regs.group(1))]), data)
  if quote:
   if (quote in '"\''):
    data = data.replace(quote, ('\\' + quote))
   data = ''.join((quote, data, quote))
 elif quote:
  data = '(empty)'
 data = data.encode(charset, 'backslashreplace')
 if smart:
  data = re.sub('\\\\x0([0-7])(?=[^0-7]|$)', '\\\\\\1', data)
 if to_unicode:
  data = unicode(data, charset)
 return data

def makePrintable ( data , charset , quote = None , to_unicode = False , smart = True ) : if data : if ( not isinstance ( data , unicode ) ) : data = unicode ( data , 'ISO-8859-1' ) charset = 'ASCII' data = regex_control_code . sub ( ( lambda regs : controlchars [ ord ( regs . group ( 1 ) ) ] ) , data ) if quote : if ( quote in '"\'' ) : data = data . replace ( quote , ( '\\' + quote ) ) data = '' . join ( ( quote , data , quote ) ) elif quote : data = '(empty)' data = data . encode ( charset , 'backslashreplace' ) if smart : data = re . sub ( '\\\\x0([0-7])(?=[^0-7]|$)' , '\\\\\\1' , data ) if to_unicode : data = unicode ( data , charset ) return data
prepare a string to make it printable in the specified charset .