|
37 | 37 | "isb", "generate_strings_from_regex", "get_alphabet_from_mask", "handle_error", "is_native", |
38 | 38 | "list_categories", "list_encodings", "list_macros", "lookup", "maketrans", "os", "rank", "re", "register", |
39 | 39 | "remove", "reset", "s2i", "search", "stopfunc", "BytesIO", "_input", "_stripl", "CodecMacro", |
40 | | - "DARWIN", "LANG", "LINUX", "MASKS", "PY3", "UNIX", "WINDOWS"] |
| 40 | + "ParameterError", "DARWIN", "LANG", "LINUX", "MASKS", "PY3", "UNIX", "WINDOWS"] |
41 | 41 | CODECS_REGISTRY = None |
42 | 42 | CODECS_OVERWRITTEN = [] |
43 | 43 | CODECS_CATEGORIES = ["native", "custom"] |
@@ -145,6 +145,9 @@ def __repr__(self): |
145 | 145 | return "<codext.CodecMacro object for encoding %s at %#x>" % (self.name, id(self)) |
146 | 146 |
|
147 | 147 |
|
| 148 | +class ParameterError(ValueError): |
| 149 | + __module__ = Exception.__module__ |
| 150 | + |
148 | 151 | # inspired from: https://stackoverflow.com/questions/10875442/possible-to-change-a-functions-repr-in-python |
149 | 152 | class Repr(object): |
150 | 153 | def __init__(self, name, func): |
@@ -908,7 +911,9 @@ def lookup(encoding, macro=True): |
908 | 911 | try: |
909 | 912 | return CodecMacro(encoding) |
910 | 913 | except LookupError: |
911 | | - raise LookupError("unknown encoding: %s" % encoding) |
| 914 | + e = LookupError("unknown encoding: %s" % encoding) |
| 915 | + e.__cause__ = e # stop exception chaining |
| 916 | + raise e |
912 | 917 | codecs.lookup = lookup |
913 | 918 |
|
914 | 919 |
|
|
0 commit comments