Пример #1
0
def run_server(wsgi_app, global_conf, host='localhost', port=8080):
    from wsgiutils import wsgiServer
    logged_app = TransLogger(wsgi_app)
    port = int(port)
    # For some reason this is problematic on this server:
    ensure_port_cleanup([(host, port)], maxtries=2, sleeptime=0.5)
    app_map = {'': logged_app}
    server = wsgiServer.WSGIServer((host, port), app_map)
    logged_app.logger.info('Starting HTTP server on http://%s:%s', host, port)
    server.serve_forever()
Пример #2
0
def run_server(apps, host='localhost', port=8080):
    print "Serving test app at http://%s:%s/" % (host, port)
    print "Visit http://%(host)s:%(port)s/a and " \
        "http://%(host)s:%(port)s/b to test apps" % {'host': host,
                                                     'port': port}
    
    server = wsgiServer.WSGIServer((host, port), apps, serveFiles=False)
    try:
        server.serve_forever()
    except:
        cleanup()
        raise
Пример #3
0
		THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
		(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
		THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
		
		If you make any bug fixes or feature enhancements please let me know!
		
		A simple example - a counting web site.
		Note that increments in modern browsers go up twice because two 
		requests are made - one for '/' and one for '/favicon.ico'
"""
import logging, time

from wsgiutils import SessionClient, wsgiAdaptor, wsgiServer


class TestApp:
    def requestHandler(self, request):
        session = request.getSession()
        count = session.get('counter', 0)
        count += 1
        session['counter'] = count
        request.sendContent(
            "<html><body><h1>Visits: %s</h1></body></html>" % str(count),
            "text/html")


testclient = SessionClient.LocalSessionClient('session.dbm', 'testappid')
testadaptor = wsgiAdaptor.wsgiAdaptor(TestApp(), 'siteCookieKey', testclient)
server = wsgiServer.WSGIServer(('localhost', 1088),
                               {'/': testadaptor.wsgiHook})
server.serve_forever()
Пример #4
0
    data.append({'id': x, 'data': "this is x value %d" % x})
foo.insert().execute(data)


class Foo(object):
    pass


mapper(Foo, foo)

root = './'
port = 8000


def serve(environ, start_response):
    sess = create_session()
    l = sess.query(Foo).select()

    start_response("200 OK", [('Content-type', 'text/plain')])
    threadids.add(thread.get_ident())
    print "sending response on thread", thread.get_ident(
    ), " total threads ", len(threadids)
    return ["\n".join([x.data for x in l])]


if __name__ == '__main__':
    from wsgiutils import wsgiServer
    server = wsgiServer.WSGIServer(('localhost', port), {'/': serve})
    print "Server listening on port %d" % port
    server.serve_forever()
Пример #5
0
        # Display the sum
        self.displayForm(request, firstValue + secondValue)
        return

    def displayForm(self, request, sumValue):
        request.sendContent(
            """<html><body><h1>Calculator</h1>
								<h2>Last answer was: %s</h2>
								<form name="calc">
									<input name="value1" type="text"><br>
									<input name="value2" type="text">
									<button name="Calculate" type="submit">Cal.</button>
								</form>
						</body></html>""" % str(sumValue), "text/html")


# We will use a local session client because we are not multi-process
testclient = SessionClient.LocalSessionClient('session.dbm', 'testappid')
testadaptor = wsgiAdaptor.wsgiAdaptor(TestApp(), 'siteCookieKey', testclient)

calcclient = SessionClient.LocalSessionClient('calcsession.dbm', 'calcid')
calcAdaptor = wsgiAdaptor.wsgiAdaptor(CalcApp(), 'siteCookieKey', calcclient)

# Now place the adaptor in WSGI web container
print "Serving two apps on http://localhost:1066/test.py and http://localhost:1066/calc.py"
server = wsgiServer.WSGIServer(("", 1066), {
    '/test.py': testadaptor.wsgiHook,
    '/calc.py': calcAdaptor.wsgiHook
})
server.serve_forever()