示例#1
0
def make_app():
    global _the_app

    if _the_app is None:
        p = create_publisher()
        _the_app = quixote.get_wsgi_app()

    return _the_app
示例#2
0
def run(create_publisher):
    publisher = create_publisher()
    while _fcgi.isFCGI():
        f = _fcgi.FCGI()
        response = publisher.process(f.inp, f.env)
        try:
            response.write(f.out)
        except IOError, err:
            publisher.log("IOError while sending response ignored: %s" % err)
        f.Finish()
def run(create_publisher):
    publisher = create_publisher()
    while _fcgi.isFCGI():
        f = _fcgi.FCGI()
        response = publisher.process(f.inp, f.env)
        try:
            response.write(f.out)
        except IOError, err:
            publisher.log("IOError while sending response ignored: %s" % err)
        f.Finish()
示例#4
0
def run(create_publisher):
    if sys.platform == "win32":
        # on Windows, stdin and stdout are in text mode by default
        import msvcrt
        msvcrt.setmode(sys.__stdin__.fileno(), os.O_BINARY)
        msvcrt.setmode(sys.__stdout__.fileno(), os.O_BINARY)
    publisher = create_publisher()
    response = publisher.process(sys.__stdin__, os.environ)
    try:
        response.write(sys.__stdout__)
    except IOError, err:
        publisher.log("IOError while sending response ignored: %s" % err)
示例#5
0
def make_app(app_name):

  global _the_app

  if _the_app is None:
    if app_name == 'altdemo':
      p = create_publisher()
    else:
      p = imageapp.create_publisher()
    _the_app = quixote.get_wsgi_app()

  return _the_app
示例#6
0
def run(create_publisher):
    if sys.platform == "win32":
        # on Windows, stdin and stdout are in text mode by default
        import msvcrt

        msvcrt.setmode(sys.__stdin__.fileno(), os.O_BINARY)
        msvcrt.setmode(sys.__stdout__.fileno(), os.O_BINARY)
    publisher = create_publisher()
    response = publisher.process(sys.__stdin__, os.environ)
    try:
        response.write(sys.__stdout__)
    except IOError, err:
        publisher.log("IOError while sending response ignored: %s" % err)
示例#7
0
def main():
    s = socket.socket() # Create a socket object.
    host = socket.getfqdn() # Get local machine name.

    parser = argparse.ArgumentParser() #creating a parser 
    parser.add_argument("-A", choices=['image', 'altdemo', 'myapp', 'quotes', 'chat', 'cookie'],
            help='Choose which app you would like to run')
    parser.add_argument("-p", type=int, help="Choose the port you would like to run on.")
    args = parser.parse_args()

    #Check to see if a port is specified
    if args.p == None:
        port = random.randint(8000, 9999) #Creating WSGI app
        s.bind((host, port))
    else:
        port = args.p
        s.bind((host, port))
    if args.A == 'myapp':
        wsgi_app = make_app()
    elif args.A == "image":
        imageapp.setup()
        p = imageapp.create_publisher()
        wsgi_app = quixote.get_wsgi_app()
    elif args.A == "altdemo":
        p = create_publisher()
        wsgi_app = quixote.get_wsgi_app()
    elif args.A == "quotes":
        directory_path = './quotes/'
        wsgi_app = quotes.create_quotes_app(directory_path + 'quotes.txt', directory_path + 'html')
    elif args.A == "chat":
        wsgi_app = chat.create_chat_app('./chat/html')
    elif args.A == "cookie":
        wsgi_app = make_cookie_app()
    else:
        wsgi_app = make_app() #In the event that no argument is passed just make my_app

    print 'Starting server on', host, port
    print 'The Web server URL for this would be http://%s:%d/' % (host, port)

    s.listen(5) #wait for client connection

    print 'Entering infinite loop; hit CTRL+C to exit'
    while True:
        #Establish a connection with the client
        c, (client_host, client_port) = s.accept()
        print 'Got connection from', client_host, client_port
        handle_connection(c, wsgi_app)
        #handle connection(c, validate_app)
    return
