From 09ba8ca644a6b2f2fb47f185a93dc0954e486fde Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 3 Nov 2013 13:24:27 +0100 Subject: [PATCH] Use HOLD in log() So as not to write to the output when using on an HTTP server, during the writing of headers --- morss.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/morss.py b/morss.py index 688ec8a..1da6355 100644 --- a/morss.py +++ b/morss.py @@ -34,6 +34,7 @@ DELAY = 10*60 # xml cache & ETag cache (in sec) TIMEOUT = 2 # http timeout (in sec) DEBUG = False +HOLD = False UA_RSS = 'Liferea/1.8.12 (Linux; fr_FR.utf8; http://liferea.sf.net/)' UA_HTML = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11' @@ -51,7 +52,10 @@ if 'REQUEST_URI' in os.environ: def log(txt): if DEBUG: - print repr(txt) + if HOLD: + open('morss.log', 'a').write("%s\n" % repr(txt)) + else: + print repr(txt) def lenHTML(txt): @@ -495,6 +499,8 @@ if __name__ == '__main__': DEBUG = bool(options.debug) if 'REQUEST_URI' in os.environ: + HOLD = True + if 'HTTP_IF_NONE_MATCH' in os.environ and not options.force: if time.time() - int(os.environ['HTTP_IF_NONE_MATCH'][1:-1]) < DELAY: print 'Status: 304' @@ -516,6 +522,8 @@ if __name__ == '__main__': print 'Content-Type: text/xml' print '' + HOLD = False + cache = os.getcwd() + '/cache' else: cache = os.path.expanduser('~') + '/.cache/morss'