From ebbb27d05da0f178bc3ac2408861c6acea582ccd Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Mon, 13 Feb 2017 22:41:17 +0100 Subject: [PATCH] Move xpath_class to helpers module. --- dosagelib/helpers.py | 8 +++++++- dosagelib/plugins/a.py | 4 ++-- dosagelib/plugins/b.py | 4 ++-- dosagelib/plugins/c.py | 4 ++-- dosagelib/plugins/comicfury.py | 3 +-- dosagelib/plugins/common.py | 10 ++-------- dosagelib/plugins/d.py | 4 ++-- dosagelib/plugins/e.py | 4 ++-- dosagelib/plugins/f.py | 6 +++--- dosagelib/plugins/g.py | 6 +++--- dosagelib/plugins/gocomics.py | 3 +-- dosagelib/plugins/i.py | 5 +++-- dosagelib/plugins/j.py | 4 ++-- dosagelib/plugins/k.py | 3 ++- dosagelib/plugins/m.py | 3 ++- dosagelib/plugins/n.py | 7 +++---- dosagelib/plugins/o.py | 3 ++- dosagelib/plugins/p.py | 4 ++-- dosagelib/plugins/r.py | 5 +++-- dosagelib/plugins/s.py | 5 ++--- dosagelib/plugins/t.py | 7 +++---- dosagelib/plugins/u.py | 6 +++--- dosagelib/plugins/v.py | 3 +-- dosagelib/plugins/w.py | 6 +++--- dosagelib/plugins/z.py | 4 ++-- 25 files changed, 60 insertions(+), 61 deletions(-) diff --git a/dosagelib/helpers.py b/dosagelib/helpers.py index 5b701965a..d07e5e9f1 100644 --- a/dosagelib/helpers.py +++ b/dosagelib/helpers.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function @@ -52,3 +52,9 @@ def indirectStarter(self): data = self.getPage(url) newurl = self.fetchUrl(url, data, self.latestSearch) return self.link_modifier(url, newurl) + + +def xpath_class(name): + """Returns an XPath expressions which finds a tag which has a specified + class.""" + return 'contains(concat(" ", @class, " "), " %s ")' % name diff --git a/dosagelib/plugins/a.py b/dosagelib/plugins/a.py index 41356d103..c3be9f64f 100644 --- a/dosagelib/plugins/a.py +++ b/dosagelib/plugins/a.py @@ -9,8 +9,8 @@ from re import compile, escape, MULTILINE from ..util import tagre from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import regexNamer, bounceStarter, indirectStarter -from .common import _WordPressScraper, xpath_class, WP_LATEST_SEARCH +from ..helpers import regexNamer, bounceStarter, indirectStarter, xpath_class +from .common import _WordPressScraper, WP_LATEST_SEARCH class AbstruseGoose(_BasicScraper): diff --git a/dosagelib/plugins/b.py b/dosagelib/plugins/b.py index bad0e1d24..20ca5d409 100644 --- a/dosagelib/plugins/b.py +++ b/dosagelib/plugins/b.py @@ -9,9 +9,9 @@ from re import compile, escape from ..util import tagre from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from .common import (_ComicControlScraper, _WordPressScraper, _WPNaviIn, - WP_PREV_SEARCH, xpath_class) + WP_PREV_SEARCH) class BadassMuthas(_BasicScraper): diff --git a/dosagelib/plugins/c.py b/dosagelib/plugins/c.py index 97f3369a0..a004dd9e6 100644 --- a/dosagelib/plugins/c.py +++ b/dosagelib/plugins/c.py @@ -8,9 +8,9 @@ from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import bounceStarter, indirectStarter +from ..helpers import bounceStarter, indirectStarter, xpath_class from ..util import tagre -from .common import _TumblrScraper, _WordPressScraper, xpath_class +from .common import _TumblrScraper, _WordPressScraper class CampComic(_BasicScraper): diff --git a/dosagelib/plugins/comicfury.py b/dosagelib/plugins/comicfury.py index cb3a16176..a80320f34 100644 --- a/dosagelib/plugins/comicfury.py +++ b/dosagelib/plugins/comicfury.py @@ -8,8 +8,7 @@ from __future__ import absolute_import, division, print_function import os from ..scraper import _ParserScraper -from ..helpers import bounceStarter -from .common import xpath_class +from ..helpers import bounceStarter, xpath_class XPATH_LINK = '//a[%s and contains(text(), "%s")]' XPATH_IMG = '//a[%s][img[contains(@alt, "%s")]]' diff --git a/dosagelib/plugins/common.py b/dosagelib/plugins/common.py index 2ef009206..53b7e32f8 100644 --- a/dosagelib/plugins/common.py +++ b/dosagelib/plugins/common.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from ..scraper import _ParserScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class # Common base classes for comics with the same structure (same hosting # software, for example) go here. Since those are shared by many modules, @@ -14,12 +14,6 @@ from ..helpers import indirectStarter # expression is for which comics. -def xpath_class(name): - """Returns an XPath expressions which finds a tag which has a specified - class.""" - return 'contains(concat(" ", @class, " "), " %s ")' % name - - WP_LATEST_SEARCH = '//a[%s]' % xpath_class('comic-nav-last') WP_PREV_SEARCH = '//a[%s]' % xpath_class('comic-nav-previous') diff --git a/dosagelib/plugins/d.py b/dosagelib/plugins/d.py index 30b30594b..2f21d6d7b 100644 --- a/dosagelib/plugins/d.py +++ b/dosagelib/plugins/d.py @@ -8,9 +8,9 @@ from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter, bounceStarter +from ..helpers import indirectStarter, bounceStarter, xpath_class from ..util import tagre -from .common import _WordPressScraper, xpath_class +from .common import _WordPressScraper class DamnLol(_ParserScraper): diff --git a/dosagelib/plugins/e.py b/dosagelib/plugins/e.py index efc167fe3..2b92d0eba 100644 --- a/dosagelib/plugins/e.py +++ b/dosagelib/plugins/e.py @@ -8,10 +8,10 @@ from __future__ import absolute_import, division, print_function import os from re import compile, escape, IGNORECASE -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from .common import _WordPressScraper, WP_LATEST_SEARCH, xpath_class +from .common import _WordPressScraper, WP_LATEST_SEARCH class EarthsongSaga(_ParserScraper): diff --git a/dosagelib/plugins/f.py b/dosagelib/plugins/f.py index d80adec4f..0b3acaf94 100644 --- a/dosagelib/plugins/f.py +++ b/dosagelib/plugins/f.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile, escape, IGNORECASE from ..util import tagre from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter -from .common import _WPNaviIn, _WordPressScraper, xpath_class +from ..helpers import indirectStarter, xpath_class +from .common import _WPNaviIn, _WordPressScraper class FalconTwin(_BasicScraper): diff --git a/dosagelib/plugins/g.py b/dosagelib/plugins/g.py index 2db85ffe3..fc5badcb7 100644 --- a/dosagelib/plugins/g.py +++ b/dosagelib/plugins/g.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from ..util import tagre -from .common import _ComicControlScraper, _WordPressScraper, xpath_class +from .common import _ComicControlScraper, _WordPressScraper class Galaxion(_BasicScraper): diff --git a/dosagelib/plugins/gocomics.py b/dosagelib/plugins/gocomics.py index 244c741f2..cc28383b8 100644 --- a/dosagelib/plugins/gocomics.py +++ b/dosagelib/plugins/gocomics.py @@ -6,8 +6,7 @@ from __future__ import absolute_import, division, print_function from ..scraper import _ParserScraper -from ..helpers import bounceStarter -from .common import xpath_class +from ..helpers import bounceStarter, xpath_class class GoComics(_ParserScraper): diff --git a/dosagelib/plugins/i.py b/dosagelib/plugins/i.py index 07ea7d332..1c93fe20d 100644 --- a/dosagelib/plugins/i.py +++ b/dosagelib/plugins/i.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile, escape +from ..helpers import xpath_class from ..scraper import _BasicScraper from ..util import tagre -from .common import _WordPressScraper, xpath_class +from .common import _WordPressScraper class IAmArg(_BasicScraper): diff --git a/dosagelib/plugins/j.py b/dosagelib/plugins/j.py index 2fb82a05b..89f9eb2fa 100644 --- a/dosagelib/plugins/j.py +++ b/dosagelib/plugins/j.py @@ -9,8 +9,8 @@ from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from ..helpers import indirectStarter -from .common import _ComicControlScraper, xpath_class +from ..helpers import indirectStarter, xpath_class +from .common import _ComicControlScraper class JackCannon(_BasicScraper): diff --git a/dosagelib/plugins/k.py b/dosagelib/plugins/k.py index 7b99de411..dd6e19eb5 100644 --- a/dosagelib/plugins/k.py +++ b/dosagelib/plugins/k.py @@ -7,9 +7,10 @@ from __future__ import absolute_import, division, print_function from re import compile, escape, IGNORECASE +from ..helpers import xpath_class from ..scraper import _BasicScraper from ..util import tagre -from .common import _ComicControlScraper, _WordPressScraper, xpath_class +from .common import _ComicControlScraper, _WordPressScraper class KevinAndKell(_BasicScraper): diff --git a/dosagelib/plugins/m.py b/dosagelib/plugins/m.py index bebabf8ff..57973ec9a 100755 --- a/dosagelib/plugins/m.py +++ b/dosagelib/plugins/m.py @@ -7,9 +7,10 @@ from __future__ import absolute_import, division, print_function from re import compile, escape, IGNORECASE +from ..helpers import xpath_class from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from .common import _ComicControlScraper, _WordPressScraper, xpath_class +from .common import _ComicControlScraper, _WordPressScraper class MacHall(_BasicScraper): diff --git a/dosagelib/plugins/n.py b/dosagelib/plugins/n.py index 63acac854..533d5d435 100644 --- a/dosagelib/plugins/n.py +++ b/dosagelib/plugins/n.py @@ -1,17 +1,16 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from ..util import tagre -from .common import (_ComicControlScraper, _WordPressScraper, WP_LATEST_SEARCH, - xpath_class) +from .common import _ComicControlScraper, _WordPressScraper, WP_LATEST_SEARCH class Namesake(_ComicControlScraper): diff --git a/dosagelib/plugins/o.py b/dosagelib/plugins/o.py index 21e8862d1..b3495f5f8 100644 --- a/dosagelib/plugins/o.py +++ b/dosagelib/plugins/o.py @@ -7,9 +7,10 @@ from __future__ import absolute_import, division, print_function from re import compile, escape +from ..helpers import xpath_class from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from .common import _WordPressScraper, xpath_class +from .common import _WordPressScraper class OctopusPie(_ParserScraper): diff --git a/dosagelib/plugins/p.py b/dosagelib/plugins/p.py index 38366940e..0fcc65e2c 100644 --- a/dosagelib/plugins/p.py +++ b/dosagelib/plugins/p.py @@ -8,9 +8,9 @@ from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import bounceStarter, queryNamer, indirectStarter +from ..helpers import bounceStarter, queryNamer, indirectStarter, xpath_class from ..util import tagre -from .common import _ComicControlScraper, _WordPressScraper, xpath_class +from .common import _ComicControlScraper, _WordPressScraper class PandyLand(_WordPressScraper): diff --git a/dosagelib/plugins/r.py b/dosagelib/plugins/r.py index b52e730a0..2322c0c08 100644 --- a/dosagelib/plugins/r.py +++ b/dosagelib/plugins/r.py @@ -1,16 +1,17 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile from six.moves.urllib.parse import urljoin +from ..helpers import xpath_class from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from .common import _WordPressScraper, xpath_class +from .common import _WordPressScraper class RadioactivePanda(_BasicScraper): diff --git a/dosagelib/plugins/s.py b/dosagelib/plugins/s.py index cf9e7f695..48dab95cf 100644 --- a/dosagelib/plugins/s.py +++ b/dosagelib/plugins/s.py @@ -10,10 +10,9 @@ from os.path import splitext import datetime from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter, bounceStarter +from ..helpers import indirectStarter, bounceStarter, xpath_class from ..util import tagre -from .common import (_ComicControlScraper, _WordPressScraper, WP_LATEST_SEARCH, - xpath_class) +from .common import _ComicControlScraper, _WordPressScraper, WP_LATEST_SEARCH class SabrinaOnline(_BasicScraper): diff --git a/dosagelib/plugins/t.py b/dosagelib/plugins/t.py index 963edba31..e85efd628 100644 --- a/dosagelib/plugins/t.py +++ b/dosagelib/plugins/t.py @@ -1,17 +1,16 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile, escape, IGNORECASE from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from ..util import tagre -from .common import (_ComicControlScraper, _TumblrScraper, _WordPressScraper, - xpath_class) +from .common import _ComicControlScraper, _TumblrScraper, _WordPressScraper class TheBrads(_ParserScraper): diff --git a/dosagelib/plugins/u.py b/dosagelib/plugins/u.py index 874801b45..10057e74e 100644 --- a/dosagelib/plugins/u.py +++ b/dosagelib/plugins/u.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from ..util import tagre -from .common import _WordPressScraper, xpath_class +from .common import _WordPressScraper class Underling(_WordPressScraper): diff --git a/dosagelib/plugins/v.py b/dosagelib/plugins/v.py index 1dc89c4cb..7cb0e9dcf 100644 --- a/dosagelib/plugins/v.py +++ b/dosagelib/plugins/v.py @@ -7,9 +7,8 @@ from __future__ import absolute_import, division, print_function from re import compile from ..scraper import _BasicScraper, _ParserScraper -from ..helpers import indirectStarter +from ..helpers import indirectStarter, xpath_class from ..util import tagre -from .common import xpath_class class VampireCheerleaders(_BasicScraper): diff --git a/dosagelib/plugins/w.py b/dosagelib/plugins/w.py index 790234693..7e2189823 100644 --- a/dosagelib/plugins/w.py +++ b/dosagelib/plugins/w.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function @@ -9,8 +9,8 @@ from re import compile, escape, IGNORECASE from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from ..helpers import indirectStarter -from .common import _ComicControlScraper, _WordPressScraper, xpath_class +from ..helpers import indirectStarter, xpath_class +from .common import _ComicControlScraper, _WordPressScraper class WapsiSquare(_WordPressScraper): diff --git a/dosagelib/plugins/z.py b/dosagelib/plugins/z.py index d8ab6e7e5..b63f68168 100644 --- a/dosagelib/plugins/z.py +++ b/dosagelib/plugins/z.py @@ -9,8 +9,8 @@ from re import compile, escape from ..scraper import _BasicScraper, _ParserScraper from ..util import tagre -from ..helpers import bounceStarter -from .common import _WordPressScraper, xpath_class +from ..helpers import bounceStarter, xpath_class +from .common import _WordPressScraper class ZapComic(_ParserScraper):