示例#8
0
"""
run-qx.py
- runs a quixote example application
  in a WSGI server
"""

import socket
import random

### here is the code needed to create a WSGI application interface to
### a Quixote app:

import quixote
from quixote.demo import create_publisher
from quixote.demo.mini_demo import create_publisher
from quixote.demo.altdemo import create_publisher

p = create_publisher()
wsgi_app = quixote.get_wsgi_app()

### now that we have a WSGI app, we can run it in the WSGI reference server:

from wsgiref.simple_server import make_server

host = socket.getfqdn() # Get local machine name
port = random.randint(8000, 9999)
p.is_thread_safe = True # hack...
httpd = make_server('', port, wsgi_app)
print "Serving at http://%s:%d/..." % (host, port,)
httpd.serve_forever()
示例#9
0
def main():
    """
    Initializes the Server.

    Parses command line arguments (if present),
    then initializes the wsgi_app and starts up the server,
    then waits for connections
    """

    apps = [
        'fires', 'hw6',
        'imageapp',
        'quixote_demo',
        'quotes',
        'chat',
        'cookie'
    ]
    parser = argparse.ArgumentParser(
        description='A WSGI Server implemented for CSE491-001.',
        epilog='Please check the non-existent documentation for more info.',
        formatter_class=argparse.RawTextHelpFormatter
    )
    # Add the '-?' alias for '--help', which I prefer to use:
    parser.add_argument('-?',
        action='help',
        help='Alias for --help')
    # Add the application argument:
    parser.add_argument('--app',
        nargs='?',
        dest='app',
        default='fires',
        choices=apps,
        help='\n'.join([
            'Which WSGI application to run.',
            '(default: "%(default)s" - my homework 6)',
            'Alias: -A'
            ]))
    parser.add_argument('-A',
        nargs='?',
        dest='app',
        default='fires',
        choices=apps,
        help=argparse.SUPPRESS)
    # Add the port argument:
    parser.add_argument('--port',
        nargs='?',
        default=random.randint(8000, 9999),
        type=int,
        help='\n'.join([
            'Which port to start the server on.',
            '(default: random integer between 8000 and 9999)',
            'Alias: -p'
            ]))
    # After that, parse the command-line arguments.
    args = parser.parse_args()

    # Create a socket object
    sock = socket.socket()
    # Get local machine name
    host = socket.getfqdn()

    if host in ('magrathea', 'Thoth'):
        # For testing, I don't want to have to change my url all the damn time.
        port = 8080
    else:
        port = args.port
    # Bind to the port
    # TODO figure out how to immediately unbind when I'm done
    sock.bind((host, port))
    print 'Starting server at http://%s:%d/' % (host, port)
    # Now wait for client connection.
    sock.listen(5)

    # get this from commandline
    app_to_run = args.app
    if app_to_run == 'quixote_demo':
        # quixote stuff for testing with that
        p = create_publisher()
        # p.is_thread_safe = True # hack...
        wsgi_app = quixote.get_wsgi_app()
    elif app_to_run == 'imageapp':
        imageapp.setup()
        p = imageapp.create_publisher()
        wsgi_app = quixote.get_wsgi_app()
    elif app_to_run == 'quotes':
        wsgi_app = QuotesApp('./quotes/quotes.txt', './quotes/html')
    elif app_to_run == 'chat':
        wsgi_app = ChatApp('./chat/html')
    elif app_to_run == 'cookie':
        wsgi_app = cookieapp.wsgi_app
    else: #if app_to_run == 'fires': # default
        wsgi_app = app.make_app()


    print 'Entering infinite loop; hit CTRL-C to exit'
    try:
        while True:
            # Establish connection with client.
            conn, (client_host, client_port) = sock.accept()
            print 'Got connection from', client_host, client_port
            handle_connection(conn, wsgi_app)
    finally:
        # teardown stuffs
        if app_to_run == 'imageapp':
            imageapp.teardown()
        sock.shutdown(2)
        sock.close()