A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

257 行
8.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2012 Ben Kurtovic <ben.kurtovic@verizon.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. """
  23. **EarwigBot: Exceptions**
  24. This module contains all exceptions used by EarwigBot::
  25. EarwigBotError
  26. +-- NoConfigError
  27. +-- IRCError
  28. | +-- BrokenSocketError
  29. +-- WikiToolsetError
  30. +-- SiteNotFoundError
  31. +-- ServiceError
  32. | +-- APIError
  33. | +-- SQLError
  34. +-- NoServiceError
  35. +-- LoginError
  36. +-- NamespaceNotFoundError
  37. +-- PageNotFoundError
  38. +-- InvalidPageError
  39. +-- RedirectError
  40. +-- UserNotFoundError
  41. +-- EditError
  42. | +-- PermissionsError
  43. | +-- EditConflictError
  44. | +-- NoContentError
  45. | +-- ContentTooBigError
  46. | +-- SpamDetectedError
  47. | +-- FilteredError
  48. +-- CopyvioCheckError
  49. +-- UnknownSearchEngineError
  50. +-- UnsupportedSearchEngineError
  51. +-- SearchQueryError
  52. """
  53. class EarwigBotError(Exception):
  54. """Base exception class for errors in EarwigBot."""
  55. class NoConfigError(EarwigBotError):
  56. """The bot cannot be run without a config file.
  57. This occurs if no config file exists, and the user said they did not want
  58. one to be created.
  59. """
  60. class IRCError(EarwigBotError):
  61. """Base exception class for errors in IRC-relation sections of the bot."""
  62. class BrokenSocketError(IRCError):
  63. """A socket has broken, because it is not sending data.
  64. Raised by :py:meth:`IRCConnection._get
  65. <earwigbot.irc.connection.IRCConnection._get>`.
  66. """
  67. class WikiToolsetError(EarwigBotError):
  68. """Base exception class for errors in the Wiki Toolset."""
  69. class SiteNotFoundError(WikiToolsetError):
  70. """A particular site could not be found in the sites database.
  71. Raised by :py:class:`~earwigbot.wiki.sitesdb.SitesDB`.
  72. """
  73. class ServiceError(WikiToolsetError):
  74. """Base exception class for an error within a service (the API or SQL).
  75. This is caught by :py:meth:`Site.delegate
  76. <earwigbot.wiki.site.Site.delegate>` to indicate a service is
  77. non-functional so another, less-preferred one can be tried.
  78. """
  79. class APIError(ServiceError):
  80. """Couldn't connect to a site's API.
  81. Perhaps the server doesn't exist, our URL is wrong or incomplete, or
  82. there are temporary problems on their end.
  83. Raised by :py:meth:`Site.api_query <earwigbot.wiki.site.Site.api_query>`.
  84. """
  85. class SQLError(ServiceError):
  86. """Some error involving SQL querying occurred.
  87. Raised by :py:meth:`Site.sql_query <earwigbot.wiki.site.Site.sql_query>`.
  88. """
  89. class NoServiceError(WikiToolsetError):
  90. """No service is functioning to handle a specific task.
  91. Raised by :py:meth:`Site.delegate <earwigbot.wiki.site.Site.delegate>`.
  92. """
  93. class LoginError(WikiToolsetError):
  94. """An error occured while trying to login.
  95. Perhaps the username/password is incorrect.
  96. Raised by :py:meth:`Site._login <earwigbot.wiki.site.Site._login>`.
  97. """
  98. class NamespaceNotFoundError(WikiToolsetError):
  99. """A requested namespace name or namespace ID does not exist.
  100. Raised by :py:meth:`Site.namespace_id_to_name
  101. <earwigbot.wiki.site.Site.namespace_id_to_name>` and
  102. :py:meth:`Site.namespace_name_to_id
  103. <earwigbot.wiki.site.Site.namespace_name_to_id>`.
  104. """
  105. class PageNotFoundError(WikiToolsetError):
  106. """Attempted to get information about a page that does not exist.
  107. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  108. """
  109. class InvalidPageError(WikiToolsetError):
  110. """Attempted to get information about a page whose title is invalid.
  111. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  112. """
  113. class RedirectError(WikiToolsetError):
  114. """A redirect-only method was called on a malformed or non-redirect page.
  115. Raised by :py:meth:`Page.get_redirect_target
  116. <earwigbot.wiki.page.Page.get_redirect_target>`.
  117. """
  118. class UserNotFoundError(WikiToolsetError):
  119. """Attempted to get certain information about a user that does not exist.
  120. Raised by :py:class:`~earwigbot.wiki.user.User`.
  121. """
  122. class EditError(WikiToolsetError):
  123. """An error occured while editing.
  124. This is used as a base class for all editing errors; this one specifically
  125. is used only when a generic error occurs that we don't know about.
  126. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  127. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  128. """
  129. class PermissionsError(EditError):
  130. """A permissions error ocurred while editing.
  131. We tried to do something we don't have permission to, like trying to delete
  132. a page as a non-admin, or trying to edit a page without login information
  133. and AssertEdit enabled.
  134. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  135. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  136. """
  137. class EditConflictError(EditError):
  138. """We gotten an edit conflict or a (rarer) delete/recreate conflict.
  139. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  140. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  141. """
  142. class NoContentError(EditError):
  143. """We tried to create a page or new section with no content.
  144. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  145. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  146. """
  147. class ContentTooBigError(EditError):
  148. """The edit we tried to push exceeded the article size limit.
  149. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  150. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  151. """
  152. class SpamDetectedError(EditError):
  153. """The spam filter refused our edit.
  154. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  155. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  156. """
  157. class FilteredError(EditError):
  158. """The edit filter refused our edit.
  159. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  160. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  161. """
  162. class CopyvioCheckError(WikiToolsetError):
  163. """An error occured when checking a page for copyright violations.
  164. This is a base class for multiple exceptions; usually one of those will be
  165. raised instead of this.
  166. Raised by :py:meth:`Page.copyvio_check
  167. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  168. :py:meth:`Page.copyvio_compare
  169. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  170. """
  171. class UnknownSearchEngineError(CopyvioCheckError):
  172. """Attempted to do a copyvio check with an unknown search engine.
  173. Search engines are specified in :file:`config.yml` as
  174. :py:attr:`config.wiki["search"]["engine"]`.
  175. Raised by :py:meth:`Page.copyvio_check
  176. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  177. :py:meth:`Page.copyvio_compare
  178. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  179. """
  180. class UnsupportedSearchEngineError(CopyvioCheckError):
  181. """Attmpted to do a copyvio check using an unavailable engine.
  182. This might occur if, for example, an engine requires oauth2 but the package
  183. couldn't be imported.
  184. Raised by :py:meth:`Page.copyvio_check
  185. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  186. :py:meth:`Page.copyvio_compare
  187. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  188. """
  189. class SearchQueryError(CopyvioCheckError):
  190. """Some error ocurred while doing a search query.
  191. Raised by :py:meth:`Page.copyvio_check
  192. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  193. :py:meth:`Page.copyvio_compare
  194. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  195. """