codekingpro/portable-devtools
114k
1#2# This file is part of pyasn1 software.3#4# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>5# License: https://pyasn1.readthedocs.io/en/latest/license.html6#7 8 9class PyAsn1Error(Exception):10 """Base pyasn1 exception11 12 `PyAsn1Error` is the base exception class (based on13 :class:`Exception`) that represents all possible ASN.1 related14 errors.15 16 Parameters17 ----------18 args:19 Opaque positional parameters20 21 Keyword Args22 ------------23 kwargs:24 Opaque keyword parameters25 26 """27 def __init__(self, *args, **kwargs):28 self._args = args29 self._kwargs = kwargs30 31 @property32 def context(self):33 """Return exception context34 35 When exception object is created, the caller can supply some opaque36 context for the upper layers to better understand the cause of the37 exception.38 39 Returns40 -------41 : :py:class:`dict`42 Dict holding context specific data43 """44 return self._kwargs.get('context', {})45 46 47class ValueConstraintError(PyAsn1Error):48 """ASN.1 type constraints violation exception49 50 The `ValueConstraintError` exception indicates an ASN.1 value51 constraint violation.52 53 It might happen on value object instantiation (for scalar types) or on54 serialization (for constructed types).55 """56 57 58class SubstrateUnderrunError(PyAsn1Error):59 """ASN.1 data structure deserialization error60 61 The `SubstrateUnderrunError` exception indicates insufficient serialised62 data on input of a de-serialization codec.63 """64 65 66class EndOfStreamError(SubstrateUnderrunError):67 """ASN.1 data structure deserialization error68 69 The `EndOfStreamError` exception indicates the condition of the input70 stream has been closed.71 """72 73 74class UnsupportedSubstrateError(PyAsn1Error):75 """Unsupported substrate type to parse as ASN.1 data."""76 77 78class PyAsn1UnicodeError(PyAsn1Error, UnicodeError):79 """Unicode text processing error80 81 The `PyAsn1UnicodeError` exception is a base class for errors relating to82 unicode text de/serialization.83 84 Apart from inheriting from :class:`PyAsn1Error`, it also inherits from85 :class:`UnicodeError` to help the caller catching unicode-related errors.86 """87 def __init__(self, message, unicode_error=None):88 if isinstance(unicode_error, UnicodeError):89 UnicodeError.__init__(self, *unicode_error.args)90 PyAsn1Error.__init__(self, message)91 92 93class PyAsn1UnicodeDecodeError(PyAsn1UnicodeError, UnicodeDecodeError):94 """Unicode text decoding error95 96 The `PyAsn1UnicodeDecodeError` exception represents a failure to97 deserialize unicode text.98 99 Apart from inheriting from :class:`PyAsn1UnicodeError`, it also inherits100 from :class:`UnicodeDecodeError` to help the caller catching unicode-related101 errors.102 """103 104 105class PyAsn1UnicodeEncodeError(PyAsn1UnicodeError, UnicodeEncodeError):106 """Unicode text encoding error107 108 The `PyAsn1UnicodeEncodeError` exception represents a failure to109 serialize unicode text.110 111 Apart from inheriting from :class:`PyAsn1UnicodeError`, it also inherits112 from :class:`UnicodeEncodeError` to help the caller catching113 unicode-related errors.114 """115 116 117 