From c189417aef2371efc988b945c5e81611c6dce229 Mon Sep 17 00:00:00 2001 From: Julien BERNARD Date: Wed, 11 Nov 2020 15:44:45 -0500 Subject: [PATCH 1/3] When raising IDNAException add label on which exception occured --- picu/loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/picu/loader.py b/picu/loader.py index 088cc65..8997043 100644 --- a/picu/loader.py +++ b/picu/loader.py @@ -833,7 +833,7 @@ def idna_process(self, s, func, _lowlvl_func, uidna=None): if idna_info.errors == 0: return uchar_array_to_uni(dest[:rv]) else: - raise IDNAException(idna_info.errors, _lowlvl_func.__name__ + ': ') + raise IDNAException(idna_info.errors, "%s on %s:" % (_lowlvl_func.__name__, s)) elif err.value != U_BUFFER_OVERFLOW_ERROR: raise PICUException("%s failed with error code %d (%s)" % (_lowlvl_func, err.value, self.u_errorName(err))) From 85d2a675ca84a1f2203753742dbc6c2e4b98d0f1 Mon Sep 17 00:00:00 2001 From: Julien BERNARD Date: Fri, 27 Nov 2020 11:40:46 -0500 Subject: [PATCH 2/3] Add more information to IDNA exceptions to be able to get clearer debug --- picu/exceptions.py | 16 +++++++++------- picu/loader.py | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/picu/exceptions.py b/picu/exceptions.py index 726d7d7..4440488 100644 --- a/picu/exceptions.py +++ b/picu/exceptions.py @@ -14,19 +14,21 @@ class PropertyNotFound(PICUException): class IDNAException(PICUException, UnicodeError): - ERROR_MESSAGES = dict((getattr(constants, e), e) for e in dir(constants) if e.startswith('UIDNA_ERROR_')) + ERROR_MESSAGES = dict( + (getattr(constants, e), e) for e in dir(constants) if e.startswith('UIDNA_ERROR_')) - def __init__(self, idna_errors, msgprefix, *args): + def __init__(self, idna_errors, obj, msgprefix, *args): self.idna_errors = idna_errors + self.error_labels = [] + self.obj = obj # parse IDNA error codes - err_labels = [] for ecode, elabel in self.ERROR_MESSAGES.items(): if idna_errors & ecode: - err_labels.append(elabel) + self.error_labels.append(elabel) idna_errors = idna_errors & ~ecode if idna_errors: - err_labels.append("UNKNOWN_ERROR-%s" % idna_errors) - - super(IDNAException, self).__init__("%s%s" % (msgprefix, ', '.join(err_labels)), *args) + self.error_labels.append("UNKNOWN_ERROR-%s" % idna_errors) + super(IDNAException, self).__init__("%s%s" % (msgprefix, ', '.join(self.error_labels)), + *args) diff --git a/picu/loader.py b/picu/loader.py index 8997043..f0e82fb 100644 --- a/picu/loader.py +++ b/picu/loader.py @@ -833,7 +833,7 @@ def idna_process(self, s, func, _lowlvl_func, uidna=None): if idna_info.errors == 0: return uchar_array_to_uni(dest[:rv]) else: - raise IDNAException(idna_info.errors, "%s on %s:" % (_lowlvl_func.__name__, s)) + raise IDNAException(idna_info.errors, s, _lowlvl_func.__name__ + ': ') elif err.value != U_BUFFER_OVERFLOW_ERROR: raise PICUException("%s failed with error code %d (%s)" % (_lowlvl_func, err.value, self.u_errorName(err))) @@ -845,7 +845,7 @@ def idna_process(self, s, func, _lowlvl_func, uidna=None): if idna_info.errors == 0: return uchar_array_to_uni(dest[:rv]) else: - raise IDNAException(idna_info.errors, func.__name__ + ': ') + raise IDNAException(idna_info.errors, s, func.__name__ + ': ') def idna_encode_label(self, s, uidna=None): return self.idna_process(s, self.uidna_labelToASCII, self._uidna_labelToASCII, uidna) From 46bcc30431e4b0ffc204272539d78c116853eb3d Mon Sep 17 00:00:00 2001 From: Julien BERNARD Date: Fri, 18 Dec 2020 15:18:56 -0500 Subject: [PATCH 3/3] Prepare 1.1 release --- Changelog.md | 6 +++++- setup.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index e57ee94..58ee226 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,10 @@ # Changelog for picu +## 1.1 (2020-12-04) +### New features +- Add more debug information in IDNA exceptions + ## 1.0 (2018-09-06) ### New features - Support of Python 3. Compatibility with python2 is preserved for this release. -- Support of Unicode up to 10.0.0 (ICU up to release 60). \ No newline at end of file +- Support of Unicode up to 10.0.0 (ICU up to release 60). diff --git a/setup.py b/setup.py index c0e7d3e..2401ea8 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name="picu", - version='1.0', + version='1.1', author="Wil Tan", author_email="wil@cloudregistry.net", description="Python ctypes-based ICU Wrapper",