Commits

Philip Jenvey committed 4739822

raw_unicode_escape_decode accepts unicode

Comments (0)

Files changed (2)

pypy/module/_codecs/interp_codecs.py

          "utf_32_decode",
          "utf_32_be_decode",
          "utf_32_le_decode",
-         "raw_unicode_escape_decode",
          ]:
     make_decoder_wrapper(decoders)
 
     return space.newtuple([space.wrap(result), space.wrap(consumed)])
 
 # ____________________________________________________________
+# Raw Unicode escape (accepts bytes or str)
+
+@unwrap_spec(string='bufferstr_or_u', errors='str_or_None',
+             w_final=WrappedDefault(False))
+def raw_unicode_escape_decode(space, string, errors="strict", w_final=None):
+    if errors is None:
+        errors = 'strict'
+    final = space.is_true(w_final)
+    state = space.fromcache(CodecState)
+    result, consumed = runicode.str_decode_raw_unicode_escape(
+        string, len(string), errors,
+        final, state.decode_error_handler)
+    return space.newtuple([space.wrap(result), space.wrap(consumed)])
+
+# ____________________________________________________________
 # Unicode-internal
 
 @unwrap_spec(errors='str_or_None')

pypy/module/_codecs/test/test_codecs.py

         assert bytes.decode("unicode_internal") == "a"
 
     def test_raw_unicode_escape(self):
+        import _codecs
         assert str(b"\u0663", "raw-unicode-escape") == "\u0663"
         assert "\u0663".encode("raw-unicode-escape") == b"\u0663"
+        assert _codecs.raw_unicode_escape_decode(r"\u1234") == ("\u1234", 6)
 
     def test_escape_decode(self):
         import _codecs