def encodeOrFail(S): try: return S.encode('utf-8') except: return S def decodeOrFail(S): try: return S.decode('utf-8') except: return S