jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/661898 )
Change subject: [IMPR ]Move page decorators into _decorators.py file
......................................................................
[IMPR ]Move page decorators into _decorators.py file
page.py is one of the biggest framework file with 236 KB disk
space and 5100 lines of code. This should be splitted into smaller
parts for readability and maintainability. Moving decorators to its
own file like in site module.
Change-Id: I7b633791456160df0eae1cb48bd4ccf88842c2d5
---
M docs/api_ref/pywikibot.page.rst
M pywikibot/CONTENT.rst
M pywikibot/page/__init__.py
A pywikibot/page/_decorators.py
4 files changed, 62 insertions(+), 45 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/api_ref/pywikibot.page.rst b/docs/api_ref/pywikibot.page.rst
index 5bbd20f..46ec207 100644
--- a/docs/api_ref/pywikibot.page.rst
+++ b/docs/api_ref/pywikibot.page.rst
@@ -6,6 +6,11 @@
Submodules
----------
+pywikibot.page.\_decorators module
+----------------------------------
+
+.. automodule:: pywikibot.page._decorators
+
pywikibot.page.\_revision module
--------------------------------
diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst
index 52cd01a..8b2878a 100644
--- a/pywikibot/CONTENT.rst
+++ b/pywikibot/CONTENT.rst
@@ -104,6 +104,8 @@
+============================+======================================================+
| __init__.py | Objects representing MediaWiki pages
|
+----------------------------+------------------------------------------------------+
+ | _decorators.py | Decorators used by page objects
|
+
+----------------------------+------------------------------------------------------+
| _revision.py | Object representing page revision
|
+----------------------------+------------------------------------------------------+
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index be8b2ce..4cd0970 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -43,10 +43,10 @@
UserRightsError,
)
from pywikibot.family import Family
+from pywikibot.page._decorators import allow_asynchronous
from pywikibot.page._revision import Revision
from pywikibot.site import DataSite, Namespace
from pywikibot.tools import (
- add_full_name,
compute_file_hash,
ComparableMixin,
deprecated,
@@ -55,7 +55,6 @@
DotReadableDict,
first_upper,
issue_deprecation_warning,
- manage_wrapping,
redirect_func,
remove_last_args,
)
@@ -90,49 +89,6 @@
logger = logging.getLogger('pywiki.wiki.page')
-@add_full_name
-def allow_asynchronous(func):
- """
- Decorator to make it possible to run a BasePage method asynchronously.
-
- This is done when the method is called with kwarg asynchronous=True.
- Optionally, you can also provide kwarg callback, which, if provided, is
- a callable that gets the page as the first and a possible exception that
- occurred during saving in the second thread or None as the second argument.
- """
- def handle(func, self, *args, **kwargs):
- do_async = kwargs.pop('asynchronous', False)
- callback = kwargs.pop('callback', None)
- err = None
- try:
- func(self, *args, **kwargs)
- # TODO: other "expected" error types to catch?
- except pywikibot.Error as edit_err:
- err = edit_err # edit_err will be deleted in the end of the scope
- link = self.title(as_link=True)
- if do_async:
- pywikibot.error('page {} not saved due to {}\n'
- .format(link, err))
- pywikibot.log('Error saving page %s (%s)\n' % (link, err),
- exc_info=True)
- if not callback and not do_async:
- if isinstance(err, pywikibot.PageSaveRelatedError):
- raise err
- raise pywikibot.OtherPageSaveError(self, err)
- if callback:
- callback(self, err)
-
- def wrapper(self, *args, **kwargs):
- if kwargs.get('asynchronous'):
- pywikibot.async_request(handle, func, self, *args, **kwargs)
- else:
- handle(func, self, *args, **kwargs)
-
- manage_wrapping(wrapper, func)
-
- return wrapper
-
-
# Note: Link objects (defined later on) represent a wiki-page's title, while
# Page objects (defined here) represent the page itself, including its
# contents.
diff --git a/pywikibot/page/_decorators.py b/pywikibot/page/_decorators.py
new file mode 100644
index 0000000..82b82a8
--- /dev/null
+++ b/pywikibot/page/_decorators.py
@@ -0,0 +1,54 @@
+
+"""Decorators for Page objects."""
+#
+# (C) Pywikibot team, 2017-2021
+#
+# Distributed under the terms of the MIT license.
+#
+
+import pywikibot
+
+from pywikibot.tools import add_full_name, manage_wrapping
+
+
+@add_full_name
+def allow_asynchronous(func):
+ """
+ Decorator to make it possible to run a BasePage method asynchronously.
+
+ This is done when the method is called with kwarg asynchronous=True.
+ Optionally, you can also provide kwarg callback, which, if provided, is
+ a callable that gets the page as the first and a possible exception that
+ occurred during saving in the second thread or None as the second argument.
+ """
+ def handle(func, self, *args, **kwargs):
+ do_async = kwargs.pop('asynchronous', False)
+ callback = kwargs.pop('callback', None)
+ err = None
+ try:
+ func(self, *args, **kwargs)
+ # TODO: other "expected" error types to catch?
+ except pywikibot.Error as edit_err:
+ err = edit_err # edit_err will be deleted in the end of the scope
+ link = self.title(as_link=True)
+ if do_async:
+ pywikibot.error('page {} not saved due to {}\n'
+ .format(link, err))
+ pywikibot.log('Error saving page %s (%s)\n' % (link, err),
+ exc_info=True)
+ if not callback and not do_async:
+ if isinstance(err, pywikibot.PageSaveRelatedError):
+ raise err
+ raise pywikibot.OtherPageSaveError(self, err)
+ if callback:
+ callback(self, err)
+
+ def wrapper(self, *args, **kwargs):
+ if kwargs.get('asynchronous'):
+ pywikibot.async_request(handle, func, self, *args, **kwargs)
+ else:
+ handle(func, self, *args, **kwargs)
+
+ manage_wrapping(wrapper, func)
+
+ return wrapper
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/661898
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7b633791456160df0eae1cb48bd4ccf88842c2d5
Gerrit-Change-Number: 661898
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits