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
@ -22,7 +22,7 @@ class WeeklyLWN(BasicNewsRecipe):
|
|||||||
remove_javascript = True
|
remove_javascript = True
|
||||||
|
|
||||||
cover_url = site_url + '/images/lcorner.png'
|
cover_url = site_url + '/images/lcorner.png'
|
||||||
#masthead_url = 'http://lwn.net/images/lcorner.png'
|
# masthead_url = 'http://lwn.net/images/lcorner.png'
|
||||||
publication_type = 'magazine'
|
publication_type = 'magazine'
|
||||||
|
|
||||||
remove_tags_before = dict(attrs={'class':'PageHeadline'})
|
remove_tags_before = dict(attrs={'class':'PageHeadline'})
|
||||||
@ -83,9 +83,9 @@ class WeeklyLWN(BasicNewsRecipe):
|
|||||||
subsection = None
|
subsection = None
|
||||||
|
|
||||||
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
|
||||||
@ -106,7 +106,7 @@ class WeeklyLWN(BasicNewsRecipe):
|
|||||||
section_title = section
|
section_title = section
|
||||||
|
|
||||||
# Most articles have anchors in their titles, *except* the security vulnerabilities
|
# Most articles have anchors in their titles, *except* the security vulnerabilities
|
||||||
article_anchor = curr.findNext(name = 'a', attrs = { 'href': re.compile('^/Articles/') } )
|
article_anchor = curr.findNext(name='a', attrs={'href': re.compile('^/Articles/')})
|
||||||
|
|
||||||
if article_anchor:
|
if article_anchor:
|
||||||
article_url = article_anchor.get('href')
|
article_url = article_anchor.get('href')
|
||||||
@ -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,8 +185,8 @@ 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
|
||||||
self.merged_books.add(mi.title)
|
self.merged_books.add(mi.title)
|
||||||
@ -221,7 +221,7 @@ class DBAdder(QObject): # {{{
|
|||||||
self.number_of_books_added += 1
|
self.number_of_books_added += 1
|
||||||
self.add_formats(id_, formats)
|
self.add_formats(id_, formats)
|
||||||
|
|
||||||
else: #automerge is off
|
else: # automerge is off
|
||||||
id_ = self.db.create_book_entry(mi, cover=cover, add_duplicates=False)
|
id_ = self.db.create_book_entry(mi, cover=cover, add_duplicates=False)
|
||||||
if id_ is None:
|
if id_ is None:
|
||||||
self.duplicates.append((mi, cover, orig_formats))
|
self.duplicates.append((mi, cover, orig_formats))
|
||||||
@ -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))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ def dnd_get_files(md, exts):
|
|||||||
purls = [urlparse(u) for u in urls]
|
purls = [urlparse(u) for u in urls]
|
||||||
# First look for a local file
|
# First look for a local file
|
||||||
local_files = [u2p(x) for x in purls if x.scheme in ('', 'file')]
|
local_files = [u2p(x) for x in purls if x.scheme in ('', 'file')]
|
||||||
local_files = [ p for p in local_files if
|
local_files = [p for p in local_files if
|
||||||
posixpath.splitext(urllib.unquote(p))[1][1:].lower() in
|
posixpath.splitext(urllib.unquote(p))[1][1:].lower() in
|
||||||
exts]
|
exts]
|
||||||
local_files = [x for x in local_files if os.path.exists(x)]
|
local_files = [x for x in local_files if os.path.exists(x)]
|
||||||
@ -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])
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ utf8enc2latex_mapping = {
|
|||||||
# The extraction has been done by the "create_unimap.py" script
|
# The extraction has been done by the "create_unimap.py" script
|
||||||
# located at <http://docutils.sf.net/tools/dev/create_unimap.py>.
|
# located at <http://docutils.sf.net/tools/dev/create_unimap.py>.
|
||||||
|
|
||||||
#Fix some encoding problem between cp1252 and latin1
|
# Fix some encoding problem between cp1252 and latin1
|
||||||
# from http://www.microsoft.com/typography/unicode/1252.htm
|
# from http://www.microsoft.com/typography/unicode/1252.htm
|
||||||
u'\x80': '{\\texteuro}', # EURO SIGN
|
u'\x80': '{\\texteuro}', # EURO SIGN
|
||||||
u'\x82': '{,}', # SINGLE LOW-9 QUOTATION MARK
|
u'\x82': '{,}', # SINGLE LOW-9 QUOTATION MARK
|
||||||
@ -2465,7 +2465,7 @@ utf8enc2latex_mapping = {
|
|||||||
u'\U0001d7fe': '$\\mathtt{8}$',
|
u'\U0001d7fe': '$\\mathtt{8}$',
|
||||||
u'\U0001d7ff': '$\\mathtt{9}$',
|
u'\U0001d7ff': '$\\mathtt{9}$',
|
||||||
|
|
||||||
#Items from simple list
|
# Items from simple list
|
||||||
u'\u0106': "{\\a\\'C}",
|
u'\u0106': "{\\a\\'C}",
|
||||||
u'\u0408': '{\\CYRJE}',
|
u'\u0408': '{\\CYRJE}',
|
||||||
u'\u20ac': '{\\texteuro}',
|
u'\u20ac': '{\\texteuro}',
|
||||||
@ -2796,45 +2796,45 @@ utf8enc2latex_mapping = {
|
|||||||
u'\u016f': '{\\r u}',
|
u'\u016f': '{\\r u}',
|
||||||
u'\xfa': "{\\'u}"
|
u'\xfa': "{\\'u}"
|
||||||
|
|
||||||
#Items to add at a latter date (check first)
|
# Items to add at a latter date (check first)
|
||||||
#u'\u0000': r'{$\alpha$}',
|
# u'\u0000': r'{$\alpha$}',
|
||||||
#u'\u0000': r'{$\beta$}',
|
# u'\u0000': r'{$\beta$}',
|
||||||
#u'\u0000': r'{$\gamma$}',
|
# u'\u0000': r'{$\gamma$}',
|
||||||
#u'\u0000': r'{$\delta$}',
|
# u'\u0000': r'{$\delta$}',
|
||||||
#u'\u0000': r'{$\epsilon$}',
|
# u'\u0000': r'{$\epsilon$}',
|
||||||
#u'\u0000': r'{$\varepsilon$}',
|
# u'\u0000': r'{$\varepsilon$}',
|
||||||
#u'\u0000': r'{$\zeta$}',
|
# u'\u0000': r'{$\zeta$}',
|
||||||
#u'\u0000': r'{$\eta$}',
|
# u'\u0000': r'{$\eta$}',
|
||||||
#u'\u0000': r'{$\theta$}',
|
# u'\u0000': r'{$\theta$}',
|
||||||
#u'\u0000': r'{$\vartheta$}',
|
# u'\u0000': r'{$\vartheta$}',
|
||||||
#u'\u0000': r'{$\iota$}',
|
# u'\u0000': r'{$\iota$}',
|
||||||
#u'\u0000': r'{$\kappa$}',
|
# u'\u0000': r'{$\kappa$}',
|
||||||
#u'\u0000': r'{$\lambda$}',
|
# u'\u0000': r'{$\lambda$}',
|
||||||
#u'\u0000': r'{$\mu$}',
|
# u'\u0000': r'{$\mu$}',
|
||||||
#u'\u0000': r'{$\xi$}',
|
# u'\u0000': r'{$\xi$}',
|
||||||
#u'\u0000': r'{$\pi$}',
|
# u'\u0000': r'{$\pi$}',
|
||||||
#u'\u0000': r'{$\varpi$}',
|
# u'\u0000': r'{$\varpi$}',
|
||||||
#u'\u0000': r'{$\rho$}',
|
# u'\u0000': r'{$\rho$}',
|
||||||
#u'\u0000': r'{$\varrho$}',
|
# u'\u0000': r'{$\varrho$}',
|
||||||
#u'\u0000': r'{$\sigma$}',
|
# u'\u0000': r'{$\sigma$}',
|
||||||
#u'\u0000': r'{$\varsigma$}',
|
# u'\u0000': r'{$\varsigma$}',
|
||||||
#u'\u0000': r'{$\tau$}',
|
# u'\u0000': r'{$\tau$}',
|
||||||
#u'\u0000': r'{$\upsilon$}',
|
# u'\u0000': r'{$\upsilon$}',
|
||||||
#u'\u0000': r'{$\phi$}',
|
# u'\u0000': r'{$\phi$}',
|
||||||
#u'\u0000': r'{$\varphi$}',
|
# u'\u0000': r'{$\varphi$}',
|
||||||
#u'\u0000': r'{$\psi$}',
|
# u'\u0000': r'{$\psi$}',
|
||||||
#u'\u0000': r'{$\omega$}',
|
# u'\u0000': r'{$\omega$}',
|
||||||
#u'\u0000': r'{$\Gamma$}',
|
# u'\u0000': r'{$\Gamma$}',
|
||||||
#u'\u0000': r'{$\Delta$}',
|
# u'\u0000': r'{$\Delta$}',
|
||||||
#u'\u0000': r'{$\Theta$}',
|
# u'\u0000': r'{$\Theta$}',
|
||||||
#u'\u0000': r'{$\Lambda$}',
|
# u'\u0000': r'{$\Lambda$}',
|
||||||
#u'\u0000': r'{$\Xi$}',
|
# u'\u0000': r'{$\Xi$}',
|
||||||
#u'\u0000': r'{$\Pi$}',
|
# u'\u0000': r'{$\Pi$}',
|
||||||
#u'\u0000': r'{$\Sigma$}',
|
# u'\u0000': r'{$\Sigma$}',
|
||||||
#u'\u0000': r'{$\Upsilon$}',
|
# u'\u0000': r'{$\Upsilon$}',
|
||||||
#u'\u0000': r'{$\Phi$}',
|
# u'\u0000': r'{$\Phi$}',
|
||||||
#u'\u0000': r'{$\Psi$}',
|
# u'\u0000': r'{$\Psi$}',
|
||||||
#u'\u0000': r'{$\Omega$}',
|
# u'\u0000': r'{$\Omega$}',
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_mapping = {
|
entity_mapping = {
|
||||||
@ -2847,7 +2847,7 @@ class BibTeX:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.rep_utf8 = MReplace(utf8enc2latex_mapping)
|
self.rep_utf8 = MReplace(utf8enc2latex_mapping)
|
||||||
self.rep_ent = MReplace(entity_mapping)
|
self.rep_ent = MReplace(entity_mapping)
|
||||||
#Set default conversion to ASCII BibTeX
|
# Set default conversion to ASCII BibTeX
|
||||||
self.ascii_bibtex = True
|
self.ascii_bibtex = True
|
||||||
# This substitution is based on the description of cite key restrictions at
|
# This substitution is based on the description of cite key restrictions at
|
||||||
# http://bibdesk.sourceforge.net/manual/BibDesk%20Help_2.html
|
# http://bibdesk.sourceforge.net/manual/BibDesk%20Help_2.html
|
||||||
@ -2859,27 +2859,23 @@ 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)
|
||||||
|
|
||||||
def resolveEntities(self, text):
|
def resolveEntities(self, text):
|
||||||
#for entity, entity_map in entity_mapping.iteritems():
|
# for entity, entity_map in entity_mapping.iteritems():
|
||||||
# text = text.replace(entity, entity_map)
|
# text = text.replace(entity, entity_map)
|
||||||
#return text
|
# return text
|
||||||
return self.rep_ent.mreplace(text)
|
return self.rep_ent.mreplace(text)
|
||||||
|
|
||||||
def resolveUnicode(self, text):
|
def resolveUnicode(self, text):
|
||||||
#UTF-8 text as entry
|
# UTF-8 text as entry
|
||||||
#for unichar, latexenc in utf8enc2latex_mapping.iteritems() :
|
# for unichar, latexenc in utf8enc2latex_mapping.iteritems() :
|
||||||
# text = text.replace(unichar, latexenc)
|
# text = text.replace(unichar, latexenc)
|
||||||
text = self.rep_utf8.mreplace(text)
|
text = self.rep_utf8.mreplace(text)
|
||||||
return text.replace(u'$}{$', u'')
|
return text.replace(u'$}{$', u'')
|
||||||
@ -2891,9 +2887,9 @@ class BibTeX:
|
|||||||
text.replace('\\', '\\\\')
|
text.replace('\\', '\\\\')
|
||||||
return self.escape.sub(lambda m: u'\\%s' % m.group(), text)
|
return self.escape.sub(lambda m: u'\\%s' % m.group(), text)
|
||||||
|
|
||||||
#Calibre functions
|
# Calibre functions
|
||||||
#Option to go to official ASCII Bibtex or unofficial UTF-8
|
# Option to go to official ASCII Bibtex or unofficial UTF-8
|
||||||
#Go from an unicode entry to ASCII Bibtex format without encoding
|
# Go from an unicode entry to ASCII Bibtex format without encoding
|
||||||
def utf8ToBibtex(self, text):
|
def utf8ToBibtex(self, text):
|
||||||
if len(text) == 0:
|
if len(text) == 0:
|
||||||
return ''
|
return ''
|
||||||
@ -2904,5 +2900,6 @@ class BibTeX:
|
|||||||
return self.escapeSpecialCharacters(text)
|
return self.escapeSpecialCharacters(text)
|
||||||
|
|
||||||
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