It's not that hard:
def escapeSpecialCharacters ( text, characters ):
for character in characters:
text = text.replace( character, '\\' + character )
return text
>>> escapeSpecialCharacters( 'I\'m "stuck" :\\', '\'"' )
'I\\\'m \\"stuck\\" :\\'
>>> print( _ )
I\'m \"stuck\" :\