Author: Matti Picus <[email protected]>
Branch: py3.6
Changeset: r98053:2769fb7dff63
Date: 2019-11-14 14:59 -0700
http://bitbucket.org/pypy/pypy/changeset/2769fb7dff63/

Log:    catch an OSError raised when {en,de}coding with a codepage

diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -5,7 +5,7 @@
 from rpython.rlib.rutf8 import MAXUNICODE
 from rpython.rlib import runicode
 
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.interpreter import unicodehelper
 from pypy.module.unicodedata.interp_ucd import unicodedb
@@ -727,9 +727,12 @@
             allow_surrogates = True
         state = space.fromcache(CodecState)
         ulen = w_arg._length
-        result = unicodehelper.utf8_encode_code_page(code_page, w_arg._utf8,
+        try:
+            result = unicodehelper.utf8_encode_code_page(code_page, 
w_arg._utf8,
                       errors, state.encode_error_handler,
                       allow_surrogates=allow_surrogates)
+        except OSError as e:
+            raise wrap_oserror(space, e)
         return space.newtuple([space.newbytes(result), space.newint(ulen)])
 
     @unwrap_spec(code_page=int, string='bufferstr', errors='text_or_none',
@@ -742,9 +745,12 @@
             errors = 'strict'
         final = space.is_true(w_final)
         state = space.fromcache(CodecState)
-        result, length, pos = unicodehelper.str_decode_code_page(code_page,
+        try:
+            result, length, pos = unicodehelper.str_decode_code_page(code_page,
                                    string, errors, final,
                                    state.decode_error_handler)
+        except OSError as e:
+            raise wrap_oserror(space, e)
         # must return bytes, pos
         return space.newtuple([space.newutf8(result, length), 
space.newint(pos)])
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to