Skip to content

Commit

Permalink
Use super() instead of explicit class naming
Browse files Browse the repository at this point in the history
Fix #127
  • Loading branch information
lukasjuhrich committed Jul 24, 2016
1 parent 2c2555d commit 1767209
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions mwclient/errors.py
Expand Up @@ -19,7 +19,7 @@ class APIError(MwClientError):
def __init__(self, code, info, kwargs):
self.code = code
self.info = info
MwClientError.__init__(self, code, info, kwargs)
super(APIError, self).__init__(code, info, kwargs)


class InsufficientPermission(MwClientError):
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, response_text=None):
'you used the correct hostname. If you did, the server might ' + \
'be wrongly configured or experiencing temporary problems.'
self.response_text = response_text
MwClientError.__init__(self, self.message, response_text)
super(InvalidResponse, self).__init__(self.message, response_text)

def __str__(self):
return self.message
13 changes: 8 additions & 5 deletions mwclient/ex.py
Expand Up @@ -47,11 +47,14 @@ def __init__(self, *config_files, **kwargs):

do_login = 'username' in self.config and 'password' in self.config

client.Site.__init__(self, host=self.config['host'],
path=self.config['path'], ext=self.config.get('ext', '.php'),
do_init=not do_login,
retry_timeout=self.config.get('retry_timeout', 30),
max_retries=self.config.get('max_retries', -1))
super(ConfiguredSite, self).__init__(
host=self.config['host'],
path=self.config['path'],
ext=self.config.get('ext', '.php'),
do_init=not do_login,
retry_timeout=self.config.get('retry_timeout', 30),
max_retries=self.config.get('max_retries', -1),
)

if do_login:
self.login(self.config['username'],
Expand Down
25 changes: 16 additions & 9 deletions mwclient/listing.py
Expand Up @@ -143,7 +143,7 @@ def get_list(generator=False):

class NestedList(List):
def __init__(self, nested_param, *args, **kwargs):
List.__init__(self, *args, **kwargs)
super(NestedList, self).__init__(*args, **kwargs)
self.nested_param = nested_param

def set_iter(self, data):
Expand All @@ -153,7 +153,8 @@ def set_iter(self, data):
class GeneratorList(List):

def __init__(self, site, list_name, prefix, *args, **kwargs):
List.__init__(self, site, list_name, prefix, *args, **kwargs)
super(GeneratorList, self).__init__(site, list_name, prefix,
*args, **kwargs)

self.args['g' + self.prefix + 'limit'] = self.args[self.prefix + 'limit']
del self.args[self.prefix + 'limit']
Expand All @@ -167,7 +168,7 @@ def __init__(self, site, list_name, prefix, *args, **kwargs):
self.page_class = mwclient.page.Page

def __next__(self):
info = List.__next__(self, full=True)
info = super(GeneratorList, self).__next__(full=True)
if info['ns'] == 14:
return Category(self.site, u'', info)
if info['ns'] == 6:
Expand All @@ -182,7 +183,7 @@ def load_chunk(self):
# Put this here so that the constructor does not fail
# on uninitialized sites
self.args['iiprop'] = 'timestamp|user|comment|url|size|sha1|metadata|archivename'
return List.load_chunk(self)
return super(GeneratorList, self).load_chunk()


class Category(mwclient.page.Page, GeneratorList):
Expand Down Expand Up @@ -219,8 +220,10 @@ def __init__(self, site, prefix=None, start=None, namespace=0, redirects='all',
if end:
kwargs['gapto'] = end

GeneratorList.__init__(self, site, 'allpages', 'ap',
gapnamespace=text_type(namespace), gapfilterredir=redirects, **kwargs)
super(PageList, self).__init__(site, 'allpages', 'ap',
gapnamespace=text_type(namespace),
gapfilterredir=redirects,
**kwargs)

def __getitem__(self, name):
return self.get(name, None)
Expand Down Expand Up @@ -257,7 +260,9 @@ def guess_namespace(self, name):
class PageProperty(List):

def __init__(self, page, prop, prefix, *args, **kwargs):
List.__init__(self, page.site, prop, prefix, titles=page.name, *args, **kwargs)
super(PageProperty, self).__init__(page.site, prop, prefix,
titles=page.name,
*args, **kwargs)
self.page = page
self.generator = 'prop'

Expand All @@ -272,7 +277,9 @@ def set_iter(self, data):
class PagePropertyGenerator(GeneratorList):

def __init__(self, page, prop, prefix, *args, **kwargs):
GeneratorList.__init__(self, page.site, prop, prefix, titles=page.name, *args, **kwargs)
super(PagePropertyGenerator, self).__init__(page.site, prop, prefix,
titles=page.name,
*args, **kwargs)
self.page = page


Expand All @@ -281,4 +288,4 @@ class RevisionsIterator(PageProperty):
def load_chunk(self):
if 'rvstartid' in self.args and 'rvstart' in self.args:
del self.args['rvstart']
return PageProperty.load_chunk(self)
return super(RevisionsIterator, self).load_chunk()

0 comments on commit 1767209

Please sign in to comment.