mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
pep8
This commit is contained in:
parent
3d699bb357
commit
826d5ab725
@ -85,7 +85,7 @@ class WeeklyLWN(BasicNewsRecipe):
|
|||||||
while True:
|
while True:
|
||||||
curr = curr.findNext(attrs={'class': ['SummaryHL', 'Cat1HL', 'Cat2HL']})
|
curr = curr.findNext(attrs={'class': ['SummaryHL', 'Cat1HL', 'Cat2HL']})
|
||||||
|
|
||||||
if curr == None:
|
if curr is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
text = curr.contents[0].string
|
text = curr.contents[0].string
|
||||||
@ -134,10 +134,11 @@ class WeeklyLWN(BasicNewsRecipe):
|
|||||||
else:
|
else:
|
||||||
print >>sys.stderr, "lwn_weekly.recipe: something bad happened; should not be able to reach this"
|
print >>sys.stderr, "lwn_weekly.recipe: something bad happened; should not be able to reach this"
|
||||||
|
|
||||||
ans = [(section, articles[section]) for section in ans if section in articles]
|
ans = [(section2, articles[section2]) for section2 in ans if section2 in articles]
|
||||||
# from pprint import pprint
|
# from pprint import pprint
|
||||||
# pprint(ans)
|
# pprint(ans)
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
# vim: expandtab:ts=4:sw=4
|
# vim: expandtab:ts=4:sw=4
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
## History:
|
import re
|
||||||
## 1: Base Version
|
# History:
|
||||||
## 2: Added rules for wdr.de, ndr.de, br-online.de
|
# 1: Base Version
|
||||||
## 3: Added rules for rbb-online.de, boerse.ard.de, sportschau.de
|
# 2: Added rules for wdr.de, ndr.de, br-online.de
|
||||||
## 4: New design of tagesschau.de implemented. Simplyfied.
|
# 3: Added rules for rbb-online.de, boerse.ard.de, sportschau.de
|
||||||
## 5: Taken out the pictures.
|
# 4: New design of tagesschau.de implemented. Simplyfied.
|
||||||
|
# 5: Taken out the pictures.
|
||||||
|
|
||||||
class Tagesschau(BasicNewsRecipe):
|
class Tagesschau(BasicNewsRecipe):
|
||||||
title = 'Tagesschau'
|
title = 'Tagesschau'
|
||||||
|
@ -114,7 +114,7 @@ class FB2Input(InputFormatPlugin):
|
|||||||
break
|
break
|
||||||
|
|
||||||
opf = OPFCreator(os.getcwdu(), mi)
|
opf = OPFCreator(os.getcwdu(), mi)
|
||||||
entries = [(f, guess_type(f)[0]) for f in os.listdir(u'.')]
|
entries = [(f2, guess_type(f)[0]) for f2 in os.listdir(u'.')]
|
||||||
opf.create_manifest(entries)
|
opf.create_manifest(entries)
|
||||||
opf.create_spine([u'index.xhtml'])
|
opf.create_spine([u'index.xhtml'])
|
||||||
if cpath:
|
if cpath:
|
||||||
@ -127,7 +127,7 @@ class FB2Input(InputFormatPlugin):
|
|||||||
from calibre.ebooks.fb2 import base64_decode
|
from calibre.ebooks.fb2 import base64_decode
|
||||||
self.binary_map = {}
|
self.binary_map = {}
|
||||||
for elem in doc.xpath('./*'):
|
for elem in doc.xpath('./*'):
|
||||||
if elem.text and 'binary' in elem.tag and elem.attrib.has_key('id'):
|
if elem.text and 'binary' in elem.tag and 'id' in elem.attrib:
|
||||||
ct = elem.get('content-type', '')
|
ct = elem.get('content-type', '')
|
||||||
fname = elem.attrib['id']
|
fname = elem.attrib['id']
|
||||||
ext = ct.rpartition('/')[-1].lower()
|
ext = ct.rpartition('/')[-1].lower()
|
||||||
@ -146,3 +146,4 @@ class FB2Input(InputFormatPlugin):
|
|||||||
with open(fname, 'wb') as f:
|
with open(fname, 'wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,8 +105,7 @@ class IndexEntry(object):
|
|||||||
'author_offset': 71,
|
'author_offset': 71,
|
||||||
|
|
||||||
}
|
}
|
||||||
RTAG_MAP = {v:k for k, v in TAG_VALUES.iteritems()}
|
RTAG_MAP = {v:k for k, v in TAG_VALUES.iteritems()} # noqa
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, offset, label_offset):
|
def __init__(self, offset, label_offset):
|
||||||
self.offset, self.label_offset = offset, label_offset
|
self.offset, self.label_offset = offset, label_offset
|
||||||
@ -131,8 +130,10 @@ class IndexEntry(object):
|
|||||||
|
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
def size(self):
|
def size(self):
|
||||||
def fget(self): return self.length
|
def fget(self):
|
||||||
def fset(self, val): self.length = val
|
return self.length
|
||||||
|
def fset(self, val):
|
||||||
|
self.length = val
|
||||||
return property(fget=fget, fset=fset, doc='Alias for length')
|
return property(fget=fget, fset=fset, doc='Alias for length')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -383,7 +384,6 @@ class TBS(object): # {{{
|
|||||||
buf.write(encode_tbs(last_article.index-next_sec.index,
|
buf.write(encode_tbs(last_article.index-next_sec.index,
|
||||||
{0b1000: 0}))
|
{0b1000: 0}))
|
||||||
|
|
||||||
|
|
||||||
# If a section TOC starts and extends into the next record add
|
# If a section TOC starts and extends into the next record add
|
||||||
# a trailing vwi. We detect this by TBS type==3, processing last
|
# a trailing vwi. We detect this by TBS type==3, processing last
|
||||||
# section present in the record, and the last article in that
|
# section present in the record, and the last article in that
|
||||||
@ -460,8 +460,10 @@ class Indexer(object): # {{{
|
|||||||
for node in oeb.toc.iterdescendants():
|
for node in oeb.toc.iterdescendants():
|
||||||
if node.klass == 'article':
|
if node.klass == 'article':
|
||||||
aut, desc = node.author, node.description
|
aut, desc = node.author, node.description
|
||||||
if not aut: aut = _('Unknown')
|
if not aut:
|
||||||
if not desc: desc = _('No details available')
|
aut = _('Unknown')
|
||||||
|
if not desc:
|
||||||
|
desc = _('No details available')
|
||||||
node.author, node.description = aut, desc
|
node.author, node.description = aut, desc
|
||||||
|
|
||||||
self.cncx = CNCX(oeb.toc, self.is_periodical)
|
self.cncx = CNCX(oeb.toc, self.is_periodical)
|
||||||
@ -652,7 +654,6 @@ class Indexer(object): # {{{
|
|||||||
next_offset = self.serializer.body_end_offset
|
next_offset = self.serializer.body_end_offset
|
||||||
index.length = next_offset - index.offset
|
index.length = next_offset - index.offset
|
||||||
|
|
||||||
|
|
||||||
# Remove empty indices
|
# Remove empty indices
|
||||||
indices = [x for x in indices if x.length > 0]
|
indices = [x for x in indices if x.length > 0]
|
||||||
|
|
||||||
@ -885,3 +886,4 @@ class Indexer(object): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,8 @@ class Extract(ODF2XHTML):
|
|||||||
f.write(css.encode('utf-8'))
|
f.write(css.encode('utf-8'))
|
||||||
|
|
||||||
def get_css_for_class(self, cls):
|
def get_css_for_class(self, cls):
|
||||||
if not cls: return None
|
if not cls:
|
||||||
|
return None
|
||||||
for rule in self.css.cssRules.rulesOfType(CSSRule.STYLE_RULE):
|
for rule in self.css.cssRules.rulesOfType(CSSRule.STYLE_RULE):
|
||||||
for sel in rule.selectorList:
|
for sel in rule.selectorList:
|
||||||
q = sel.selectorText
|
q = sel.selectorText
|
||||||
@ -112,7 +113,8 @@ class Extract(ODF2XHTML):
|
|||||||
for img in imgpath(root):
|
for img in imgpath(root):
|
||||||
div2 = img.getparent()
|
div2 = img.getparent()
|
||||||
div1 = div2.getparent()
|
div1 = div2.getparent()
|
||||||
if (len(div1), len(div2)) != (1, 1): continue
|
if (len(div1), len(div2)) != (1, 1):
|
||||||
|
continue
|
||||||
cls = div1.get('class', '')
|
cls = div1.get('class', '')
|
||||||
first_rules = filter(None, [self.get_css_for_class(x) for x in
|
first_rules = filter(None, [self.get_css_for_class(x) for x in
|
||||||
cls.split()])
|
cls.split()])
|
||||||
@ -151,7 +153,6 @@ class Extract(ODF2XHTML):
|
|||||||
style = div2.attrib['style']
|
style = div2.attrib['style']
|
||||||
div2.attrib['style'] = 'display:inline;'+style
|
div2.attrib['style'] = 'display:inline;'+style
|
||||||
|
|
||||||
|
|
||||||
def filter_css(self, root, log):
|
def filter_css(self, root, log):
|
||||||
style = root.xpath('//*[local-name() = "style" and @type="text/css"]')
|
style = root.xpath('//*[local-name() = "style" and @type="text/css"]')
|
||||||
if style:
|
if style:
|
||||||
@ -282,7 +283,7 @@ class Extract(ODF2XHTML):
|
|||||||
zf = ZipFile(stream, 'r')
|
zf = ZipFile(stream, 'r')
|
||||||
self.extract_pictures(zf)
|
self.extract_pictures(zf)
|
||||||
opf = OPFCreator(os.path.abspath(os.getcwdu()), mi)
|
opf = OPFCreator(os.path.abspath(os.getcwdu()), mi)
|
||||||
opf.create_manifest([(os.path.abspath(f), None) for f in
|
opf.create_manifest([(os.path.abspath(f2), None) for f2 in
|
||||||
walk(os.getcwdu())])
|
walk(os.getcwdu())])
|
||||||
opf.create_spine([os.path.abspath('index.xhtml')])
|
opf.create_spine([os.path.abspath('index.xhtml')])
|
||||||
with open('metadata.opf', 'wb') as f:
|
with open('metadata.opf', 'wb') as f:
|
||||||
@ -291,3 +292,4 @@ class Extract(ODF2XHTML):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class DBAdder(QObject): # {{{
|
|||||||
with open(cover, 'rb') as f:
|
with open(cover, 'rb') as f:
|
||||||
cover = f.read()
|
cover = f.read()
|
||||||
orig_formats = formats
|
orig_formats = formats
|
||||||
formats = [f for f in formats if not f.lower().endswith('.opf')]
|
formats = [f2 for f2 in formats if not f2.lower().endswith('.opf')]
|
||||||
if prefs['add_formats_to_existing']: # automerge is on
|
if prefs['add_formats_to_existing']: # automerge is on
|
||||||
identical_book_list = self.db.find_identical_books(mi)
|
identical_book_list = self.db.find_identical_books(mi)
|
||||||
if identical_book_list: # books with same author and nearly same title exist in db
|
if identical_book_list: # books with same author and nearly same title exist in db
|
||||||
@ -385,7 +385,6 @@ class Adder(QObject): # {{{
|
|||||||
if self.continue_updating:
|
if self.continue_updating:
|
||||||
single_shot(self.update)
|
single_shot(self.update)
|
||||||
|
|
||||||
|
|
||||||
def process_duplicates(self):
|
def process_duplicates(self):
|
||||||
duplicates = self.db_adder.duplicates
|
duplicates = self.db_adder.duplicates
|
||||||
if not duplicates:
|
if not duplicates:
|
||||||
@ -427,7 +426,6 @@ class Adder(QObject): # {{{
|
|||||||
del self.db_adder
|
del self.db_adder
|
||||||
self.db_adder = None
|
self.db_adder = None
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def number_of_books_added(self):
|
def number_of_books_added(self):
|
||||||
return getattr(getattr(self, 'db_adder', None), 'number_of_books_added',
|
return getattr(getattr(self, 'db_adder', None), 'number_of_books_added',
|
||||||
@ -489,7 +487,6 @@ class Saver(QObject): # {{{
|
|||||||
self.continue_updating = True
|
self.continue_updating = True
|
||||||
single_shot(self.update)
|
single_shot(self.update)
|
||||||
|
|
||||||
|
|
||||||
def canceled(self):
|
def canceled(self):
|
||||||
self.continue_updating = False
|
self.continue_updating = False
|
||||||
if self.worker is not None:
|
if self.worker is not None:
|
||||||
@ -499,7 +496,6 @@ class Saver(QObject): # {{{
|
|||||||
self.callback(self.worker.path, self.failures, self.worker.error)
|
self.callback(self.worker.path, self.failures, self.worker.error)
|
||||||
self.callback_called = True
|
self.callback_called = True
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if not self.continue_updating:
|
if not self.continue_updating:
|
||||||
return
|
return
|
||||||
@ -531,7 +527,6 @@ class Saver(QObject): # {{{
|
|||||||
self.get_result()
|
self.get_result()
|
||||||
single_shot(self.update)
|
single_shot(self.update)
|
||||||
|
|
||||||
|
|
||||||
def get_result(self):
|
def get_result(self):
|
||||||
try:
|
try:
|
||||||
id, title, ok, tb = self.rq.get_nowait()
|
id, title, ok, tb = self.rq.get_nowait()
|
||||||
@ -549,3 +544,4 @@ class Saver(QObject): # {{{
|
|||||||
self.failures.add((title, tb))
|
self.failures.add((title, tb))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ def dnd_get_files(md, exts):
|
|||||||
remote_urls = [x for x in purls if x.scheme in ('http', 'https',
|
remote_urls = [x for x in purls if x.scheme in ('http', 'https',
|
||||||
'ftp') and posixpath.splitext(x.path)[1][1:].lower() in exts]
|
'ftp') and posixpath.splitext(x.path)[1][1:].lower() in exts]
|
||||||
if remote_urls:
|
if remote_urls:
|
||||||
filenames = [posixpath.basename(urllib.unquote(rurl.path)) for rurl in
|
filenames = [posixpath.basename(urllib.unquote(rurl2.path)) for rurl2 in
|
||||||
remote_urls]
|
remote_urls]
|
||||||
return [urlunparse(x) for x in remote_urls], filenames
|
return [urlunparse(x) for x in remote_urls], filenames
|
||||||
|
|
||||||
@ -336,3 +336,4 @@ def get_firefox_rurl(md, exts):
|
|||||||
def has_firefox_ext(md, exts):
|
def has_firefox_ext(md, exts):
|
||||||
return bool(get_firefox_rurl(md, exts)[0])
|
return bool(get_firefox_rurl(md, exts)[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -2859,15 +2859,11 @@ class BibTeX:
|
|||||||
def ValidateCitationKey(self, text):
|
def ValidateCitationKey(self, text):
|
||||||
"""
|
"""
|
||||||
removes characters not allowed in BibTeX keys
|
removes characters not allowed in BibTeX keys
|
||||||
>>> ValidateCitationKey(DummyEntry('my@id'))
|
|
||||||
'myid'
|
|
||||||
"""
|
"""
|
||||||
return self.invalid_cit.sub(u'', text)
|
return self.invalid_cit.sub(u'', text)
|
||||||
|
|
||||||
def braceUppercase(self, text):
|
def braceUppercase(self, text):
|
||||||
""" Convert uppercase letters to bibtex encoded uppercase
|
""" Convert uppercase letters to bibtex encoded uppercase
|
||||||
>>> braceUppercase('Foo Bar')
|
|
||||||
'{F}oo {B}ar'
|
|
||||||
"""
|
"""
|
||||||
return self.upper.sub(lambda m: u'{%s}' % m.group(), text)
|
return self.upper.sub(lambda m: u'{%s}' % m.group(), text)
|
||||||
|
|
||||||
@ -2906,3 +2902,4 @@ class BibTeX:
|
|||||||
def bibtex_author_format(self, item):
|
def bibtex_author_format(self, item):
|
||||||
# Format authors for Bibtex compliance (get a list as input)
|
# Format authors for Bibtex compliance (get a list as input)
|
||||||
return self.utf8ToBibtex(u' and '.join([author for author in item]))
|
return self.utf8ToBibtex(u' and '.join([author for author in item]))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user