A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

259 linhas
8.8 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. +-- 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. """
  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 PermissionsError(WikiToolsetError):
  99. """A permissions error ocurred.
  100. We tried to do something we don't have permission to, like trying to delete
  101. a page as a non-admin, or trying to edit a page without login information
  102. and AssertEdit enabled. This will also be raised if we have been blocked
  103. from editing.
  104. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>`,
  105. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`, and
  106. other API methods depending on settings.
  107. """
  108. class NamespaceNotFoundError(WikiToolsetError):
  109. """A requested namespace name or namespace ID does not exist.
  110. Raised by :py:meth:`Site.namespace_id_to_name
  111. <earwigbot.wiki.site.Site.namespace_id_to_name>` and
  112. :py:meth:`Site.namespace_name_to_id
  113. <earwigbot.wiki.site.Site.namespace_name_to_id>`.
  114. """
  115. class PageNotFoundError(WikiToolsetError):
  116. """Attempted to get information about a page that does not exist.
  117. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  118. """
  119. class InvalidPageError(WikiToolsetError):
  120. """Attempted to get information about a page whose title is invalid.
  121. Raised by :py:class:`~earwigbot.wiki.page.Page`.
  122. """
  123. class RedirectError(WikiToolsetError):
  124. """A redirect-only method was called on a malformed or non-redirect page.
  125. Raised by :py:meth:`Page.get_redirect_target
  126. <earwigbot.wiki.page.Page.get_redirect_target>`.
  127. """
  128. class UserNotFoundError(WikiToolsetError):
  129. """Attempted to get certain information about a user that does not exist.
  130. Raised by :py:class:`~earwigbot.wiki.user.User`.
  131. """
  132. class EditError(WikiToolsetError):
  133. """An error occured while editing.
  134. This is used as a base class for all editing errors; this one specifically
  135. is used only when a generic error occurs that we don't know about.
  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 EditConflictError(EditError):
  140. """We gotten an edit conflict or a (rarer) delete/recreate conflict.
  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 NoContentError(EditError):
  145. """We tried to create a page or new section with no content.
  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 ContentTooBigError(EditError):
  150. """The edit we tried to push exceeded the article size limit.
  151. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  152. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  153. """
  154. class SpamDetectedError(EditError):
  155. """The spam filter refused our edit.
  156. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  157. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  158. """
  159. class FilteredError(EditError):
  160. """The edit filter refused our edit.
  161. Raised by :py:meth:`Page.edit <earwigbot.wiki.page.Page.edit>` and
  162. :py:meth:`Page.add_section <earwigbot.wiki.page.Page.add_section>`.
  163. """
  164. class CopyvioCheckError(WikiToolsetError):
  165. """An error occured when checking a page for copyright violations.
  166. This is a base class for multiple exceptions; usually one of those will be
  167. raised instead of this.
  168. Raised by :py:meth:`Page.copyvio_check
  169. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  170. :py:meth:`Page.copyvio_compare
  171. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  172. """
  173. class UnknownSearchEngineError(CopyvioCheckError):
  174. """Attempted to do a copyvio check with an unknown search engine.
  175. Search engines are specified in :file:`config.yml` as
  176. :py:attr:`config.wiki["search"]["engine"]`.
  177. Raised by :py:meth:`Page.copyvio_check
  178. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  179. :py:meth:`Page.copyvio_compare
  180. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  181. """
  182. class UnsupportedSearchEngineError(CopyvioCheckError):
  183. """Attmpted to do a copyvio check using an unavailable engine.
  184. This might occur if, for example, an engine requires oauth2 but the package
  185. couldn't be imported.
  186. Raised by :py:meth:`Page.copyvio_check
  187. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  188. :py:meth:`Page.copyvio_compare
  189. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  190. """
  191. class SearchQueryError(CopyvioCheckError):
  192. """Some error ocurred while doing a search query.
  193. Raised by :py:meth:`Page.copyvio_check
  194. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_check>` and
  195. :py:meth:`Page.copyvio_compare
  196. <earwigbot.wiki.copyvios.CopyvioMixIn.copyvio_compare>`.
  197. """