A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

245 Zeilen
8.3 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2012 by 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. +-- IRCError
  27. | +-- BrokenSocketError
  28. | +-- KwargParseError
  29. +-- WikiToolsetError
  30. +-- SiteNotFoundError
  31. +-- SiteAPIError
  32. +-- LoginError
  33. +-- NamespaceNotFoundError
  34. +-- PageNotFoundError
  35. +-- InvalidPageError
  36. +-- RedirectError
  37. +-- UserNotFoundError
  38. +-- EditError
  39. | +-- PermissionsError
  40. | +-- EditConflictError
  41. | +-- NoContentError
  42. | +-- ContentTooBigError
  43. | +-- SpamDetectedError
  44. | +-- FilteredError
  45. +-- SQLError
  46. +-- CopyvioCheckError
  47. +-- UnknownSearchEngineError
  48. +-- UnsupportedSearchEngineError
  49. +-- SearchQueryError
  50. """
  51. class EarwigBotError(Exception):
  52. """Base exception class for errors in EarwigBot."""
  53. class IRCError(EarwigBotError):
  54. """Base exception class for errors in IRC-relation sections of the bot."""
  55. class BrokenSocketError(IRCError):
  56. """A socket has broken, because it is not sending data.
  57. Raised by :py:meth:`IRCConnection._get
  58. <earwigbot.irc.connection.IRCConnection._get>`.
  59. """
  60. class KwargParseError(IRCError):
  61. """Couldn't parse a certain keyword argument in an IRC message.
  62. This is usually caused by it being given incorrectly: e.g., no value (abc),
  63. just a value (=xyz), just an equal sign (=), instead of the correct form
  64. (abc=xyz).
  65. Raised by :py:meth:`Data.parse_kwargs
  66. <earwigbot.irc.data.Data.parse_kwargs>`.
  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 SiteAPIError(WikiToolsetError):
  75. """Couldn't connect to a site's API.
  76. Perhaps the server doesn't exist, our URL is wrong or incomplete, or
  77. there are temporary problems on their end.
  78. Raised by :py:meth:`Site.api_query <earwigbot.wiki.site.Site.api_query>`.
  79. """
  80. class LoginError(WikiToolsetError):
  81. """An error occured while trying to login.
  82. Perhaps the username/password is incorrect.
  83. Raised by :py:meth:`Site._login <earwigbot.wiki.site.Site._login>`.
  84. """
  85. class NamespaceNotFoundError(WikiToolsetError):
  86. """A requested namespace name or namespace ID does not exist.
  87. Raised by :py:meth:`Site.namespace_id_to_name
  88. <earwigbot.wiki.site.Site.namespace_id_to_name>` and
  89. :py:meth:`Site.namespace_name_to_id
  90. <earwigbot.wiki.site.Site.namespace_name_to_id>`.
  91. """
  92. class PageNotFoundError(WikiToolsetError):
  93. """Attempted to get information about a page that does not exist.
  94. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  95. """
  96. class InvalidPageError(WikiToolsetError):
  97. """Attempted to get information about a page whose title is invalid.
  98. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  99. """
  100. class RedirectError(WikiToolsetError):
  101. """A redirect-only method was called on a malformed or non-redirect page.
  102. Raised by :py:meth:`Page.get_redirect_target
  103. <earwigbot.wiki.page.Page.get_redirect_target>`.
  104. """
  105. class UserNotFoundError(WikiToolsetError):
  106. """Attempted to get certain information about a user that does not exist.
  107. Raised by :py:class:`~earwigbot.wiki.user.User`.
  108. """
  109. class EditError(WikiToolsetError):
  110. """An error occured while editing.
  111. This is used as a base class for all editing errors; this one specifically
  112. is used only when a generic error occurs that we don't know about.
  113. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  114. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  115. """
  116. class PermissionsError(EditError):
  117. """A permissions error ocurred while editing.
  118. We tried to do something we don't have permission to, like trying to delete
  119. a page as a non-admin, or trying to edit a page without login information
  120. and AssertEdit enabled.
  121. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  122. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  123. """
  124. class EditConflictError(EditError):
  125. """We gotten an edit conflict or a (rarer) delete/recreate conflict.
  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 NoContentError(EditError):
  130. """We tried to create a page or new section with no content.
  131. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  132. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  133. """
  134. class ContentTooBigError(EditError):
  135. """The edit we tried to push exceeded the article size limit.
  136. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  137. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  138. """
  139. class SpamDetectedError(EditError):
  140. """The spam filter refused our edit.
  141. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  142. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  143. """
  144. class FilteredError(EditError):
  145. """The edit filter refused our edit.
  146. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  147. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  148. """
  149. class SQLError(WikiToolsetError):
  150. """Some error involving SQL querying occurred.
  151. Raised by :py:meth:`Site.sql_query <earwigbot.wiki.site.Site.sql_query>`.
  152. """
  153. class CopyvioCheckError(WikiToolsetError):
  154. """An error occured when checking a page for copyright violations.
  155. This is a base class for multiple exceptions; usually one of those will be
  156. raised instead of this.
  157. Raised by :py:meth:`Page.copyvio_check
  158. <earwigbot.wiki.copyvios.CopyvioMixin.copyvio_check>` and
  159. :py:meth:`Page.copyvio_compare
  160. <earwigbot.wiki.copyvios.CopyvioMixin.copyvio_compare>`.
  161. """
  162. class UnknownSearchEngineError(CopyvioCheckError):
  163. """Attempted to do a copyvio check with an unknown search engine.
  164. Search engines are specified in :file:`config.yml` as
  165. :py:attr:`config.wiki["search"]["engine"]`.
  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 UnsupportedSearchEngineError(CopyvioCheckError):
  172. """Attmpted to do a copyvio check using an unavailable engine.
  173. This might occur if, for example, an engine requires oauth2 but the package
  174. couldn't be imported.
  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 SearchQueryError(CopyvioCheckError):
  181. """Some error ocurred while doing a search query.
  182. Raised by :py:meth:`Page.copyvio_check
  183. <earwigbot.wiki.copyvios.CopyvioMixin.copyvio_check>` and
  184. :py:meth:`Page.copyvio_compare
  185. <earwigbot.wiki.copyvios.CopyvioMixin.copyvio_compare>`.
  186. """