From a0a5847c1c5306ce9f77f9206efbe7ff57636898 Mon Sep 17 00:00:00 2001 From: Pierre-Selim Date: Sun, 30 Aug 2015 12:56:44 +0200 Subject: [PATCH] wikibase_item and wikibase_repository as properties, typo in docstring As discussed in mwclient/mwclient#96 wikibase_item() and wikibase() are good candidate for properties. Typo: dictionnary -> dictionary --- .idea/dictionaries/Pierre_Selim.xml | 7 +++++++ mwclient/client.py | 15 ++++++++------- mwclient/page.py | 10 ++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .idea/dictionaries/Pierre_Selim.xml diff --git a/.idea/dictionaries/Pierre_Selim.xml b/.idea/dictionaries/Pierre_Selim.xml new file mode 100644 index 00000000..c98ed000 --- /dev/null +++ b/.idea/dictionaries/Pierre_Selim.xml @@ -0,0 +1,7 @@ + + + + dictionnary + + + \ No newline at end of file diff --git a/mwclient/client.py b/mwclient/client.py index d14cb087..c8a0d0d1 100644 --- a/mwclient/client.py +++ b/mwclient/client.py @@ -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 @@ -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): diff --git a/mwclient/page.py b/mwclient/page.py index fa2fe2d1..344b713d 100644 --- a/mwclient/page.py +++ b/mwclient/page.py @@ -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.""" @@ -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, @@ -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