New MOBI writer: Change values of dictype and cdetype fields to be the same as for the old writer. Fixes #847766 (8.18 doesn't overwrite previous days newsfeeds for same publications)

This commit is contained in:
Kovid Goyal 2011-09-12 14:21:34 -06:00
parent 1ecfb81a07
commit 2bf6e7bed0
5 changed files with 133 additions and 113 deletions

View File

@ -13,6 +13,7 @@ class USAToday(BasicNewsRecipe):
title = 'USA Today' title = 'USA Today'
__author__ = 'Kovid Goyal' __author__ = 'Kovid Goyal'
oldest_article = 1 oldest_article = 1
publication_type = 'newspaper'
timefmt = '' timefmt = ''
max_articles_per_feed = 20 max_articles_per_feed = 20
language = 'en' language = 'en'

View File

@ -61,6 +61,13 @@ class MobiWriter(object):
def __call__(self, oeb, path_or_stream): def __call__(self, oeb, path_or_stream):
self.log = oeb.log self.log = oeb.log
pt = None
if oeb.metadata.publication_type:
x = unicode(oeb.metadata.publication_type[0]).split(':')
if len(x) > 1:
pt = x[1].lower()
self.publication_type = pt
if hasattr(path_or_stream, 'write'): if hasattr(path_or_stream, 'write'):
return self.dump_stream(oeb, path_or_stream) return self.dump_stream(oeb, path_or_stream)
with open(path_or_stream, 'w+b') as stream: with open(path_or_stream, 'w+b') as stream:
@ -351,7 +358,7 @@ class MobiWriter(object):
elif self.indexer.is_periodical: elif self.indexer.is_periodical:
# If you change this, remember to change the cdetype in the EXTH # If you change this, remember to change the cdetype in the EXTH
# header as well # header as well
bt = 0x103 bt = {'newspaper':0x101}.get(self.publication_type, 0x103)
record0.write(pack(b'>IIIII', record0.write(pack(b'>IIIII',
0xe8, bt, 65001, uid, 6)) 0xe8, bt, 65001, uid, 6))
@ -525,15 +532,16 @@ class MobiWriter(object):
nrecs += 1 nrecs += 1
# Write cdetype # Write cdetype
if self.is_periodical: if not self.is_periodical:
# If you set the book type header field to 0x101 use NWPR here if exth.write(pack(b'>II', 501, 12))
# you use 0x103 use MAGZ exth.write(b'EBOK')
data = b'MAGZ'
else:
data = b'EBOK'
exth.write(pack(b'>II', 501, len(data)+8))
exth.write(data)
nrecs += 1 nrecs += 1
else:
# Should be b'NWPR' for doc type of 0x101 and b'MAGZ' for doctype
# of 0x103 but the old writer didn't write them, and I dont know
# what it should be for type 0x102 (b'BLOG'?) so write nothing
# instead
pass
# Add a publication date entry # Add a publication date entry
if oeb.metadata['date']: if oeb.metadata['date']:

View File

@ -146,6 +146,11 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
self.config = {} self.config = {}
self.is_running = False self.is_running = False
self.exception = None self.exception = None
self.config['/'] = {
'tools.sessions.on' : True,
'tools.sessions.timeout': 60, # Session times out after 60 minutes
}
if not wsgi: if not wsgi:
self.setup_loggers() self.setup_loggers()
cherrypy.engine.bonjour.subscribe() cherrypy.engine.bonjour.subscribe()
@ -154,6 +159,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
'tools.gzip.mime_types': ['text/html', 'text/plain', 'tools.gzip.mime_types': ['text/html', 'text/plain',
'text/xml', 'text/javascript', 'text/css'], 'text/xml', 'text/javascript', 'text/css'],
} }
if opts.password: if opts.password:
self.config['/'] = { self.config['/'] = {
'tools.digest_auth.on' : True, 'tools.digest_auth.on' : True,

View File

@ -28,6 +28,10 @@ class Browser(B):
B.set_cookiejar(self, *args, **kwargs) B.set_cookiejar(self, *args, **kwargs)
self._clone_actions['set_cookiejar'] = ('set_cookiejar', args, kwargs) self._clone_actions['set_cookiejar'] = ('set_cookiejar', args, kwargs)
@property
def cookiejar(self):
return self._clone_actions['set_cookiejar'][1][0]
def set_handle_redirect(self, *args, **kwargs): def set_handle_redirect(self, *args, **kwargs):
B.set_handle_redirect(self, *args, **kwargs) B.set_handle_redirect(self, *args, **kwargs)
self._clone_actions['set_handle_redirect'] = ('set_handle_redirect', self._clone_actions['set_handle_redirect'] = ('set_handle_redirect',

View File

@ -671,8 +671,9 @@ def set_response_cookie(path=None, path_header=None, name='session_id',
# save it to disk and the session is lost if people close # save it to disk and the session is lost if people close
# the browser. So we have to use the old "expires" ... sigh ... # the browser. So we have to use the old "expires" ... sigh ...
## cookie[name]['max-age'] = timeout * 60 ## cookie[name]['max-age'] = timeout * 60
if timeout: if False and timeout: # Changed by Kovid, we want the user to have to
cookie[name]['expires'] = http.HTTPDate(time.time() + (timeout * 60)) # re-authenticate on browser restart
cookie[name]['expires'] = http.HTTPDate(time.time() + timeout)
if domain is not None: if domain is not None:
cookie[name]['domain'] = domain cookie[name]['domain'] = domain
if secure: if secure: