annotate piecrust/wsgiutil/__init__.py @ 1145:e94737572542

serve: Fix an issue where false positive matches were rendered as the requested page. Now we try to render the page, but also try to detect for the most common "empty" pages.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 05 Jun 2018 22:08:51 -0700
parents 7ecb946bfafd
children d0f86d9a9d40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
897
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
1 import logging
935
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
2 from piecrust.serving.wrappers import get_piecrust_server
379
d40b744a9d99 serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents: 376
diff changeset
3
d40b744a9d99 serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents: 376
diff changeset
4
897
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
5 def _setup_logging(log_file, log_level, max_log_bytes, log_backup_count):
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
6 if log_file:
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
7 from logging.handlers import RotatingFileHandler
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
8 handler = RotatingFileHandler(log_file, maxBytes=max_log_bytes,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
9 backupCount=log_backup_count)
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
10 handler.setLevel(log_level)
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
11 logging.getLogger().addHandler(handler)
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
12
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
13
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
14 def get_app(root_dir, *,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
15 cache_key='prod',
935
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
16 serve_admin=False,
897
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
17 log_file=None,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
18 log_level=logging.INFO,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
19 log_backup_count=0,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
20 max_log_bytes=4096):
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
21 _setup_logging(log_file, log_level, max_log_bytes, log_backup_count)
935
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
22 app = get_piecrust_server(root_dir,
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
23 serve_site=True,
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
24 serve_admin=serve_admin,
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
25 cache_key=cache_key)
379
d40b744a9d99 serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents: 376
diff changeset
26 return app
d40b744a9d99 serve: Add a generic WSGI app factory.
Ludovic Chabant <ludovic@chabant.com>
parents: 376
diff changeset
27
897
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
28
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
29 def get_admin_app(root_dir, *,
935
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
30 cache_key='prod',
897
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
31 log_file=None,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
32 log_level=logging.INFO,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
33 log_backup_count=0,
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
34 max_log_bytes=4096):
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
35 _setup_logging(log_file, log_level, max_log_bytes, log_backup_count)
935
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
36 app = get_piecrust_server(root_dir,
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
37 serve_site=False,
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
38 serve_admin=True,
7ecb946bfafd admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents: 897
diff changeset
39 cache_key=cache_key)
897
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
40 return app
b4156f5d4368 wsgi: Add admin panel to WSGI helpers.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
41