mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pull from trunk
This commit is contained in:
commit
dbc2d315ed
@ -970,7 +970,12 @@ class Canvas(LRFStream):
|
|||||||
stream = cStringIO.StringIO(self.stream)
|
stream = cStringIO.StringIO(self.stream)
|
||||||
while stream.tell() < len(self.stream):
|
while stream.tell() < len(self.stream):
|
||||||
tag = Tag(stream)
|
tag = Tag(stream)
|
||||||
self._contents.append(PutObj(self._document.objects, *struct.unpack("<HHI", tag.contents)))
|
try:
|
||||||
|
self._contents.append(
|
||||||
|
PutObj(self._document.objects,
|
||||||
|
*struct.unpack("<HHI", tag.contents)))
|
||||||
|
except struct.error:
|
||||||
|
print 'Canvas object has errors, skipping.'
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
s = '\n<%s objid="%s" '%(self.__class__.__name__, self.id,)
|
s = '\n<%s objid="%s" '%(self.__class__.__name__, self.id,)
|
||||||
|
@ -313,8 +313,10 @@ class MobiReader(object):
|
|||||||
self.read_embedded_metadata(root, metadata_elems[0], guide)
|
self.read_embedded_metadata(root, metadata_elems[0], guide)
|
||||||
for elem in guides + metadata_elems:
|
for elem in guides + metadata_elems:
|
||||||
elem.getparent().remove(elem)
|
elem.getparent().remove(elem)
|
||||||
|
fname = self.name.encode('ascii', 'replace')
|
||||||
|
fname = re.sub(r'[\x08\x15\0]+', '', fname)
|
||||||
htmlfile = os.path.join(output_dir,
|
htmlfile = os.path.join(output_dir,
|
||||||
sanitize_file_name(self.name)+'.html')
|
sanitize_file_name(fname)+'.html')
|
||||||
try:
|
try:
|
||||||
for ref in guide.xpath('descendant::reference'):
|
for ref in guide.xpath('descendant::reference'):
|
||||||
if ref.attrib.has_key('href'):
|
if ref.attrib.has_key('href'):
|
||||||
@ -396,8 +398,8 @@ class MobiReader(object):
|
|||||||
'xx-large' : '6',
|
'xx-large' : '6',
|
||||||
}
|
}
|
||||||
mobi_version = self.book_header.mobi_version
|
mobi_version = self.book_header.mobi_version
|
||||||
style_map = {}
|
|
||||||
for i, tag in enumerate(root.iter(etree.Element)):
|
for i, tag in enumerate(root.iter(etree.Element)):
|
||||||
|
tag.attrib.pop('xmlns', '')
|
||||||
if tag.tag in ('country-region', 'place', 'placetype', 'placename',
|
if tag.tag in ('country-region', 'place', 'placetype', 'placename',
|
||||||
'state', 'city', 'street', 'address', 'content'):
|
'state', 'city', 'street', 'address', 'content'):
|
||||||
tag.tag = 'div' if tag.tag == 'content' else 'span'
|
tag.tag = 'div' if tag.tag == 'content' else 'span'
|
||||||
|
@ -81,7 +81,12 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30,
|
|||||||
for x in to:
|
for x in to:
|
||||||
return sendmail_direct(from_, x, msg, timeout, localhost, verbose)
|
return sendmail_direct(from_, x, msg, timeout, localhost, verbose)
|
||||||
import smtplib
|
import smtplib
|
||||||
cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL
|
class SMTP_SSL(smtplib.SMTP_SSL): # Workaround for bug in smtplib.py
|
||||||
|
def _get_socket(self, host, port, timeout):
|
||||||
|
smtplib.SMTP_SSL._get_socket(self, host, port, timeout)
|
||||||
|
return self.sock
|
||||||
|
|
||||||
|
cls = smtplib.SMTP if encryption == 'TLS' else SMTP_SSL
|
||||||
timeout = None # Non-blocking sockets sometimes don't work
|
timeout = None # Non-blocking sockets sometimes don't work
|
||||||
port = int(port)
|
port = int(port)
|
||||||
s = cls(timeout=timeout, local_hostname=localhost)
|
s = cls(timeout=timeout, local_hostname=localhost)
|
||||||
@ -93,6 +98,8 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30,
|
|||||||
s.starttls()
|
s.starttls()
|
||||||
s.ehlo()
|
s.ehlo()
|
||||||
if username is not None and password is not None:
|
if username is not None and password is not None:
|
||||||
|
if encryption == 'SSL':
|
||||||
|
s.sock = s.file.sslobj
|
||||||
s.login(username, password)
|
s.login(username, password)
|
||||||
s.sendmail(from_, to, msg)
|
s.sendmail(from_, to, msg)
|
||||||
return s.quit()
|
return s.quit()
|
||||||
|
@ -177,6 +177,8 @@ class ProgressBar:
|
|||||||
self.width = self.term.COLS or 75
|
self.width = self.term.COLS or 75
|
||||||
self.bar = term.render(self.BAR)
|
self.bar = term.render(self.BAR)
|
||||||
self.header = self.term.render(self.HEADER % header.center(self.width))
|
self.header = self.term.render(self.HEADER % header.center(self.width))
|
||||||
|
if isinstance(self.header, unicode):
|
||||||
|
self.header = self.header.encode('utf-8')
|
||||||
self.cleared = 1 #: true if we haven't drawn the bar yet.
|
self.cleared = 1 #: true if we haven't drawn the bar yet.
|
||||||
|
|
||||||
def update(self, percent, message=''):
|
def update(self, percent, message=''):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user