def escapeString(string):
 toEscapeChars = ['\\', '(', ')']
 escapedValue = ''
 for i in range(len(string)):
  if ((string[i] in toEscapeChars) and ((i == 0) or (string[(i - 1)] != '\\'))):
   if (string[i] == '\\'):
    if ((len(string) > (i + 1)) and re.match('[0-7]', string[(i + 1)])):
     escapedValue += string[i]
    else:
     escapedValue += ('\\' + string[i])
   else:
    escapedValue += ('\\' + string[i])
  elif (string[i] == '\r'):
   escapedValue += '\\r'
  elif (string[i] == '\n'):
   escapedValue += '\\n'
  elif (string[i] == ' DCTB '):
   escapedValue += '\\t'
  elif (string[i] == '\x08'):
   escapedValue += '\\b'
  elif (string[i] == '\x0c'):
   escapedValue += '\\f'
  else:
   escapedValue += string[i]
 return escapedValue

def escapeString ( string ) : toEscapeChars = [ '\\' , '(' , ')' ] escapedValue = '' for i in range ( len ( string ) ) : if ( ( string [ i ] in toEscapeChars ) and ( ( i == 0 ) or ( string [ ( i - 1 ) ] != '\\' ) ) ) : if ( string [ i ] == '\\' ) : if ( ( len ( string ) > ( i + 1 ) ) and re . match ( '[0-7]' , string [ ( i + 1 ) ] ) ) : escapedValue += string [ i ] else : escapedValue += ( '\\' + string [ i ] ) else : escapedValue += ( '\\' + string [ i ] ) elif ( string [ i ] == '\r' ) : escapedValue += '\\r' elif ( string [ i ] == '\n' ) : escapedValue += '\\n' elif ( string [ i ] == ' DCTB ' ) : escapedValue += '\\t' elif ( string [ i ] == '\x08' ) : escapedValue += '\\b' elif ( string [ i ] == '\x0c' ) : escapedValue += '\\f' else : escapedValue += string [ i ] return escapedValue
escape the given string .