Convert language & getDisabledReasons to methods.

Both are more properties of a webcomic (this is part of the design
changes for #42)
This commit is contained in:
Tobias Gruetzmacher 2016-04-19 23:53:46 +02:00
parent df46907f39
commit 190cd3b063

View file

@ -310,8 +310,7 @@ class Scraper(object):
def fetchText(cls, url, data, textSearch, optional): def fetchText(cls, url, data, textSearch, optional):
raise ValueError("No implementation for fetchText!") raise ValueError("No implementation for fetchText!")
@classmethod def getDisabledReasons(self):
def getDisabledReasons(cls):
""" """
Get a dict of reasons why this comic module is disabled. The key is a Get a dict of reasons why this comic module is disabled. The key is a
short (unique) identifier, the value is a string explaining why the short (unique) identifier, the value is a string explaining why the
@ -320,22 +319,22 @@ class Scraper(object):
""" """
return {} return {}
@classmethod def language(self):
def language(cls):
""" """
Return language of the comic as a human-readable language name instead Return language of the comic as a human-readable language name instead
of a 2-character ISO639-1 code. of a 2-character ISO639-1 code.
""" """
lang = 'Unknown (%s)' % cls.lang lang = 'Unknown (%s)' % self.lang
if pycountry is None: if pycountry is None:
if cls.lang in languages.Languages: if self.lang in languages.Languages:
lang = languages.Languages[cls.lang] lang = languages.Languages[self.lang]
else: else:
try: try:
lang = pycountry.languages.get(alpha2=cls.lang).name lang = pycountry.languages.get(alpha2=self.lang).name
except KeyError: except KeyError:
try: try:
lang = pycountry.languages.get(iso639_1_code=cls.lang).name lang = pycountry.languages.get(
iso639_1_code=self.lang).name
except KeyError: except KeyError:
pass pass
return lang return lang
@ -505,10 +504,9 @@ class _ParserScraper(Scraper):
else: else:
return None return None
@classmethod def getDisabledReasons(self):
def getDisabledReasons(cls):
res = {} res = {}
if cls.css and cssselect is None: if self.css and cssselect is None:
res['css'] = (u"This module needs the cssselect " + res['css'] = (u"This module needs the cssselect " +
u"(python-cssselect) python module which is " + u"(python-cssselect) python module which is " +
u"not installed.") u"not installed.")