예제 #1
0
    def _file_like(self, full_path):
        """Return the appropriate file object."""
        return open(full_path, 'rb')

    def _body(self, full_path, environ, file_like):
        """Return an iterator over the body of the response."""
        way_to_send = environ.get('wsgi.file_wrapper', iter_and_close)
        return way_to_send(file_like, self.block_size)


def iter_and_close(file_like, block_size):
    """Yield file contents by block then close the file."""
    while 1:
        try:
            block = file_like.read(block_size)
            if block: yield block
            else: raise StopIteration
        except StopIteration, si:
            file_like.close()
            return

from cogen.web import wsgi
from cogen.common import *
wsgi.server_factory({}, '0.0.0.0', 9000)(Static('.'))


#~ from wsgiref.simple_server import make_server
#make_server('localhost', 9000, debug).serve_forever()
#~ make_server('localhost', 9000, app).serve_forever()
예제 #2
0
def run():
    try:
        wsgi.server_factory({}, '0.0.0.0', 9000)(wsgi.async.SynchronousInputMiddleware(lorem_ipsum_app))
    except:
        import traceback
        traceback.print_exc()
예제 #3
0
def show_post(environ, start_response):
    import cgi
    import pprint

    status = "200 OK"
    response_headers = [("Content-type", "text/html")]
    start_response(status, response_headers)
    return [
        """<html>
<body>%s
<form action="form" method="post">
 <input name="field1" type="text">
 <input name="field2" type="radio">
 <input name="field3" type="password">
 <textarea name="field4">default text</textarea>
 <input name="submit" type="submit">
</form>
</body>
</html>"""
        % cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ)
    ]


from cogen.web import wsgi
from cogen.common import *

wsgi.server_factory({}, "0.0.0.0", 9001)(show_post)