Exemple #1
0
def runserver():
    """Lance un serveur wsgi de test, puis lui attribue l'application a
    lancer avec eventuellement le chainage de middleware
    """
    from pyson.middleware.error import HandleError
    from pyson.middleware.log import Log
    from pyson.middleware.session import Session  #se wrapp automatiquement avec cookie
    from pyson.middleware.force_auth import Force_auth
    from pyson.middleware.http_basic import Http_basic
    from pyson.middleware.formdata import Formdata
    from pyson.middleware.restriction import Middle as Restriction

    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr,
                       os.environ).run(urls.urls)
        print "-------------  Attention ---------------"
    else:
        import wsgiref
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', int(context.conf["port"])), WSGIRequestHandler)

        wrapper = Session(Formdata((Restriction(urls.urls))))

        httpd.set_app(wrapper)

        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #2
0
def serve(site_factory, port=0, use_reloader=False, dry=False):
    """Create a new WSGI server listening on `host` and `port` for `app`"""
    server = WSGIServer(('', port), WSGIRequestHandler)
    server.set_app(site_factory.wsgi())
    LOGGER.info('Serving on port {0}'.format(port))
    if not dry:     #pragma nocover
        server.serve_forever()
Exemple #3
0
Fichier : web.py Projet : ctb/waroo
def run_wsgi(port=8123):
    server = WSGIServer(('', port), WSGIRequestHandler)
    app = create_publisher()
    server.set_app(app)

    print 'serving on %s:%d' % (interface, port,)
    server.serve_forever()
    def start_wsgi_server():
        from rdb.RobotDebuger import DebugSetting
        app_settings = DebugSetting()
        work_root = os.getcwd()

        config_path = os.path.abspath(config_file)
        if os.path.isfile(config_path):
            app_settings.load_from_file(config_path)
        
        init_sys_logging(app_settings)
        logger = logging.getLogger("rdb.proxy")
        logger.info("Loading RDB proxy at %s" % work_root)
        
        try:
            SERVER_CONTEXT = ApplicationContext(work_root, app_settings)
            globals()['SERVER_CONTEXT'] = SERVER_CONTEXT
            
            from wsgiref.simple_server import WSGIServer
            server_address = (app_settings.WEB_BIND, int(app_settings.WEB_PORT))
            server = WSGIServer(server_address, RDBProxyWSGIHandler)
            server.set_app(wsgi_global_app)
            SERVER_CONTEXT.server = server
            
            logger.info("Serving HTTP on %s:%s..." %(app_settings.WEB_BIND,
                                                          app_settings.WEB_PORT))
            
            server.serve_forever()
        except BaseException, e:
            logger.exception(e)
Exemple #5
0
def runserver():
    """Lance un serveur wsgi de test, puis lui attribue l'application a
    lancer avec eventuellement le chainage de middleware
    """
    from pyson.middleware.error   import HandleError
    from pyson.middleware.log     import Log
    from pyson.middleware.session import Session  #se wrapp automatiquement avec cookie
    from pyson.middleware.force_auth import Force_auth
    from pyson.middleware.http_basic import Http_basic
    from pyson.middleware.formdata import Formdata
    from pyson.middleware.restriction import Middle as Restriction 

    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
        print "-------------  Attention ---------------"
    else:
        import wsgiref
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', int(context.conf["port"])), WSGIRequestHandler)

        wrapper  = Session(Formdata((Restriction(urls.urls))))

        httpd.set_app(wrapper)

        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #6
0
def run(create_publisher, host='', port=80, handler_class=RequestHandler):
    """Runs a Quixote application using the simple server from wsgiref."""
    publisher = create_publisher()
    app = QWIP(publisher)
    server = WSGIServer((host, port), handler_class)
    server.set_app(app)
    try:
        server.serve_forever()
    finally:
        server.server_close()
Exemple #7
0
def run():
    import urls
    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', 8000), WSGIRequestHandler)
        httpd.set_app(urls.urls)
        print "Serving HTTP os %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #8
