A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
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.

273 lines
9.1 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2015 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. +-- PermissionsError
  37. +-- NamespaceNotFoundError
  38. +-- PageNotFoundError
  39. +-- InvalidPageError
  40. +-- RedirectError
  41. +-- UserNotFoundError
  42. +-- EditError
  43. | +-- EditConflictError
  44. | +-- NoContentError
  45. | +-- ContentTooBigError
  46. | +-- SpamDetectedError
  47. | +-- FilteredError
  48. +-- CopyvioCheckError
  49. +-- UnknownSearchEngineError
  50. +-- UnsupportedSearchEngineError
  51. +-- SearchQueryError
  52. +-- ParserExclusionError
  53. """
  54. class EarwigBotError(Exception):
  55. """Base exception class for errors in EarwigBot."""
  56. class NoConfigError(EarwigBotError):
  57. """The bot cannot be run without a config file.
  58. This occurs if no config file exists, and the user said they did not want
  59. one to be created.
  60. """
  61. class IRCError(EarwigBotError):
  62. """Base exception class for errors in IRC-relation sections of the bot."""
  63. class BrokenSocketError(IRCError):
  64. """A socket has broken, because it is not sending data.
  65. Raised by :py:meth:`IRCConnection._get
  66. <earwigbot.irc.connection.IRCConnection._get>`.
  67. """
  68. class WikiToolsetError(EarwigBotError):
  69. """Base exception class for errors in the Wiki Toolset."""
  70. class SiteNotFoundError(WikiToolsetError):
  71. """A particular site could not be found in the sites database.
  72. Raised by :py:class:`~earwigbot.wiki.sitesdb.SitesDB`.
  73. """
  74. class ServiceError(WikiToolsetError):
  75. """Base exception class for an error within a service (the API or SQL).
  76. This is caught by :py:meth:`Site.delegate
  77. <earwigbot.wiki.site.Site.delegate>` to indicate a service is
  78. non-functional so another, less-preferred one can be tried.
  79. """
  80. class APIError(ServiceError):
  81. """Couldn't connect to a site's API.
  82. Perhaps the server doesn't exist, our URL is wrong or incomplete, or
  83. there are temporary problems on their end.
  84. Raised by :py:meth:`Site.api_query <earwigbot.wiki.site.Site.api_query>`.
  85. """
  86. class SQLError(ServiceError):
  87. """Some error involving SQL querying occurred.
  88. Raised by :py:meth:`Site.sql_query <earwigbot.wiki.site.Site.sql_query>`.
  89. """
  90. class NoServiceError(WikiToolsetError):
  91. """No service is functioning to handle a specific task.
  92. Raised by :py:meth:`Site.delegate <earwigbot.wiki.site.Site.delegate>`.
  93. """
  94. class LoginError(WikiToolsetError):
  95. """An error occured while trying to login.
  96. Perhaps the username/password is incorrect.
  97. Raised by :py:meth:`Site._login <earwigbot.wiki.site.Site._login>`.
  98. """
  99. class PermissionsError(WikiToolsetError):
  100. """A permissions error ocurred.
  101. We tried to do something we don't have permission to, like trying to delete
  102. a page as a non-admin, or trying to edit a page without login information
  103. and AssertEdit enabled. This will also be raised if we have been blocked
  104. from editing.
  105. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>`,
  106. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`, and
  107. other API methods depending on settings.
  108. """
  109. class NamespaceNotFoundError(WikiToolsetError):
  110. """A requested namespace name or namespace ID does not exist.
  111. Raised by :py:meth:`Site.namespace_id_to_name
  112. <earwigbot.wiki.site.Site.namespace_id_to_name>` and
  113. :py:meth:`Site.namespace_name_to_id
  114. <earwigbot.wiki.site.Site.namespace_name_to_id>`.
  115. """
  116. class PageNotFoundError(WikiToolsetError):
  117. """Attempted to get information about a page that does not exist.
  118. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  119. """
  120. class InvalidPageError(WikiToolsetError):
  121. """Attempted to get information about a page whose title is invalid.
  122. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  123. """
  124. class RedirectError(WikiToolsetError):
  125. """A redirect-only method was called on a malformed or non-redirect page.
  126. Raised by :py:meth:`Page.get_redirect_target
  127. <earwigbot.wiki.page.Page.get_redirect_target>`.
  128. """
  129. class UserNotFoundError(WikiToolsetError):
  130. """Attempted to get certain information about a user that does not exist.
  131. Raised by :py:class:`~earwigbot.wiki.user.User`.
  132. """
  133. class EditError(WikiToolsetError):
  134. """An error occured while editing.
  135. This is used as a base class for all editing errors; this one specifically
  136. is used only when a generic error occurs that we don't know about.
  137. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  138. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  139. """
  140. class EditConflictError(EditError):
  141. """We gotten an edit conflict or a (rarer) delete/recreate conflict.
  142. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  143. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  144. """
  145. class NoContentError(EditError):
  146. """We tried to create a page or new section with no content.
  147. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  148. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  149. """
  150. class ContentTooBigError(EditError):
  151. """The edit we tried to push exceeded the article size limit.
  152. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  153. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  154. """
  155. class SpamDetectedError(EditError):
  156. """The spam filter refused our edit.
  157. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  158. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  159. """
  160. class FilteredError(EditError):
  161. """The edit filter refused our edit.
  162. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  163. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  164. """
  165. class CopyvioCheckError(WikiToolsetError):
  166. """An error occured when checking a page for copyright violations.
  167. This is a base class for multiple exceptions; usually one of those will be
  168. raised instead of this.
  169. Raised by :py:meth:`Page.copyvio_check
  170. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  171. :py:meth:`Page.copyvio_compare
  172. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  173. """
  174. class UnknownSearchEngineError(CopyvioCheckError):
  175. """Attempted to do a copyvio check with an unknown search engine.
  176. Search engines are specified in :file:`config.yml` as
  177. :py:attr:`config.wiki["search"]["engine"]`.
  178. Raised by :py:meth:`Page.copyvio_check
  179. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>`.
  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>`.
  187. """
  188. class SearchQueryError(CopyvioCheckError):
  189. """Some error ocurred while doing a search query.
  190. Raised by :py:meth:`Page.copyvio_check
  191. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>`.
  192. """
  193. class ParserExclusionError(CopyvioCheckError):
  194. """A content parser detected that the given source should be excluded.
  195. Raised internally by :py:meth:`Page.copyvio_check
  196. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>`; should not be
  197. exposed in client code.
  198. """
  199. class ParserRedirectError(CopyvioCheckError):
  200. """A content parser detected that a redirect should be followed.
  201. Raised internally by :py:meth:`Page.copyvio_check
  202. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>`; should not be
  203. exposed in client code.
  204. """
  205. def __init__(self, url):
  206. super().__init__()
  207. self.url = url