jenkins-bot has submitted this change and it was merged.
Change subject: Allow unicode in cache entry description
......................................................................
Allow unicode in cache entry description
The entry description has historically been checked to be a ascii string.
This removes that check, allowing it to contain non-ascii, and adds
documentation for the relevant methods.
The entry description is hashed and converted to a hexdigest to become
a unique cache key. The entry description is stored in the cache entry,
and compared to the request parameters.
Change-Id: I51b8052a8c6b73452d7a486d60d36393eefb25e0
---
M pywikibot/data/api.py
1 file changed, 18 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index eb97667..5cb880b 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -768,15 +768,19 @@
If this is modified, please also update
scripts/maintenance/cache.py to support
the new key and all previous keys.
+
+ @rtype: unicode
"""
login_status = self.site._loginstatus
if login_status > pywikibot.site.LoginStatus.NOT_LOGGED_IN and \
hasattr(self.site, '_userinfo') and \
'name' in self.site._userinfo:
- # This uses the format of Page.__repr__(), without the encoding
- # it performs. This string cant be encoded otherwise it creates an
- # exception when _create_file_name() tries to encode it again.
+ # This uses the format of Page.__repr__, without performing
+ # config.console_encoding as done by Page.__repr__.
+ # The returned value cant be encoded to anything other than
+ # ascii otherwise it creates an exception when _create_file_name()
+ # tries to encode it as utf-8.
user_key = u'User(User:%s)' % self.site._userinfo['name']
else:
user_key = pywikibot.site.LoginStatus(
@@ -787,6 +791,11 @@
return repr(self.site) + user_key + request_key
def _create_file_name(self):
+ """
+ Return a unique ascii identifier for the cache entry.
+
+ @rtype: str (hexademical; i.e. characters 0-9 and a-f only)
+ """
return hashlib.sha256(
self._uniquedescriptionstr().encode('utf-8')
).hexdigest()
@@ -799,13 +808,17 @@
return dt + self.expiry < datetime.datetime.now()
def _load_cache(self):
- """Return whether the cache can be used."""
+ """Load cache entry for request, if available.
+
+ @return: Whether the request was loaded from the cache
+ @rtype: bool
+ """
self._add_defaults()
try:
filename = self._cachefile_path()
with open(filename, 'rb') as f:
uniquedescr, self._data, self._cachetime = pickle.load(f)
- assert(uniquedescr == str(self._uniquedescriptionstr()))
+ assert(uniquedescr == self._uniquedescriptionstr())
if self._expired(self._cachetime):
self._data = None
return False
--
To view, visit
https://gerrit.wikimedia.org/r/169987
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I51b8052a8c6b73452d7a486d60d36393eefb25e0
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>