Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- cdx handler refactoring: factor out CDXHandler and init to
seperate cdx_handler module - Make wsgi app a class, add port as an optional field in wsgi app and router. (not required to be specified)
- Loading branch information
Showing
9 changed files
with
102 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pywb.cdx.query import CDXQuery | ||
from pywb.cdx.cdxserver import create_cdx_server | ||
|
||
from pywb.framework.archivalrouter import ArchivalRouter, Route | ||
from pywb.framework.basehandlers import BaseHandler | ||
|
||
from views import TextCapturesView | ||
|
||
|
||
#================================================================= | ||
class CDXHandler(BaseHandler): | ||
""" | ||
Handler which passes wsgi request to cdx server and | ||
returns a text-based cdx response | ||
""" | ||
def __init__(self, index_reader, view=None): | ||
self.index_reader = index_reader | ||
self.view = view if view else TextCapturesView() | ||
|
||
def __call__(self, wbrequest): | ||
params = CDXQuery.extract_params_from_wsgi_env(wbrequest.env) | ||
cdx_lines = self.index_reader.load_cdx(**params) | ||
|
||
return self.view.render_response(wbrequest, cdx_lines) | ||
|
||
def __str__(self): | ||
return 'CDX Handler: ' + str(self.index_reader) | ||
|
||
|
||
#================================================================= | ||
DEFAULT_RULES = 'pywb/rules.yaml' | ||
|
||
#================================================================= | ||
def create_cdx_server_app(config): | ||
""" | ||
Create a cdx server config to be wrapped in a wsgi app | ||
Currently using single access point '/cdx' | ||
TODO: more complex example with multiple collections? | ||
""" | ||
cdx_server = create_cdx_server(config, DEFAULT_RULES) | ||
port = config.get('port') | ||
routes = [Route('cdx', CDXHandler(cdx_server))] | ||
return ArchivalRouter(routes, port=port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters