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 Aug 30, 2015
1 parent a660b7d commit a0a5847
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .idea/dictionaries/Pierre_Selim.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions mwclient/client.py
Expand Up @@ -105,7 +105,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 @@ -789,17 +789,18 @@ def ask(self, query, title=None):
result = self.raw_api('ask', query=query, **kwargs)
return result['query']['results']

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 @@ -57,7 +57,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 @@ -453,12 +453,13 @@ def templates(self, namespace=None, generator=True):
else:
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 @@ -470,5 +471,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 a0a5847

Please sign in to comment.