Skip to content

Commit

Permalink
wikibase_item and wikibase_repository as properties, typo in docstring
Browse files Browse the repository at this point in the history
As discussed in mwclient#96 wikibase_item() and wikibase() are
good candidate for properties.
Typo: dictionnary -> dictionary
  • Loading branch information
PierreSelim committed Jul 20, 2018
1 parent 107230c commit 382bf5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 8 additions & 7 deletions mwclient/client.py
Expand Up @@ -118,7 +118,7 @@ def __init__(self, host, path='/w/', ext='.php', pool=None, retry_timeout=30,
self.Images = self.images

# wikibase caching
self.wikibase_site = None
self._wikibase_repository = None

# Initialization status
self.initialized = False
Expand Down Expand Up @@ -1091,17 +1091,18 @@ def ask(self, query, title=None):
for key, value in answers.items():
yield {key: value}

def wikibase(self):
@property
def wikibase_repository(self):
"""Wiki base repository."""
if self.wikibase_site is None:
if self._wikibase_repository is None:
result = self.api('query', meta='wikibase')
url = result['query']['wikibase']['repo']['url']
host = url['base'].replace('//', '')
path = url['scriptpath'] + "/"
self.wikibase_site = WikiBaseSite(('https', host),
path=path,
pool=self.connection)
return self.wikibase_site
self._wikibase_repository = WikiBaseSite(('https', host),
path=path,
pool=self.connection)
return self._wikibase_repository


class WikiBaseSite(Site):
Expand Down
10 changes: 6 additions & 4 deletions mwclient/page.py
Expand Up @@ -66,7 +66,7 @@ def __init__(self, site, name, info=None, extra_properties=None):
self.edit_time = None

# caching wikibase_item
self.item = None
self._wikibase_item = None

def redirects_to(self):
""" Returns the redirect target page, or None if the page is not a redirect page."""
Expand Down Expand Up @@ -496,12 +496,13 @@ def templates(self, namespace=None, generator=True):
return mwclient.listing.PageProperty(self, 'templates', prefix,
return_values='title', **kwargs)

@property
def wikibase_item(self):
"""Item linked to a Page.
if a wikibase item is linked to a page it returns this item,
None otherwise."""
if self.item is None:
if self._wikibase_item is None:
info = self.site.api('query',
prop='pageprops',
titles=self.name,
Expand All @@ -513,5 +514,6 @@ def wikibase_item(self):
# a wikibase_item property
entity = info[pageid]['pageprops']['wikibase_item']
if entity is not None:
self.item = mwclient.entity.Item(self.site.wikibase(), entity)
return self.item
self._wikibase_item = mwclient.entity.Item(self.site.wikibase_repository,
entity)
return self._wikibase_item

0 comments on commit 382bf5f

Please sign in to comment.