mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-05-07 12:02:25 +02:00
Only apply open_page_in_browser when use_browser_cache_only:true
This commit is contained in:
parent
60c14c2cef
commit
ccd25b0c93
5 changed files with 17 additions and 29 deletions
|
|
@ -77,7 +77,7 @@ class BaseBrowserCache(object):
|
|||
# use newest
|
||||
if entrytuple and (not rettuple or rettuple[1] < entrytuple[1]):
|
||||
rettuple = entrytuple
|
||||
logger.debug("\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n%s"%key)
|
||||
# logger.debug("\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n%s"%key)
|
||||
|
||||
if rettuple is None:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class BlockfileCache(BaseChromiumCache):
|
|||
if self.cacheBlock.type != CacheBlock.INDEX:
|
||||
raise Exception("Invalid Index File")
|
||||
logger.debug("Using BlockfileCache")
|
||||
#self.scan_cache_keys()
|
||||
# self.scan_cache_keys()
|
||||
# 1/0
|
||||
|
||||
def scan_cache_keys(self):
|
||||
"""
|
||||
|
|
@ -59,6 +60,7 @@ class BlockfileCache(BaseChromiumCache):
|
|||
Saving uint32 address as key--hashing to find key later proved
|
||||
unreliable.
|
||||
"""
|
||||
logger.debug("scan_cache_keys")
|
||||
with share_open(os.path.join(self.cache_dir, "index"), 'rb') as index:
|
||||
# Skipping Header
|
||||
index.seek(92*4)
|
||||
|
|
@ -81,7 +83,7 @@ class BlockfileCache(BaseChromiumCache):
|
|||
entry = CacheEntry(cacheaddr)
|
||||
self.add_key_mapping_entry(entry)
|
||||
def add_key_mapping_entry(self,entry):
|
||||
if '/11377932/' in entry.keyToStr():
|
||||
if '/14161667/' in entry.keyToStr():
|
||||
logger.debug(entry)
|
||||
logger.debug("data length:%s"%len(entry.data))
|
||||
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ class FirefoxCache2(BaseBrowserCache):
|
|||
"""Constructor for FirefoxCache2"""
|
||||
super(FirefoxCache2,self).__init__(*args, **kargs)
|
||||
logger.debug("Using FirefoxCache2")
|
||||
#self.scan_cache_keys()
|
||||
#1/0
|
||||
# self.scan_cache_keys()
|
||||
# 1/0
|
||||
|
||||
def scan_cache_keys(self):
|
||||
"""Scan cache entries to save entries in this cache"""
|
||||
|
|
@ -54,7 +54,7 @@ class FirefoxCache2(BaseBrowserCache):
|
|||
for entry in os.scandir(os.path.join(self.cache_dir,'entries')):
|
||||
with share_open(entry.path, "rb") as entry_file:
|
||||
metadata = _read_entry_headers(entry_file)
|
||||
if '14093457' in metadata['key']:
|
||||
if '7395422' in metadata['key']:
|
||||
logger.debug("%s->%s"%(metadata['key'],metadata['key_hash']))
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from ..six import ensure_binary, ensure_text
|
|||
from ..exceptions import BrowserCacheException
|
||||
from .share_open import share_open
|
||||
|
||||
from .base_chromium import BaseChromiumCache, EPOCH_DIFFERENCE
|
||||
from .base_chromium import BaseChromiumCache
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -51,8 +51,8 @@ class SimpleCache(BaseChromiumCache):
|
|||
"""Constructor for SimpleCache"""
|
||||
super(SimpleCache,self).__init__(*args, **kargs)
|
||||
logger.debug("Using SimpleCache")
|
||||
#self.scan_cache_keys()
|
||||
#1/0
|
||||
# self.scan_cache_keys()
|
||||
# 1/0
|
||||
|
||||
def scan_cache_keys(self):
|
||||
"""Scan cache entries to save entries in this cache"""
|
||||
|
|
@ -98,24 +98,6 @@ class SimpleCache(BaseChromiumCache):
|
|||
return False
|
||||
return False
|
||||
|
||||
# def get_data_impl(self, url):
|
||||
# """
|
||||
# returns location, entry age(unix epoch), content-encoding and
|
||||
# raw(compressed) data
|
||||
# """
|
||||
# logger.debug("simple get impl ================================= ")
|
||||
# url = ensure_text(url)
|
||||
# logger.debug(url)
|
||||
# retval = None
|
||||
# for fullkey in self.make_keys(url):
|
||||
|
||||
# entrytuple = self.get_data_key_impl(url, fullkey)
|
||||
# # use newest
|
||||
# if entrytuple and (not retval or retval[1] < entrytuple[1]):
|
||||
# retval = entrytuple
|
||||
# logger.debug("\n------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n%s"%fullkey)
|
||||
# return retval
|
||||
|
||||
def get_data_key_impl(self, url, key):
|
||||
"""
|
||||
returns location, entry age(unix epoch), content-encoding and
|
||||
|
|
|
|||
|
|
@ -48,8 +48,13 @@ class BrowserCacheDecorator(FetcherDecorator):
|
|||
d = self.cache.get_data(url)
|
||||
## XXX - should number/sleep times be configurable?
|
||||
## derive from slow_down_sleep_time?
|
||||
|
||||
## XXX - should there be a fail counter / limit for
|
||||
## cases of pointing to wrong cache/etc?
|
||||
sleeptries = [ 3, 10 ]
|
||||
while fetcher.getConfig("open_page_in_browser",False) and not d and sleeptries:
|
||||
while( fetcher.getConfig("use_browser_cache_only") and
|
||||
fetcher.getConfig("open_page_in_browser",False) and
|
||||
not d and sleeptries ):
|
||||
logger.debug("\n\nopen page in browser here %s\n"%url)
|
||||
webbrowser.open(url)
|
||||
time.sleep(sleeptries.pop(0))
|
||||
|
|
@ -64,7 +69,6 @@ class BrowserCacheDecorator(FetcherDecorator):
|
|||
if d:
|
||||
return FetcherResponse(d,redirecturl=url,fromcache=True)
|
||||
|
||||
## make use_browser_cache true/false/only?
|
||||
if fetcher.getConfig("use_browser_cache_only"):
|
||||
raise exceptions.HTTPErrorFFF(
|
||||
url,
|
||||
|
|
|
|||
Loading…
Reference in a new issue