A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

258 lignes
8.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  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. This will also be raised if we have been blocked
  134. from editing.
  135. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  136. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  137. """
  138. class EditConflictError(EditError):
  139. """We gotten an edit conflict or a (rarer) delete/recreate conflict.
  140. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  141. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  142. """
  143. class NoContentError(EditError):
  144. """We tried to create a page or new section with no content.
  145. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  146. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  147. """
  148. class ContentTooBigError(EditError):
  149. """The edit we tried to push exceeded the article size limit.
  150. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  151. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  152. """
  153. class SpamDetectedError(EditError):
  154. """The spam filter refused our edit.
  155. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  156. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  157. """
  158. class FilteredError(EditError):
  159. """The edit filter refused our edit.
  160. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  161. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  162. """
  163. class CopyvioCheckError(WikiToolsetError):
  164. """An error occured when checking a page for copyright violations.
  165. This is a base class for multiple exceptions; usually one of those will be
  166. raised instead of this.
  167. Raised by :py:meth:`Page.copyvio_check
  168. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  169. :py:meth:`Page.copyvio_compare
  170. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  171. """
  172. class UnknownSearchEngineError(CopyvioCheckError):
  173. """Attempted to do a copyvio check with an unknown search engine.
  174. Search engines are specified in :file:`config.yml` as
  175. :py:attr:`config.wiki["search"]["engine"]`.
  176. Raised by :py:meth:`Page.copyvio_check
  177. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  178. :py:meth:`Page.copyvio_compare
  179. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  180. """
  181. class UnsupportedSearchEngineError(CopyvioCheckError):
  182. """Attmpted to do a copyvio check using an unavailable engine.
  183. This might occur if, for example, an engine requires oauth2 but the package
  184. couldn't be imported.
  185. Raised by :py:meth:`Page.copyvio_check
  186. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  187. :py:meth:`Page.copyvio_compare
  188. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  189. """
  190. class SearchQueryError(CopyvioCheckError):
  191. """Some error ocurred while doing a search query.
  192. Raised by :py:meth:`Page.copyvio_check
  193. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  194. :py:meth:`Page.copyvio_compare
  195. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  196. """