From 71ebd4b7f0b88fc0ceb36d8c2464a5114470f5a0 Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Mon, 23 Feb 2015 23:18:36 +0200
Subject: [PATCH] py: Implement UnicodeError.

Still too shy to implement UnicodeEncodeError which was really needed for
micropython-lib case.
---
 py/modbuiltins.c | 3 +++
 py/obj.h         | 1 +
 py/objexcept.c   | 6 +++++-
 py/qstrdefs.h    | 3 +++
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 594f385f4..c7323afaa 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -683,6 +683,9 @@ STATIC const mp_map_elem_t mp_module_builtins_globals_table[] = {
     { MP_OBJ_NEW_QSTR(MP_QSTR_SyntaxError), (mp_obj_t)&mp_type_SyntaxError },
     { MP_OBJ_NEW_QSTR(MP_QSTR_SystemExit), (mp_obj_t)&mp_type_SystemExit },
     { MP_OBJ_NEW_QSTR(MP_QSTR_TypeError), (mp_obj_t)&mp_type_TypeError },
+    #if MICROPY_PY_BUILTINS_STR_UNICODE
+    { MP_OBJ_NEW_QSTR(MP_QSTR_UnicodeError), (mp_obj_t)&mp_type_UnicodeError },
+    #endif
     { MP_OBJ_NEW_QSTR(MP_QSTR_ValueError), (mp_obj_t)&mp_type_ValueError },
     { MP_OBJ_NEW_QSTR(MP_QSTR_ZeroDivisionError), (mp_obj_t)&mp_type_ZeroDivisionError },
     // Somehow CPython managed to have OverflowError not inherit from ValueError ;-/
diff --git a/py/obj.h b/py/obj.h
index 3a9a6431c..db42e795a 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -369,6 +369,7 @@ extern const mp_obj_type_t mp_type_StopIteration;
 extern const mp_obj_type_t mp_type_SyntaxError;
 extern const mp_obj_type_t mp_type_SystemExit;
 extern const mp_obj_type_t mp_type_TypeError;
+extern const mp_obj_type_t mp_type_UnicodeError;
 extern const mp_obj_type_t mp_type_ValueError;
 extern const mp_obj_type_t mp_type_ZeroDivisionError;
 
diff --git a/py/objexcept.c b/py/objexcept.c
index 858804d0b..824c9b0ad 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -249,7 +249,11 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
   //MP_DEFINE_EXCEPTION(SystemError, Exception)
   MP_DEFINE_EXCEPTION(TypeError, Exception)
   MP_DEFINE_EXCEPTION(ValueError, Exception)
-    //TODO: Implement UnicodeErrors which take arguments
+#if MICROPY_PY_BUILTINS_STR_UNICODE
+    MP_DEFINE_EXCEPTION_BASE(ValueError)
+    MP_DEFINE_EXCEPTION(UnicodeError, ValueError)
+    //TODO: Implement more UnicodeError subclasses which take arguments
+#endif
   /*
   MP_DEFINE_EXCEPTION(Warning, Exception)
     MP_DEFINE_EXCEPTION_BASE(Warning)
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 77514f521..88c0d5a3e 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -137,6 +137,9 @@ Q(TypeError)
 Q(UnboundLocalError)
 Q(ValueError)
 Q(ZeroDivisionError)
+#if MICROPY_PY_BUILTINS_STR_UNICODE
+Q(UnicodeError)
+#endif
 
 Q(None)
 Q(False)
-- 
GitLab