0
def run():
    import urls
    if os.environ.get('REQUEST_METHOD', ''):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(
            sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', 8080), WSGIRequestHandler)
        httpd.set_app(urls.urls)
        print "Server HTTP on %s port %s..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #9
0
def run():
    import urls
    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ) \
                .run(urls.load('urls.map'))
    else:
        os.environ = {}
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', 8080), WSGIRequestHandler)
        httpd.set_app(urls.load('urls.map'))
        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #10
0
def run():
    import urls

    if os.environ.get('REQUEST_METHOD', ''):
        from wsgiref.handlers import  BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', 8080), WSGIRequestHandler)
        httpd.set_app(urls.urls)
        host, port = httpd.socket.getsockname()[:2]
        print 'Serving HTTP on {0} port {1}...'.format(host, port)
        httpd.serve_forever()
Exemple #11
0
class HealthCheck:
    def __init__(self, port):
        self.server = WSGIServer(('0.0.0.0', port),
                                 NoLoggingWSGIRequestHandler)
        api = falcon.App()
        api.add_route('/health', self)
        self.server.set_app(api)

    def on_get(self, _, response):
        response.media = {'status': 'available'}

    def start(self):
        self.server.serve_forever()
Exemple #12
0
def run():
    import urls
    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        f = file("log", "a")
        BaseCGIHandler(sys.stdin, sys.stdout, f, os.environ).run(urls.urls)
        f.close()
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', 8080), WSGIRequestHandler)
        httpd.set_app(urls.urls)
        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #13
0
def run():
    import urls

    if os.environ.get('REQUEST_METHOD', ''):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr,
                       os.environ).run(urls.urls)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', 8080), WSGIRequestHandler)
        httpd.set_app(urls.urls)
        host, port = httpd.socket.getsockname()[:2]
        print 'Serving HTTP on {0} port {1}...'.format(host, port)
        httpd.serve_forever()
Exemple #14
0
def serve(handler, host='localhost', port=8080, debug=True):
    """
    Starts a developent server on the local machine. By default, the
    server runs on port 8080 on localhost. You can pass in a different
    hostname and/or IP using the keyword arguments.
    """

    if debug:
        handler = DebugMiddleware.wrap(handler)

    httpd = WSGIServer((host, port), WSGIRequestHandler)
    httpd.set_app(WSGIHandler(handler))
    print("Development server is running at http://%s:%s/" % (host, port))
    httpd.serve_forever()
Exemple #15
0
def run(selector):
    """Run the server provided by selector"""

    print selector
    exec "from  " + selector + " import urls, port"

    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ) \
                .run(urls)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
# with the code like this we are binding to no particular interface, matter?
        httpd = WSGIServer(('', port), WSGIRequestHandler)
        httpd.set_app(urls)
        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #16
0
def start_simple(filename, hostname, port):
    """
    Start a wsgiref.simple_server to run our app.

    Provides the simplest base for testing, debugging
    and development.

    XXX no longer used
    """
    os.environ = {}
    from wsgiref.simple_server import WSGIServer, WSGIRequestHandler

    hostname = config["server_host"]["host"]
    port = int(config["server_host"]["port"])
    httpd = WSGIServer((hostname, port), WSGIRequestHandler)
    httpd.set_app(load_app())
    print >>sys.stderr, "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
    httpd.serve_forever()
Exemple #17
0
class GaeTestServer(object):

    def __init__(self):
        self.sdk_path = resolve_sdk_path()
        print 'python sdk found', self.sdk_path
        sys.path.insert(0, self.sdk_path)
        import dev_appserver
        dev_appserver.fix_sys_path()
        sys.path.insert(0, 'src')
        self.testbed = None
        self.httpd = None

    def boot_gae(self):
        from google.appengine.api import memcache
        from google.appengine.ext import ndb
        from google.appengine.ext import testbed
        from google.appengine.datastore import datastore_stub_util
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
        self.testbed.init_memcache_stub()

    def boot_web(self, port, app):
        self.port = port
        self.httpd = WSGIServer(('localhost', port), WSGIRequestHandler)
        self.httpd.set_app(app)

    def server_forever_background(self):
        self.thread = threading.Thread(target=self.httpd.serve_forever)
        self.thread.start()

    def server_forever(self):
        self.httpd.serve_forever()

    def shutdown(self):
        if self.testbed:
            self.testbed.deactivate()
        if self.httpd:
            self.httpd.shutdown()
            self.httpd = None
