Skip to content

Status

email_profile.core.status.Status

Source code in email_profile/core/status.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class Status:
    OK = "OK"
    NO = "NO"
    BAD = "BAD"

    @staticmethod
    def check_status(status: str) -> StatusResponse:
        """Return a StatusResponse without raising on failure."""
        ok, message = _STATUS_MESSAGES.get(status, (False, "Unknown error"))
        return StatusResponse(ok=ok, message=message)

    @staticmethod
    def validate_status(
        status: str,
        payload: object = None,
    ) -> StatusResponse:
        """Return a StatusResponse, raising on failure."""
        ok, message = _STATUS_MESSAGES.get(status, (False, "Unknown error"))

        if not ok:
            specific = _classify(payload)
            if specific is not None:
                raise specific
            raise IMAPError(message)

        return StatusResponse(ok=ok, message=message)

    @staticmethod
    def state(context: tuple) -> list:
        """Validate IMAP response and return the payload."""
        Status.validate_status(context[0], payload=context[1])
        return context[1]

BAD = 'BAD' class-attribute instance-attribute

NO = 'NO' class-attribute instance-attribute

OK = 'OK' class-attribute instance-attribute

check_status(status) staticmethod

Return a StatusResponse without raising on failure.

Source code in email_profile/core/status.py
65
66
67
68
69
@staticmethod
def check_status(status: str) -> StatusResponse:
    """Return a StatusResponse without raising on failure."""
    ok, message = _STATUS_MESSAGES.get(status, (False, "Unknown error"))
    return StatusResponse(ok=ok, message=message)

state(context) staticmethod

Validate IMAP response and return the payload.

Source code in email_profile/core/status.py
87
88
89
90
91
@staticmethod
def state(context: tuple) -> list:
    """Validate IMAP response and return the payload."""
    Status.validate_status(context[0], payload=context[1])
    return context[1]

validate_status(status, payload=None) staticmethod

Return a StatusResponse, raising on failure.

Source code in email_profile/core/status.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@staticmethod
def validate_status(
    status: str,
    payload: object = None,
) -> StatusResponse:
    """Return a StatusResponse, raising on failure."""
    ok, message = _STATUS_MESSAGES.get(status, (False, "Unknown error"))

    if not ok:
        specific = _classify(payload)
        if specific is not None:
            raise specific
        raise IMAPError(message)

    return StatusResponse(ok=ok, message=message)

email_profile.core.status.StatusResponse dataclass

Source code in email_profile/core/status.py
10
11
12
13
@dataclass
class StatusResponse:
    ok: bool
    message: str

message instance-attribute

ok instance-attribute

__init__(ok, message)