jenkins-bot has submitted this change and it was merged.
Change subject: Fetch sha1 in site.loadrevisions and store it
......................................................................
Fetch sha1 in site.loadrevisions and store it
page.Revision.sha1() will use the fetched sha1 if possible, otherwise it
will calculate it based on the revision text.
Change-Id: I6fca5f6032032fb10b608815dfb51d276a1b4b29
---
M pywikibot/data/api.py
M pywikibot/page.py
M pywikibot/site.py
3 files changed, 14 insertions(+), 2 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 539eed3..aa2aebc 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2787,6 +2787,7 @@
rollbacktoken=rev.get('rollbacktoken', None),
parentid=rev.get('parentid'),
contentmodel=rev.get('contentmodel', None),
+ sha1=rev.get('sha1', None)
)
page._revisions[revision.revid] = revision
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b364488..b8909bf 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4439,7 +4439,7 @@
def __init__(self, revid, timestamp, user, anon=False, comment=u"",
text=None, minor=False, rollbacktoken=None, parentid=None,
- contentmodel=None):
+ contentmodel=None, sha1=None):
"""
Constructor.
@@ -4472,6 +4472,7 @@
self.rollbacktoken = rollbacktoken
self._parent_id = parentid
self._content_model = contentmodel
+ self._sha1 = sha1
@property
def parent_id(self):
@@ -4509,6 +4510,16 @@
return self._content_model
+ @property
+ def sha1(self):
+ if self._sha1 is None:
+ if self.text is None:
+ # No text? No sha1 then.
+ return None
+ self._sha1 = hashlib.sha1(self.text.encode('utf8')).hexdigest()
+
+ return self._sha1
+
def hist_entry(self):
"""Return a namedtuple with a Page history
record."""
return Revision.HistEntry(self.revid, self.timestamp, self.user,
diff --git a/pywikibot/site.py b/pywikibot/site.py
index f1901da..023bf40 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3390,7 +3390,7 @@
rvargs = {'type_arg': 'info|revisions'}
if getText:
- rvargs[u"rvprop"] =
u"ids|flags|timestamp|user|comment|content"
+ rvargs[u"rvprop"] =
u"ids|flags|timestamp|user|comment|content|sha1"
if section is not None:
rvargs[u"rvsection"] = unicode(section)
if rollback:
--
To view, visit
https://gerrit.wikimedia.org/r/221434
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6fca5f6032032fb10b608815dfb51d276a1b4b29
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>