import libbe.util.wsgi
-# return callback(environ, start_response)
-# except libbe.storage.NotReadable, e:
-# raise libbe.util.wsgi.HandlerError(403, 'Read permission denied')
-# except libbe.storage.NotWriteable, e:
-# raise libbe.util.wsgi.HandlerError(403, 'Write permission denied')
-# except libbe.storage.InvalidID, e:
-# raise libbe.util.wsgi.HandlerError(
-# self.http_user_error, 'InvalidID %s' % e)
-
-
class ServerApp (libbe.util.wsgi.WSGI_AppObject,
libbe.util.wsgi.WSGI_DataObject):
"""WSGI server for a BE Storage instance over HTTP.
import libbe.bugdir
import libbe.command.serve
import libbe.util.http
+ import libbe.util.wsgi
class HTTP (base.VersionedStorage):
name = 'TestingHTTP'
def __init__(self, repo, *args, **kwargs):
self._storage_backend = base.VersionedStorage(repo)
- self.app = libbe.command.serve.ServerApp(
+ app = libbe.command.serve.ServerApp(
storage=self._storage_backend)
+ self.app = libbe.util.wsgi.BEExceptionApp(app=app)
HTTP.__init__(self, repo='http://localhost:8000/', *args, **kwargs)
self.intitialized = False
# duplicated from libbe.command.serve.WSGITestCase
import libbe.util.encoding
import libbe.command
import libbe.command.base
+import libbe.storage
+
if libbe.TESTING == True:
import copy
raise
+class BEExceptionApp (WSGI_Middleware):
+ """Translate BE-specific exceptions
+ """
+ def __init__(self, *args, **kwargs):
+ super(BEExceptionApp, self).__init__(*args, **kwargs)
+ self.http_user_error = 418
+
+ def _call(self, environ, start_response):
+ try:
+ return self.app(environ, start_response)
+ except libbe.storage.NotReadable as e:
+ raise libbe.util.wsgi.HandlerError(403, 'Read permission denied')
+ except libbe.storage.NotWriteable as e:
+ raise libbe.util.wsgi.HandlerError(403, 'Write permission denied')
+ except libbe.storage.InvalidID as e:
+ raise libbe.util.wsgi.HandlerError(
+ self.http_user_error, 'InvalidID {}'.format(e))
+
+
class UppercaseHeaderApp (WSGI_Middleware):
"""WSGI middleware that uppercases incoming HTTP headers.
'socket-name':params['host'],
'port':params['port'],
}
+ app = BEExceptionApp(app, logger=self.logger)
app = ExceptionApp(app, logger=self.logger)
if params['ssl'] == True:
details['protocol'] = 'HTTPS'