File: exceptions.py

package info (click to toggle)
python-gssapi 1.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 880 kB
  • sloc: python: 3,709; sh: 198; makefile: 154; ansic: 60
file content (47 lines) | stat: -rw-r--r-- 1,307 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import typing as t

from gssapi.raw.exceptions import *  # noqa
from gssapi.raw.misc import GSSError  # noqa

"""High-Level API Errors

This module includes several high-level exceptions,
in addition to GSSError and exceptions from
:mod:`gssapi.raw.exceptions`.
"""


# non-GSS exceptions
class GeneralError(Exception):
    """A General High-Level API Error"""
    MAJOR_MESSAGE = "General error"
    FMT_STR = "{maj}: {min}."

    def __init__(
        self,
        minor_message: str,
        **kwargs: str,
    ) -> None:
        maj_str = self.MAJOR_MESSAGE.format(**kwargs)
        err_str = self.FMT_STR.format(maj=maj_str, min=minor_message)
        super(GeneralError, self).__init__(err_str)


class UnknownUsageError(GeneralError):
    """An Error indicating an unknown usage type"""
    MAJOR_MESSAGE = "Unable to determine {obj} usage"


class EncryptionNotUsed(GeneralError):
    """An Error indicating that encryption was requested, but not used"""
    MAJOR_MESSAGE = "Confidentiality was requested, but not used"

    def __init__(
        self,
        minor_message: str,
        unwrapped_message: t.Optional[bytes] = None,
        **kwargs: str,
    ) -> None:
        super(EncryptionNotUsed, self).__init__(minor_message, **kwargs)

        self.unwrapped_message = unwrapped_message