jenkins-bot has submitted this change and it was merged.

Change subject: tools.py: introduce class DotReadableDict(), super of 
Revision() and FileInfo()
......................................................................


tools.py: introduce class DotReadableDict(), super of Revision() and FileInfo()

Parent class of Page.Revision() and Page.FileInfo().

Provide:
- __getitem__()
- __unicode__()
-__repr__().

Change-Id: I45877492693837da4f53f11f9869a52dea25c3b0
---
M pywikibot/page.py
M pywikibot/tools.py
2 files changed, 38 insertions(+), 38 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/page.py b/pywikibot/page.py
index bb1f515..1befe68 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -48,6 +48,7 @@
     SiteDefinitionError
 )
 from pywikibot.tools import (
+    UnicodeMixin, DotReadableDict,
     ComparableMixin, deprecated, deprecate_arg, deprecated_args,
     remove_last_args, _NotImplementedWarning,
     OrderedDict, Counter,
@@ -64,7 +65,7 @@
 # Note: Link objects (defined later on) represent a wiki-page's title, while
 # Page objects (defined here) represent the page itself, including its 
contents.
 
-class BasePage(pywikibot.UnicodeMixin, ComparableMixin):
+class BasePage(UnicodeMixin, ComparableMixin):
 
     """BasePage: Base object for a MediaWiki page.
 
@@ -4210,7 +4211,7 @@
                 }
 
 
-class Revision(pywikibot.UnicodeMixin):
+class Revision(DotReadableDict):
 
     """A structure holding information about a single revision of a Page."""
 
@@ -4268,29 +4269,8 @@
         return Revision.FullHistEntry(self.revid, self.timestamp, self.user,
                                       self.text, self.rollbacktoken)
 
-    def __getitem__(self, key):
-        """Give access to Revision class values by key.
 
-        Revision class may also give access to its values by keys
-        e.g. revid parameter may be assigned by revision['revid']
-        as well as revision.revid. This makes formatting strings with
-        % operator easier.
-
-        """
-        return getattr(self, key)
-
-    def __unicode__(self):
-        """Return string representation."""
-        _content = u', '.join(
-            u'{0}: {1}'.format(k, v) for k, v in self.__dict__.items())
-        return u'{{{0}}}'.format(_content)
-
-    def __repr__(self):
-        """Return a more complete string representation."""
-        return self.__dict__.__repr__()
-
-
-class FileInfo(pywikibot.UnicodeMixin):
+class FileInfo(DotReadableDict):
 
     """A structure holding imageinfo of latest rev. of FilePage.
 
@@ -4316,23 +4296,9 @@
         self.__dict__.update(file_revision)
         self.timestamp = pywikibot.Timestamp.fromISOformat(self.timestamp)
 
-    def __getitem__(self, key):
-        """Access attributes also with dict.like keys."""
-        return getattr(self, key)
-
     def __eq__(self, other):
         """Test if two File_info objects are equal."""
         return self.__dict__ == other.__dict__
-
-    def __unicode__(self):
-        """Return string representation."""
-        _content = u', '.join(
-            u'{0}: {1}'.format(k, v) for k, v in self.__dict__.items())
-        return u'{{{0}}}'.format(_content)
-
-    def __repr__(self):
-        """Return a more complete string representation."""
-        return self.__dict__.__repr__()
 
 
 class Link(ComparableMixin):
diff --git a/pywikibot/tools.py b/pywikibot/tools.py
index dd5ec2c..cb19499 100644
--- a/pywikibot/tools.py
+++ b/pywikibot/tools.py
@@ -136,6 +136,40 @@
         return other != self._cmpkey()
 
 
+class DotReadableDict(UnicodeMixin):
+
+    """Parent class of Revision() and FileInfo().
+
+    Provide:
+    - __getitem__(), __unicode__() and __repr__().
+
+    """
+
+    def __getitem__(self, key):
+        """Give access to class values by key.
+
+        Revision class may also give access to its values by keys
+        e.g. revid parameter may be assigned by revision['revid']
+        as well as revision.revid. This makes formatting strings with
+        % operator easier.
+
+        """
+        return getattr(self, key)
+
+    def __unicode__(self):
+        """Return string representation."""
+        if sys.version_info[0] > 2:
+            return repr(self.__dict__)
+        else:
+            _content = u', '.join(
+                u'{0}: {1}'.format(k, v) for k, v in self.__dict__.items())
+            return u'{{{0}}}'.format(_content)
+
+    def __repr__(self):
+        """Return a more complete string representation."""
+        return repr(self.__dict___)
+
+
 def concat_options(message, line_length, options):
     """Concatenate options."""
     indent = len(message) + 2

-- 
To view, visit https://gerrit.wikimedia.org/r/190563
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I45877492693837da4f53f11f9869a52dea25c3b0
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to