Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_except.py 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Exceptions in L{twisted.mail}.
  5. """
  6. from typing import Optional
  7. class IMAP4Exception(Exception):
  8. pass
  9. class IllegalClientResponse(IMAP4Exception):
  10. pass
  11. class IllegalOperation(IMAP4Exception):
  12. pass
  13. class IllegalMailboxEncoding(IMAP4Exception):
  14. pass
  15. class MailboxException(IMAP4Exception):
  16. pass
  17. class MailboxCollision(MailboxException):
  18. def __str__(self) -> str:
  19. return "Mailbox named %s already exists" % self.args
  20. class NoSuchMailbox(MailboxException):
  21. def __str__(self) -> str:
  22. return "No mailbox named %s exists" % self.args
  23. class ReadOnlyMailbox(MailboxException):
  24. def __str__(self) -> str:
  25. return "Mailbox open in read-only state"
  26. class UnhandledResponse(IMAP4Exception):
  27. pass
  28. class NegativeResponse(IMAP4Exception):
  29. pass
  30. class NoSupportedAuthentication(IMAP4Exception):
  31. def __init__(self, serverSupports, clientSupports):
  32. IMAP4Exception.__init__(self, "No supported authentication schemes available")
  33. self.serverSupports = serverSupports
  34. self.clientSupports = clientSupports
  35. def __str__(self) -> str:
  36. return IMAP4Exception.__str__(
  37. self
  38. ) + ": Server supports {!r}, client supports {!r}".format(
  39. self.serverSupports,
  40. self.clientSupports,
  41. )
  42. class IllegalServerResponse(IMAP4Exception):
  43. pass
  44. class IllegalIdentifierError(IMAP4Exception):
  45. pass
  46. class IllegalQueryError(IMAP4Exception):
  47. pass
  48. class MismatchedNesting(IMAP4Exception):
  49. pass
  50. class MismatchedQuoting(IMAP4Exception):
  51. pass
  52. class SMTPError(Exception):
  53. pass
  54. class SMTPClientError(SMTPError):
  55. """
  56. Base class for SMTP client errors.
  57. """
  58. def __init__(
  59. self,
  60. code: int,
  61. resp: bytes,
  62. log: Optional[bytes] = None,
  63. addresses: Optional[object] = None,
  64. isFatal: bool = False,
  65. retry: bool = False,
  66. ):
  67. """
  68. @param code: The SMTP response code associated with this error.
  69. @param resp: The string response associated with this error.
  70. @param log: A string log of the exchange leading up to and including
  71. the error.
  72. @param isFatal: A boolean indicating whether this connection can
  73. proceed or not. If True, the connection will be dropped.
  74. @param retry: A boolean indicating whether the delivery should be
  75. retried. If True and the factory indicates further retries are
  76. desirable, they will be attempted, otherwise the delivery will be
  77. failed.
  78. """
  79. if isinstance(resp, str): # type: ignore[unreachable]
  80. resp = resp.encode("utf-8") # type: ignore[unreachable]
  81. if isinstance(log, str): # type: ignore[unreachable]
  82. log = log.encode("utf-8") # type: ignore[unreachable]
  83. self.code = code
  84. self.resp = resp
  85. self.log = log
  86. self.addresses = addresses
  87. self.isFatal = isFatal
  88. self.retry = retry
  89. def __str__(self) -> str:
  90. return self.__bytes__().decode("utf-8")
  91. def __bytes__(self) -> bytes:
  92. if self.code > 0:
  93. res = [f"{self.code:03d} ".encode() + self.resp]
  94. else:
  95. res = [self.resp]
  96. if self.log:
  97. res.append(self.log)
  98. res.append(b"")
  99. return b"\n".join(res)
  100. class ESMTPClientError(SMTPClientError):
  101. """
  102. Base class for ESMTP client errors.
  103. """
  104. class EHLORequiredError(ESMTPClientError):
  105. """
  106. The server does not support EHLO.
  107. This is considered a non-fatal error (the connection will not be dropped).
  108. """
  109. class AUTHRequiredError(ESMTPClientError):
  110. """
  111. Authentication was required but the server does not support it.
  112. This is considered a non-fatal error (the connection will not be dropped).
  113. """
  114. class TLSRequiredError(ESMTPClientError):
  115. """
  116. Transport security was required but the server does not support it.
  117. This is considered a non-fatal error (the connection will not be dropped).
  118. """
  119. class AUTHDeclinedError(ESMTPClientError):
  120. """
  121. The server rejected our credentials.
  122. Either the username, password, or challenge response
  123. given to the server was rejected.
  124. This is considered a non-fatal error (the connection will not be
  125. dropped).
  126. """
  127. class AuthenticationError(ESMTPClientError):
  128. """
  129. An error occurred while authenticating.
  130. Either the server rejected our request for authentication or the
  131. challenge received was malformed.
  132. This is considered a non-fatal error (the connection will not be
  133. dropped).
  134. """
  135. class SMTPTLSError(ESMTPClientError):
  136. """
  137. An error occurred while negiotiating for transport security.
  138. This is considered a non-fatal error (the connection will not be dropped).
  139. """
  140. class SMTPConnectError(SMTPClientError):
  141. """
  142. Failed to connect to the mail exchange host.
  143. This is considered a fatal error. A retry will be made.
  144. """
  145. def __init__(self, code, resp, log=None, addresses=None, isFatal=True, retry=True):
  146. SMTPClientError.__init__(self, code, resp, log, addresses, isFatal, retry)
  147. class SMTPTimeoutError(SMTPClientError):
  148. """
  149. Failed to receive a response from the server in the expected time period.
  150. This is considered a fatal error. A retry will be made.
  151. """
  152. def __init__(self, code, resp, log=None, addresses=None, isFatal=True, retry=True):
  153. SMTPClientError.__init__(self, code, resp, log, addresses, isFatal, retry)
  154. class SMTPProtocolError(SMTPClientError):
  155. """
  156. The server sent a mangled response.
  157. This is considered a fatal error. A retry will not be made.
  158. """
  159. def __init__(self, code, resp, log=None, addresses=None, isFatal=True, retry=False):
  160. SMTPClientError.__init__(self, code, resp, log, addresses, isFatal, retry)
  161. class SMTPDeliveryError(SMTPClientError):
  162. """
  163. Indicates that a delivery attempt has had an error.
  164. """
  165. class SMTPServerError(SMTPError):
  166. def __init__(self, code, resp):
  167. self.code = code
  168. self.resp = resp
  169. def __str__(self) -> str:
  170. return "%.3d %s" % (self.code, self.resp)
  171. class SMTPAddressError(SMTPServerError):
  172. def __init__(self, addr, code, resp):
  173. from twisted.mail.smtp import Address
  174. SMTPServerError.__init__(self, code, resp)
  175. self.addr = Address(addr)
  176. def __str__(self) -> str:
  177. return "%.3d <%s>... %s" % (self.code, self.addr, self.resp)
  178. class SMTPBadRcpt(SMTPAddressError):
  179. def __init__(self, addr, code=550, resp="Cannot receive for specified address"):
  180. SMTPAddressError.__init__(self, addr, code, resp)
  181. class SMTPBadSender(SMTPAddressError):
  182. def __init__(self, addr, code=550, resp="Sender not acceptable"):
  183. SMTPAddressError.__init__(self, addr, code, resp)
  184. class AddressError(SMTPError):
  185. """
  186. Parse error in address
  187. """
  188. class POP3Error(Exception):
  189. """
  190. The base class for POP3 errors.
  191. """
  192. pass
  193. class _POP3MessageDeleted(Exception):
  194. """
  195. An internal control-flow error which indicates that a deleted message was
  196. requested.
  197. """
  198. class POP3ClientError(Exception):
  199. """
  200. The base class for all exceptions raised by POP3Client.
  201. """
  202. class InsecureAuthenticationDisallowed(POP3ClientError):
  203. """
  204. An error indicating secure authentication was required but no mechanism
  205. could be found.
  206. """
  207. class TLSError(POP3ClientError):
  208. """
  209. An error indicating secure authentication was required but either the
  210. transport does not support TLS or no TLS context factory was supplied.
  211. """
  212. class TLSNotSupportedError(POP3ClientError):
  213. """
  214. An error indicating secure authentication was required but the server does
  215. not support TLS.
  216. """
  217. class ServerErrorResponse(POP3ClientError):
  218. """
  219. An error indicating that the server returned an error response to a
  220. request.
  221. @ivar consumer: See L{__init__}
  222. """
  223. def __init__(self, reason, consumer=None):
  224. """
  225. @type reason: L{bytes}
  226. @param reason: The server response minus the status indicator.
  227. @type consumer: callable that takes L{object}
  228. @param consumer: The function meant to handle the values for a
  229. multi-line response.
  230. """
  231. POP3ClientError.__init__(self, reason)
  232. self.consumer = consumer
  233. class LineTooLong(POP3ClientError):
  234. """
  235. An error indicating that the server sent a line which exceeded the
  236. maximum line length (L{LineOnlyReceiver.MAX_LENGTH}).
  237. """