Kenneth Reitz’s Code Style™
See http://docs.python-requests.org/en/master/dev/contributing/#kenneth-reitz-s-code-style Effectively, this removes "visual" indents.
This commit is contained in:
parent
2850420303
commit
6ba1e49bfd
8 changed files with 55 additions and 53 deletions
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
||||||
# Copyright (C) 2012-2014 Bastian Kleineidam
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
# Copyright (C) 2015-2018 Tobias Gruetzmacher
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
@ -49,54 +49,54 @@ def setup_options():
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
|
|
||||||
parser.add_argument('-v', '--verbose', action='count', default=0,
|
parser.add_argument('-v', '--verbose', action='count', default=0,
|
||||||
help='provides verbose output, use multiple times for more verbosity')
|
help='provides verbose output, use multiple times for more verbosity')
|
||||||
parser.add_argument('-n', '--numstrips', action='store', type=int, default=0,
|
parser.add_argument('-n', '--numstrips', action='store', type=int, default=0,
|
||||||
help='traverse and retrieve the given number of comic strips; use --all to retrieve all comic strips')
|
help='traverse and retrieve the given number of comic strips; use --all to retrieve all comic strips')
|
||||||
parser.add_argument('-a', '--all', action='store_true',
|
parser.add_argument('-a', '--all', action='store_true',
|
||||||
help='traverse and retrieve all comic strips')
|
help='traverse and retrieve all comic strips')
|
||||||
parser.add_argument('-c', '--continue', action='store_true', dest='cont',
|
parser.add_argument('-c', '--continue', action='store_true', dest='cont',
|
||||||
help='traverse and retrieve comic strips until an existing one is found')
|
help='traverse and retrieve comic strips until an existing one is found')
|
||||||
parser.add_argument('-b', '--basepath', action='store', default='Comics',
|
parser.add_argument('-b', '--basepath', action='store', default='Comics',
|
||||||
metavar='PATH',
|
metavar='PATH',
|
||||||
help='set the path to create invidivual comic directories in, default is Comics')
|
help='set the path to create invidivual comic directories in, default is Comics')
|
||||||
parser.add_argument('--baseurl', action='store', metavar='PATH',
|
parser.add_argument('--baseurl', action='store', metavar='PATH',
|
||||||
help='the base URL of your comics directory (for RSS, HTML, etc.); this should correspond to --base-path')
|
help='the base URL of your comics directory (for RSS, HTML, etc.); this should correspond to --base-path')
|
||||||
parser.add_argument('-l', '--list', action='store_true',
|
parser.add_argument('-l', '--list', action='store_true',
|
||||||
help='list available comic modules')
|
help='list available comic modules')
|
||||||
parser.add_argument('--singlelist', action='store_true',
|
parser.add_argument('--singlelist', action='store_true',
|
||||||
help='list available comic modules in a single column list')
|
help='list available comic modules in a single column list')
|
||||||
parser.add_argument('--version', action='store_true',
|
parser.add_argument('--version', action='store_true',
|
||||||
help='display the version number')
|
help='display the version number')
|
||||||
parser.add_argument('--vote', action='store_true',
|
parser.add_argument('--vote', action='store_true',
|
||||||
help='vote for the selected comics')
|
help='vote for the selected comics')
|
||||||
parser.add_argument('-m', '--modulehelp', action='store_true',
|
parser.add_argument('-m', '--modulehelp', action='store_true',
|
||||||
help='display help for comic modules')
|
help='display help for comic modules')
|
||||||
parser.add_argument('-t', '--timestamps', action='store_true',
|
parser.add_argument('-t', '--timestamps', action='store_true',
|
||||||
help='print timestamps for all output at any info level')
|
help='print timestamps for all output at any info level')
|
||||||
parser.add_argument('-o', '--output', action='append', dest='handler',
|
parser.add_argument('-o', '--output', action='append', dest='handler',
|
||||||
choices=events.getHandlerNames(),
|
choices=events.getHandlerNames(),
|
||||||
help='sets output handlers for downloaded comics')
|
help='sets output handlers for downloaded comics')
|
||||||
parser.add_argument('--no-downscale', action='store_false',
|
parser.add_argument('--no-downscale', action='store_false',
|
||||||
dest='allowdownscale',
|
dest='allowdownscale',
|
||||||
help='prevent downscaling when using html or rss handler')
|
help='prevent downscaling when using html or rss handler')
|
||||||
parser.add_argument('-p', '--parallel', action='store', type=int, default=1,
|
parser.add_argument('-p', '--parallel', action='store', type=int, default=1,
|
||||||
help='fetch comics in parallel. Specify the number of connections')
|
help='fetch comics in parallel. Specify the number of connections')
|
||||||
parser.add_argument('--adult', action='store_true',
|
parser.add_argument('--adult', action='store_true',
|
||||||
help='confirms that you are old enough to view adult content')
|
help='confirms that you are old enough to view adult content')
|
||||||
parser.add_argument('--allow-multiple', action='store_true',
|
parser.add_argument('--allow-multiple', action='store_true',
|
||||||
help='allows multiple instances to run at the same time. Use if you know what you are doing.')
|
help='allows multiple instances to run at the same time. Use if you know what you are doing.')
|
||||||
# used for development testing prev/next matching
|
# used for development testing prev/next matching
|
||||||
parser.add_argument('--dry-run', action='store_true',
|
parser.add_argument('--dry-run', action='store_true',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
# multimatch is only used for development, eg. testing if all comics of a scripted plugin are working
|
# multimatch is only used for development, eg. testing if all comics of a scripted plugin are working
|
||||||
parser.add_argument('--multimatch', action='store_true',
|
parser.add_argument('--multimatch', action='store_true',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
# List all comic modules, even those normally suppressed, because they
|
# List all comic modules, even those normally suppressed, because they
|
||||||
# are not "real" (moved & removed)
|
# are not "real" (moved & removed)
|
||||||
parser.add_argument('--list-all', action='store_true',
|
parser.add_argument('--list-all', action='store_true',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
parser.add_argument('comic', nargs='*',
|
parser.add_argument('comic', nargs='*',
|
||||||
help='comic module name (including case insensitive substrings)')
|
help='comic module name (including case insensitive substrings)')
|
||||||
try:
|
try:
|
||||||
import argcomplete
|
import argcomplete
|
||||||
argcomplete.autocomplete(parser)
|
argcomplete.autocomplete(parser)
|
||||||
|
@ -249,7 +249,8 @@ def do_list(column_list=True, verbose=False, listall=False):
|
||||||
"""List available comics."""
|
"""List available comics."""
|
||||||
with out.pager():
|
with out.pager():
|
||||||
out.info(u'Available comic scrapers:')
|
out.info(u'Available comic scrapers:')
|
||||||
out.info(u'Comics tagged with [%s] require age confirmation with the --adult option.' % TAG_ADULT)
|
out.info(u'Comics tagged with [{}] require age confirmation'
|
||||||
|
' with the --adult option.'.format(TAG_ADULT))
|
||||||
out.info(u'Non-english comics are tagged with [%s].' % TAG_LANG)
|
out.info(u'Non-english comics are tagged with [%s].' % TAG_LANG)
|
||||||
scrapers = sorted(scraper.get_scrapers(listall),
|
scrapers = sorted(scraper.get_scrapers(listall),
|
||||||
key=lambda s: s.name.lower())
|
key=lambda s: s.name.lower())
|
||||||
|
@ -260,7 +261,8 @@ def do_list(column_list=True, verbose=False, listall=False):
|
||||||
out.info(u'%d supported comics.' % num)
|
out.info(u'%d supported comics.' % num)
|
||||||
if disabled:
|
if disabled:
|
||||||
out.info('')
|
out.info('')
|
||||||
out.info(u'Some comics are disabled, they are tagged with [%s:REASON], where REASON is one of:' % TAG_DISABLED)
|
out.info(u'Some comics are disabled, they are tagged with'
|
||||||
|
' [{}:REASON], where REASON is one of:'.format(TAG_DISABLED))
|
||||||
for k in disabled:
|
for k in disabled:
|
||||||
out.info(u' %-10s %s' % (k, disabled[k]))
|
out.info(u' %-10s %s' % (k, disabled[k]))
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -231,7 +231,7 @@ class DresdenCodak(_ParserScraper):
|
||||||
startUrl = url + 'cat/comic/'
|
startUrl = url + 'cat/comic/'
|
||||||
firstStripUrl = url + '2007/02/08/pom/'
|
firstStripUrl = url + '2007/02/08/pom/'
|
||||||
imageSearch = '//section[%s]//img[%s]' % (
|
imageSearch = '//section[%s]//img[%s]' % (
|
||||||
xpath_class('entry-content'), xpath_class('aligncenter'))
|
xpath_class('entry-content'), xpath_class('aligncenter'))
|
||||||
prevSearch = '//a[img[contains(@src, "prev")]]'
|
prevSearch = '//a[img[contains(@src, "prev")]]'
|
||||||
latestSearch = '//a[%s]' % xpath_class('tc-grid-bg-link')
|
latestSearch = '//a[%s]' % xpath_class('tc-grid-bg-link')
|
||||||
starter = indirectStarter
|
starter = indirectStarter
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
||||||
# Copyright (C) 2012-2014 Bastian Kleineidam
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
# Copyright (C) 2015-2018 Tobias Gruetzmacher
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class EarthsongSaga(_ParserScraper):
|
||||||
imgmatch = compile(r'images/vol(\d+)/ch(\d+)/(.*)\.\w+$',
|
imgmatch = compile(r'images/vol(\d+)/ch(\d+)/(.*)\.\w+$',
|
||||||
IGNORECASE).search(image_url)
|
IGNORECASE).search(image_url)
|
||||||
return 'vol%02d_ch%02d_%s' % (
|
return 'vol%02d_ch%02d_%s' % (
|
||||||
int(imgmatch.group(1)), int(imgmatch.group(2)), imgmatch.group(3))
|
int(imgmatch.group(1)), int(imgmatch.group(2)), imgmatch.group(3))
|
||||||
|
|
||||||
|
|
||||||
class EasilyAmused(_WordPressScraper):
|
class EasilyAmused(_WordPressScraper):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
||||||
# Copyright (C) 2012-2014 Bastian Kleineidam
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
# Copyright (C) 2015-2018 Tobias Gruetzmacher
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
@ -90,13 +90,13 @@ class ScenesFromAMultiverse(_BasicScraper):
|
||||||
stripUrl = url + '%s/'
|
stripUrl = url + '%s/'
|
||||||
firstStripUrl = stripUrl % '2010/06/14/parenthood'
|
firstStripUrl = stripUrl % '2010/06/14/parenthood'
|
||||||
imageSearch = (
|
imageSearch = (
|
||||||
compile(tagre("div", "id", "comic") + r"\s*" +
|
compile(tagre("div", "id", "comic") + r"\s*" +
|
||||||
tagre("img", "src",
|
tagre("img", "src",
|
||||||
r'(.*amultiverse.com/wp-content/uploads/\d+/\d+/[^"]+)')),
|
r'(.*amultiverse.com/wp-content/uploads/\d+/\d+/[^"]+)')),
|
||||||
compile(tagre("div", "id", "comic") + r"\s*" +
|
compile(tagre("div", "id", "comic") + r"\s*" +
|
||||||
tagre("a", "href", r'[^"]*') +
|
tagre("a", "href", r'[^"]*') +
|
||||||
tagre("img", "src",
|
tagre("img", "src",
|
||||||
r'(.*amultiverse.com/wp-content/uploads/\d+/\d+/[^"]+)')),
|
r'(.*amultiverse.com/wp-content/uploads/\d+/\d+/[^"]+)')),
|
||||||
)
|
)
|
||||||
prevSearch = compile(tagre("a", "href", r'(%scomic/\d+\d+/\d+/\d+/[^"]+)' % rurl, after="prev"))
|
prevSearch = compile(tagre("a", "href", r'(%scomic/\d+\d+/\d+/\d+/[^"]+)' % rurl, after="prev"))
|
||||||
help = 'Index format: yyyy/mm/dd/stripname'
|
help = 'Index format: yyyy/mm/dd/stripname'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
||||||
# Copyright (C) 2012-2014 Bastian Kleineidam
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
# Copyright (C) 2015-2016 Tobias Gruetzmacher
|
# Copyright (C) 2015-2018 Tobias Gruetzmacher
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ def _check_strip(outdir, strip, multipleImagesPerStrip):
|
||||||
files.append(fn)
|
files.append(fn)
|
||||||
assert images, 'failed to find images at %s' % strip.strip_url
|
assert images, 'failed to find images at %s' % strip.strip_url
|
||||||
if not multipleImagesPerStrip:
|
if not multipleImagesPerStrip:
|
||||||
assert len(images) == 1, 'found more than 1 image at %s: %s' % (
|
assert len(images) == 1, 'found more than 1 image at {}: {}'.format(
|
||||||
strip.strip_url, images)
|
strip.strip_url, images)
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,6 +114,6 @@ def _check_stripurl(strip, scraperobj):
|
||||||
urlmatch = "^%s$" % urlmatch
|
urlmatch = "^%s$" % urlmatch
|
||||||
ro = re.compile(urlmatch)
|
ro = re.compile(urlmatch)
|
||||||
mo = ro.search(strip.strip_url)
|
mo = ro.search(strip.strip_url)
|
||||||
err = 'strip URL %r does not match stripUrl pattern %s' % (
|
err = 'strip URL {!r} does not match stripUrl pattern {}'.format(
|
||||||
strip.strip_url, urlmatch)
|
strip.strip_url, urlmatch)
|
||||||
assert mo is not None, err
|
assert mo is not None, err
|
||||||
|
|
|
@ -24,12 +24,12 @@ def get_test_scrapers():
|
||||||
# Get limited number of scraper tests on Travis builds to make it
|
# Get limited number of scraper tests on Travis builds to make it
|
||||||
# faster
|
# faster
|
||||||
testscrapernames = [
|
testscrapernames = [
|
||||||
# "classic" _BasicScraper
|
# "classic" _BasicScraper
|
||||||
'AbstruseGoose',
|
'AbstruseGoose',
|
||||||
# complex _ParserScraper
|
# complex _ParserScraper
|
||||||
'GoComics/CalvinAndHobbes',
|
'GoComics/CalvinAndHobbes',
|
||||||
# _WordPressScraper
|
# _WordPressScraper
|
||||||
'GrrlPower'
|
'GrrlPower'
|
||||||
]
|
]
|
||||||
scraper_pattern = re.compile('^(' + '|'.join(testscrapernames) +
|
scraper_pattern = re.compile('^(' + '|'.join(testscrapernames) +
|
||||||
')$')
|
')$')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
||||||
# Copyright (C) 2012-2014 Bastian Kleineidam
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
# Copyright (C) 2015-2018 Tobias Gruetzmacher
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ class TestURL(object):
|
||||||
|
|
||||||
def test_normalisation(self):
|
def test_normalisation(self):
|
||||||
# Test URL normalisation.
|
# Test URL normalisation.
|
||||||
assert normaliseURL('http://example.com//bar/baz&baz') == \
|
assert (normaliseURL('http://example.com//bar/baz&baz') ==
|
||||||
u'http://example.com/bar/baz&baz'
|
u'http://example.com/bar/baz&baz')
|
||||||
|
|
||||||
|
|
||||||
class TestRegex(object):
|
class TestRegex(object):
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -32,7 +32,7 @@ deps =
|
||||||
[flake8]
|
[flake8]
|
||||||
# we aim for 79, but this suppresses warnings for now...
|
# we aim for 79, but this suppresses warnings for now...
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
ignore = E121,E126,E241,FI12,FI14,FI15,FI50,FI51,FI53,FI54,FI55
|
ignore = E127,E128,E241,FI12,FI14,FI15,FI50,FI51,FI53,FI54,FI55
|
||||||
require-code = True
|
require-code = True
|
||||||
min-version = 2.7
|
min-version = 2.7
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue