Commits

Alessio Deiana committed 0c1e4e7

Removes buffer output ability

I removed the buffer output functionality because I wanted to reduce
as much as possible duplicated code from invenio.

In particular the contents of application() have been updated so
instead of copying the code again, I am importing totally and
dropping the feature that needed a customized application().

Comments (0)

Files changed (3)

 About
 -----
 ``invenio-devserver'' is an HTTP server for Invenio with automatic code reloading,
-useful when developing for [[http://invenio-software.org/][Invenio]]. It also 
+useful when developing for [[http://invenio-software.org/][Invenio]]. It also
 includes a mail debug server which prints all incoming emails to the console.
 
-Invenio is a free software suite enabling you to run your own digital library 
+Invenio is a free software suite enabling you to run your own digital library
 or document repository on the web. See more on http://invenio-software.org/.
 
 Installation
  * ``Werkzeug''
  * ``mock'' (optional): to intercept errors and display them on stdout
 
-Both ``Werkzeug'' and ``mock'' will be automatically installed when using PIP.  
+Both ``Werkzeug'' and ``mock'' will be automatically installed when using PIP.
 
 Configuration
 -------------
-You need to tell ``invenio-devserver'' where your Invenio source code and 
-installation lives. Add config_local.py to your site-packages directory with 
+You need to tell ``invenio-devserver'' where your Invenio source code and
+installation lives. Add config_local.py to your site-packages directory with
 the following::
 
 	SRC_PATH = [
 
 If you don't specify ``SRC_PATH'' or ``INSTALL_PATH'' they will be guessed:
 
-  * If you are in an activated virtualenv the ``INSTALL_PATH'' is set to 
-    ``VIRTUAL_ENV'' environment variable. 
+  * If you are in an activated virtualenv the ``INSTALL_PATH'' is set to
+    ``VIRTUAL_ENV'' environment variable.
   * ``SRC_PATH'' defaults to ``~/src/invenio/''.
-  * If you are using ``invenio-devscripts'', ``SRC_PATH'' and ``INSTALL_PATH'' 
-    will be set to the environment variables ``CFG_INVENIO_SRC'' and 
+  * If you are using ``invenio-devscripts'', ``SRC_PATH'' and ``INSTALL_PATH''
+    will be set to the environment variables ``CFG_INVENIO_SRC'' and
     ``CFG_INVENIO_PREFIX' respectively.
 
 Please see ``src/invenio_devserver/config.py'' for further possible settings.
 	$ python serve.py
 
 If the Invenio installation is under another user (e.g wwww), you can use
-	
+
 	$ sudo -u www python serve.py
 
 The following options for ``serve'' are available::
 
 	$ serve --help
 	Usage: python serve.py [-bp]
-	
+
 	Invenio web server for development
-	
+
 	Options:
 	  -h, --help       show this help message and exit
 	  -b BIND_ADDRESS  Address to bind to
 	  -p BIND_PORT     Port to bind to
 	  --no-reload      Disable automatic reloading when a source file is changed
 	  --no-http        Disable http server, only update invenio install
-	  --buffer-output  Buffer output to display to display debug pages
 	  --pdb            Drop to python debugger on errors
 	  -s SRC_PATH      Source folder (one or more)
 	  -o INSTALL_PATH  Path to Invenio installation.
 
 	$ mailserve
 	Remember to set the two following settings in invenio-local.conf:
-	
+
 	CFG_MISCUTIL_SMTP_HOST=127.0.0.1
 	CFG_MISCUTIL_SMTP_PORT=1025
-	
+
 	Now accepting mail at 127.0.0.1:1025 (hit CONTROL-C to stop)
 
 
 The following options for ``mailserve'' are available::
 	Usage: mailserve [-bp]
-	
+
 	Invenio mail server for development
-	
+
 	Options:
 	  -h, --help       show this help message and exit
 	  -b BIND_ADDRESS  Address to bind to

src/invenio_devserver/serve.py

 
     static = dict([(k, config.INSTALL_PATH + v) for k, v in static_files.items()])
 
-    wsgi_app = partial(wsgi.application, options)
+    wsgi_app = wsgi.application
 
     if options.use_pdb:
         import pdb
     parser.add_option('--no-http', action='store_false', dest='serve_http',
                       default=True, help='Disable http server, only update ' \
                       'invenio install')
-    parser.add_option('--buffer-output', dest='buffer_output', default=False,
-                      action='store_true', help='Buffer output to display\n' \
-                      'to display debug pages')
     parser.add_option('--pdb', dest='use_pdb', default=False,
                       action='store_true', help='Drop to python debugger\n' \
                       'on errors')

src/invenio_devserver/wsgi.py

                                               is_static_path
 
 
-class BufferedWSGIRequest(SimulatedModPythonRequest):
-    _response_buffer = None
-
-    def start_response_wrapper(self, status, headers):
-        self._response_status = status
-        self._response_headers = headers
-        self._response_buffer = StringIO()
-
-        def write(bytes):
-            self._response_buffer.write(bytes)
-        return write
-
-    def __init__(self, environ, start_response):
-        self.__start_response_orig = start_response
-        super(BufferedWSGIRequest, self).__init__(environ,
-                                                  self.start_response_wrapper)
-
-    def final_flush(self):
-        if self._response_buffer:
-            writer = self.__start_response_orig(self._response_status,
-                                                  self._response_headers)
-            writer(self._response_buffer.getvalue())
-
-
-class WSGIRequest(SimulatedModPythonRequest):
-    def final_flush(self):
-        pass
-
-
-def application(options, environ, start_response):
-    """
-    Entry point for wsgi.
-    """
-    if options.buffer_output:
-        request = BufferedWSGIRequest
-    else:
-        request = WSGIRequest
-    req = request(environ, start_response)
-
-    try:
-        try:
-            possible_module, possible_handler = \
-                            is_mp_legacy_publisher_path(environ['PATH_INFO'])
-            if possible_module is not None:
-                mp_legacy_publisher(req, possible_module, possible_handler)
-            elif CFG_WSGI_SERVE_STATIC_FILES:
-                possible_static_path = is_static_path(environ['PATH_INFO'])
-                if possible_static_path is not None:
-                    from invenio.bibdocfile import stream_file
-                    stream_file(req, possible_static_path)
-                else:
-                    invenio_handler(req)
-            else:
-                invenio_handler(req)
-            req.flush()
-            req.final_flush()
-        except SERVER_RETURN, status:
-            status = int(str(status))
-            if status not in (OK, DONE):
-                req.status = status
-                req.headers_out['content-type'] = 'text/html'
-                admin_to_be_alerted = alert_admin_for_server_status_p(status,
-                                                req.headers_in.get('referer'))
-                if admin_to_be_alerted:
-                    register_exception(req=req, alert_admin=True)
-                if not req.response_sent_p:
-                    start_response(req.get_wsgi_status(),
-                                   req.get_low_level_headers(),
-                                   sys.exc_info())
-                return generate_error_page(req, admin_to_be_alerted)
-            else:
-                req.flush()
-    finally:
-        for (callback, data) in req.get_cleanups():
-            callback(data)
-    return []
 
 
 try:
     from invenio.webinterface_handler_flask import create_invenio_flask_app
 except ImportError:
-    pass
+    from invenio.webinterface_handler_wsgi import application
 else:
-    _application = create_invenio_flask_app()
-
-    def application(options, environ, start_response):
-        return _application(environ, start_response)
+    application = create_invenio_flask_app()