Skip to content

Commit

Permalink
Merge "[IMPR] add LogEntry.params as a public property"
Browse files Browse the repository at this point in the history
  • Loading branch information
xqt authored and Gerrit Code Review committed Sep 26, 2024
2 parents e41cb13 + a1b6d95 commit 1997bc5
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions pywikibot/logentries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Objects representing MediaWiki log entries."""
#
# (C) Pywikibot team, 2007-2023
# (C) Pywikibot team, 2007-2024
#
# Distributed under the terms of the MIT license.
#
Expand Down Expand Up @@ -94,8 +94,12 @@ def __getattr__(self, item: str) -> Any:
return super().__getattribute__(item)

@property
def _params(self) -> dict[str, Any]:
"""Additional data for some log entry types."""
def params(self) -> dict[str, Any]:
"""Additional data for some log entry types.
.. versionadded:: 9.4
private *_param* attribute became a public property
"""
return self.get('params', {})

@cached
Expand Down Expand Up @@ -182,7 +186,7 @@ def flags(self) -> list[str]:
if self.action() == 'unblock':
return []

return self._params.get('flags', [])
return self.params.get('flags', [])

@cached
def duration(self) -> datetime.timedelta | None:
Expand All @@ -198,7 +202,7 @@ def duration(self) -> datetime.timedelta | None:
@cached
def expiry(self) -> pywikibot.Timestamp | None:
"""Return a Timestamp representing the block expiry date."""
details = self._params.get('expiry')
details = self.params.get('expiry')
return pywikibot.Timestamp.fromISOformat(details) if details else None


Expand All @@ -217,7 +221,7 @@ def oldgroups(self) -> list[str]:
LogEntry has no additional data e.g. due to hidden data and
insufficient rights.
"""
return self._params.get('oldgroups', [])
return self.params.get('oldgroups', [])

@property
def newgroups(self) -> list[str]:
Expand All @@ -228,7 +232,7 @@ def newgroups(self) -> list[str]:
LogEntry has no additional data e.g. due to hidden data and
insufficient rights.
"""
return self._params.get('newgroups', [])
return self.params.get('newgroups', [])


class UploadEntry(LogEntry):
Expand All @@ -252,12 +256,12 @@ class MoveEntry(LogEntry):
@property
def target_ns(self) -> pywikibot.site._namespace.Namespace:
"""Return namespace object of target page."""
return self.site.namespaces[self._params['target_ns']]
return self.site.namespaces[self.params['target_ns']]

@property
def target_title(self) -> str:
"""Return the target title."""
return self._params['target_title']
return self.params['target_title']

@property
@cached
Expand All @@ -268,7 +272,7 @@ def target_page(self) -> pywikibot.page.Page:
def suppressedredirect(self) -> bool:
"""Return True if no redirect was created during the move."""
# Introduced in MW r47901
return 'suppressedredirect' in self._params
return 'suppressedredirect' in self.params


class PatrolEntry(LogEntry):
Expand All @@ -280,17 +284,17 @@ class PatrolEntry(LogEntry):
@property
def current_id(self) -> int:
"""Return the current id."""
return int(self._params['curid'])
return int(self.params['curid'])

@property
def previous_id(self) -> int:
"""Return the previous id."""
return int(self._params['previd'])
return int(self.params['previd'])

@property
def auto(self) -> bool:
"""Return auto patrolled."""
return 'auto' in self._params and self._params['auto'] != 0
return 'auto' in self.params and self.params['auto'] != 0


class LogEntryFactory:
Expand Down

0 comments on commit 1997bc5

Please sign in to comment.