Skip to content

Commit

Permalink
Merge pull request #3 from Viagenie/release-1.1
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
jumpifnotzero authored Jan 4, 2021
2 parents 155a826 + 46bcc30 commit 85d7f25
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -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).
- Support of Unicode up to 10.0.0 (ICU up to release 60).
16 changes: 9 additions & 7 deletions picu/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions picu/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _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)))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="picu",
version='1.0',
version='1.1',
author="Wil Tan",
author_email="[email protected]",
description="Python ctypes-based ICU Wrapper",
Expand Down

0 comments on commit 85d7f25

Please sign in to comment.