Exemple #18
0
def run():
    """ run server """
    from users import urls
    if os.environ.get("REQUEST_METHOD", ""):
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr,
                       os.environ).run(urls.urls)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        from beaker.middleware import SessionMiddleware

        session_opts = {
            'session.type': 'file',
            'session.cookie_expires': True,
            'session.data_dir': 'var',
        }

        app = SessionMiddleware(urls.urls, session_opts)
        httpd = WSGIServer(('', 8080), WSGIRequestHandler)
        httpd.set_app(app)
        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #19
0
class _HTTPServer(bottle.ServerAdapter):
    """
    Reimplement bottle's WSGIRefServer. Override the request handler class and
    add a stop() method for cleanly shutting down the server.
    """
    srv = None
    app = None

    def run(self, handler):
        # Handle the TIME_WAIT state for quick server restarts
        WSGIServer.allow_reuse_address = 1

        # Create the server and start it
        self.srv = WSGIServer((self.host, self.port), _HTTPRequestHandler)
        self.srv.set_app(self.app)
        try:
            self.srv.serve_forever()
        finally:
            self.srv.server_close()

    def stop(self):
        if self.srv:
            self.srv.shutdown()
Exemple #20
0
            ret = tools.sparql_post(env)
        elif path[0].lower() == 'submit':
            ret = tools.submit(env)

    elif env['REQUEST_METHOD'] == 'PUT':
        if path[0].lower() == 'submit':
            ret = tools.submit(env)

    elif env['REQUEST_METHOD'] == 'DELETE':
        # Not supported until authentication gets added TODO
        pass

    else:
        # Unsupported as yet
        pass

    status, headers, content = ret
    start_response(status, headers)
    return content

if __name__ == '__main__':
    if 'REQUEST_METHOD' in os.environ:
        from wsgiref.handlers import BaseCGIHandler
        BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(run)
    else:
        from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
        httpd = WSGIServer(('', config.port), WSGIRequestHandler)
        httpd.set_app(run)
        print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
        httpd.serve_forever()
Exemple #21
0
def serve(handler, host='localhost', port=8080):
    httpd = WSGIServer((host, port), WSGIRequestHandler)
    httpd.set_app(WSGIHandler(handler))
    print "Server is running at http://%s:%s/" % (host, port)
    httpd.serve_forever()
Exemple #22
0
app = dash.Dash()
auth = dash_auth.BasicAuth(app, USERNAME_PASSWORD_PAIRS)
server = app.server

cov_data = pd.read_csv("data.csv")
print(cov_data)


fig = px.scatter_mapbox(cov_data, lat="Lat", lon="Long_", hover_name="Country_Region", hover_data=["Confirmed"],
                        color_discrete_sequence=["fuchsia"], zoom=3, height=300)

fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "source": [
                "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
            ],

        }
    ],
)
fig.update_layout(height=1400, margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.show()

if __name__ == '__main__':
    http_server = WSGIServer(('', 5000), app)
    http_server.serve_forever()
Exemple #23
0
    @register('/update', method=['POST'])
    def update_book(self, request):
        return 'update book'

    @register('/query', method=['GET'])
    def query_book(self, request):
        return 'query books'


@tramp.before_request
def judge_user(request):
    return Response('Find Page')


@tramp.before_request
def judge_hello(request):
    response = Response('Sorry')
    response.set_status_code(404)

    return response


if __name__ == '__main__':
    host = '127.0.0.1'
    port = 9000
    server = WSGIServer((host, port), WSGIRequestHandler)
    server.set_app(tramp)
    print('Server Listen at: {}:{}'.format(host, port))

    server.serve_forever()
Exemple #24
0
def run(app):
    from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
    httpd = WSGIServer(('127.0.0.1', 8080), WSGIRequestHandler)
    httpd.set_app(app)
    print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
    httpd.serve_forever()
 def server(cls):
     server = WSGIServer(('localhost', 8999), WsgiHandler)
     server.set_app(cls.wsgi_app)
     server.serve_forever()