def escape_filter_chars(assertion_value, escape_mode=0):
 if escape_mode:
  r = []
  if (escape_mode == 1):
   for c in assertion_value:
    if ((c < '0') or (c > 'z') or (c in '\\*()')):
     c = ('\\%02x' % ord(c))
    r.append(c)
  elif (escape_mode == 2):
   for c in assertion_value:
    r.append(('\\%02x' % ord(c)))
  else:
   raise ValueError('escape_mode must be 0, 1 or 2.')
  s = ''.join(r)
 else:
  s = assertion_value.replace('\\', '\\5c')
  s = s.replace('*', '\\2a')
  s = s.replace('(', '\\28')
  s = s.replace(')', '\\29')
  s = s.replace('\x00', '\\00')
 return s

def escape_filter_chars ( assertion_value , escape_mode = 0 ) : if escape_mode : r = [ ] if ( escape_mode == 1 ) : for c in assertion_value : if ( ( c < '0' ) or ( c > 'z' ) or ( c in '\\*()' ) ) : c = ( '\\%02x' % ord ( c ) ) r . append ( c ) elif ( escape_mode == 2 ) : for c in assertion_value : r . append ( ( '\\%02x' % ord ( c ) ) ) else : raise ValueError ( 'escape_mode must be 0, 1 or 2.' ) s = '' . join ( r ) else : s = assertion_value . replace ( '\\' , '\\5c' ) s = s . replace ( '*' , '\\2a' ) s = s . replace ( '(' , '\\28' ) s = s . replace ( ')' , '\\29' ) s = s . replace ( '\x00' , '\\00' ) return s
replace all special characters found in assertion_value by quoted notation .