Beispiel #1
0
def run_server(hostname='localhost', port=8080,
               docs=True,
               debug='off',
               user=None, group=None,
               threaded=True,
               **kw):
    """ Run a standalone server on specified host/port. """
    application = make_application(shared=docs)

    if port < 1024:
        if os.name == 'posix' and os.getuid() != 0:
            raise RuntimeError('Must run as root to serve port number under 1024. '
                               'Run as root or change port setting.')

    if user:
        switch_user(user, group)

    if debug == 'external':
        # no threading is better for debugging, the main (and only)
        # thread then will just terminate when an exception happens
        threaded = False

    run_simple(hostname=hostname, port=port,
               application=application,
               threaded=threaded,
               use_debugger=(debug == 'web'),
               passthrough_errors=(debug == 'external'),
               request_handler=RequestHandler,
               **kw)
Beispiel #2
0
 def inner_run():
     print "Validating models..."
     self.validate(display_num_errors=True)
     print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
     print "Development server is running at http://%s:%s/" % (addr, port)
     print "Using the Werkzeug debugger (http://werkzeug.pocoo.org/)"
     print "Quit the server with %s." % quit_command
     path = options.get('admin_media_path', '')
     if not path:
         admin_media_path = os.path.join(django.__path__[0], 'contrib/admin/static/admin')
         if os.path.isdir(admin_media_path):
             path = admin_media_path
         else:
             path = os.path.join(django.__path__[0], 'contrib/admin/media')
     handler = WSGIHandler()
     if USE_ADMINMEDIAHANDLER:
         handler = AdminMediaHandler(handler, path)
     if USE_STATICFILES:
         use_static_handler = options.get('use_static_handler', True)
         insecure_serving = options.get('insecure_serving', False)
         if use_static_handler and (settings.DEBUG or insecure_serving):
             handler = StaticFilesHandler(handler)
     if open_browser:
         import webbrowser
         url = "http://%s:%s/" % (addr, port)
         webbrowser.open(url)
     run_simple(addr, int(port), DebuggedApplication(handler, True),
                use_reloader=use_reloader, use_debugger=True, threaded=threaded)
Beispiel #3
0
def main():
    wsgihandler = getwsgihandler(debug=True)
    bind_address = "127.0.0.1"
    port = 5000
    werkzeug.run_simple(
        bind_address, port, wsgihandler, use_debugger=True, use_reloader=True
    )
Beispiel #4
0
def main():
    app = Main(debug=True)
    bind_address = "127.0.0.1"
    port = 5000
    run_simple(
        bind_address, port, app, use_debugger=True, use_reloader=True
    )
Beispiel #5
0
def standalone_serve():
    """Standalone WSGI Server for debugging purposes"""
    from werkzeug import run_simple
    import logging
    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False)
    (options, args) = parser.parse_args()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.ERROR)

    port = 8080
    if len(args) > 0:
        port = int(args[0])

    app = create_application()

    #from werkzeugprofiler import ProfilerMiddleware
    #app = ProfilerMiddleware(app, stream=open('profile_stats.txt', 'w'), accum_count=100, sort_by=('cumulative', 'calls'), restrictions=(.1,))

    run_simple('0.0.0.0', port, app, use_reloader=True,
            use_debugger=True, #use_evalex=True,
            )
Beispiel #6
0
        def inner_run():
            # Flag the server as active
            from devserver import settings
            import devserver

            settings.DEVSERVER_ACTIVE = True
            settings.DEBUG = True

            from django.conf import settings
            from django.utils import translation

            print "Validating models..."
            self.validate(display_num_errors=True)
            print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
            print "Running django-devserver %s" % (devserver.get_version(),)
            print "Development server is running at http://%s:%s/" % (addr, port)
            print "Quit the server with %s." % quit_command

            # django.core.management.base forces the locale to en-us. We should
            # set it up correctly for the first request (particularly important
            # in the "--noreload" case).
            translation.activate(settings.LANGUAGE_CODE)

            if int(options["verbosity"]) < 1:
                base_handler = WSGIHandler
            else:
                base_handler = DevServerHandler

            if options["use_forked"]:
                mixin = SocketServer.ForkingMixIn
            else:
                mixin = SocketServer.ThreadingMixIn

            try:
                handler = AdminMediaHandler(base_handler(), admin_media_path)
                if use_werkzeug:
                    run_simple(
                        addr,
                        int(port),
                        DebuggedApplication(handler, True),
                        use_reloader=use_reloader,
                        use_debugger=True,
                    )
                else:
                    run(addr, int(port), handler, mixin)
            except WSGIServerException, e:
                # Use helpful error messages instead of ugly tracebacks.
                ERRORS = {
                    13: "You don't have permission to access that port.",
                    98: "That port is already in use.",
                    99: "That IP address can't be assigned-to.",
                }
                try:
                    error_text = ERRORS[e.args[0].args[0]]
                except (AttributeError, KeyError):
                    error_text = str(e)
                sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + "\n")
                # Need to use an OS exit because sys.exit doesn't work in a thread
                os._exit(1)
Beispiel #7
0
def profile_run():
    from werkzeug import run_simple
    from werkzeug.contrib.profiler import ProfilerMiddleware, MergeStream
    print "* Profiling"
    f = open('./profiler.log', 'w')
    profiled_app = ProfilerMiddleware(app, MergeStream(sys.stderr, f))
    run_simple('localhost', 5000, profiled_app,
        use_reloader=True, use_debugger=True)
Beispiel #8
0
def run(handler, host='0.0.0.0', port=8000, use_reloader=False,
        use_debugger=False, use_evalex=True, extra_files=None,
        reloader_interval=1, threaded=False, processes=1, request_handler=None,
        passthrough_errors=False):
    '''create a server instance and run it'''
    werkzeug.run_simple(host, port, handler, use_reloader, use_debugger,
            use_evalex, extra_files, reloader_interval, threaded, processes,
            request_handler, handler.static_paths, passthrough_errors)
Beispiel #9
0
def development_server():
    app_path = os.path.basename(__file__)

    werkzeug.run_simple('', 8000,
        util.wrap_static(application, app_path,
            index='wakaba.html',
            not_found_handler=app.not_found),
        use_reloader=True, use_debugger=config.DEBUG)
Beispiel #10
0
 def handle(self, **options):
     if import_excpetion:
         print "Get werkzeug module form http://werkzeug.pocoo.org/download"
         raise SystemExit
     run_simple(
         options["ip"], int(options["port"]), 
         DebuggedApplication(WSGIHandler(), True)
     )
Beispiel #11
0
 def run(self):
     """Start the debugger"""
     def setup_func():
         self.setup_500()
         self.setup_path(self.project)
     app = self.setup_app()
     run_simple(self.host, self.port, app
         , use_debugger=True, use_reloader=True, setup_func=setup_func
         )
Beispiel #12
0
def main():
    logging.basicConfig(level=logging.INFO)
    import yaml

    config = yaml.load(open("config.yaml", "r"))
    app = RESTfulWebService(config)
    from werkzeug import run_simple

    run_simple(config.get("server", "140.134.26.21"), config.get("port", 7788), app)
Beispiel #13
0
def profile_run():
    print "* Profiling"
    f = open('./profiler.log', 'w')
    profiled_app = ProfilerMiddleware(app, MergeStream(sys.stderr, f))
    run_simple(app.config['SERVER_LISTEN'],
               app.config['SERVER_PORT'],
               profiled_app,
               use_reloader=app.config['DEBUG'],
               use_debugger=app.config['DEBUG'])
Beispiel #14
0
def debug(host='0.0.0.0', port=8976):
    """ """
    # This is only needed for Django versions < [7537]:
    def null_technical_500_response(request, exc_type, exc_value, tb):
        raise exc_type, exc_value, tb
    from django.views import debug
    debug.technical_500_response = null_technical_500_response

    os.environ['DJANGO_SETTINGS_MODULE'] = 'agenda.production'

    run_simple(host, port, DebuggedApplication(WSGIHandler(), True))
Beispiel #15
0
 def inner_run():
     from django.conf import settings
     print "Validating models..."
     self.validate(display_num_errors=True)
     print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
     print "Development server is running at http://%s:%s/" % (addr, port)
     print "Using the Werkzeug debugger (http://werkzeug.pocoo.org/)"
     print "Quit the server with %s." % quit_command
     path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
     handler = AdminMediaHandler(WSGIHandler(), path)
     run_simple(addr, int(port), DebuggedApplication(handler, True), 
                use_reloader=use_reloader, use_debugger=True)            
Beispiel #16
0
def simple_server(host='127.0.0.1', port=8080, use_reloader=False):
    """Run a simple server for development purpose.

    :param host: host name
    :param post: port number
    :param use_reloader: whether to reload the server if any of the loaded
                         module changed.
    """
    from werkzeug import run_simple
    # create a wsgi application
    app = Application()
    run_simple(host, port, app, use_reloader=use_reloader, use_debugger=app.debug)
        def inner_run():
            print "Validating models..."
            self.validate(display_num_errors=True)
            print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
            print "Development server is running at http://%s:%s/" % (addr, port)
            print "Using the Werkzeug debugger (http://werkzeug.pocoo.org/)"
            print "Quit the server with %s." % quit_command
            path = options.get('admin_media_path', '')
            if not path:
                admin_media_path = os.path.join(django.__path__[0], 'contrib/admin/static/admin')
                if os.path.isdir(admin_media_path):
                    path = admin_media_path
                else:
                    path = os.path.join(django.__path__[0], 'contrib/admin/media')
            handler = WSGIHandler()
            if USE_ADMINMEDIAHANDLER:
                handler = AdminMediaHandler(handler, path)
            if USE_STATICFILES:
                use_static_handler = options.get('use_static_handler', True)
                insecure_serving = options.get('insecure_serving', False)
                if use_static_handler and (settings.DEBUG or insecure_serving):
                    handler = StaticFilesHandler(handler)
            if open_browser:
                import webbrowser
                url = "http://%s:%s/" % (addr, port)
                webbrowser.open(url)
            if cert_path:
                try:
                    from werkzeug.serving import make_ssl_devcert
                    ssl_context = make_ssl_devcert(cert_path, host='localhost')
                    run_simple(
                        addr,
                        int(port),
                        DebuggedApplication(handler, True),
                        use_reloader=use_reloader,
                        use_debugger=True,
                        threaded=threaded,
                        ssl_context=ssl_context
                    )
                except ImportError:
                    raise CommandError("""Werkzeug 0.8.2 or later is required
to use runserver_plus with ssl support.  Please
visit http://werkzeug.pocoo.org/download""")
            else:
                run_simple(
                    addr,
                    int(port),
                    DebuggedApplication(handler, True),
                    use_reloader=use_reloader,
                    use_debugger=True,
                    threaded=threaded
                )
Beispiel #18
0
def http(application, host='', port=8000):
    """
    $0 http [host [port]]

    Defaults to listening on all interfaces, port 8000
    """

    app_path = os.path.basename(sys.argv[0])

    werkzeug.run_simple(host, int(port),
        util.wrap_static(application, app_path,
            index='wakaba.html'),
        use_reloader=True, use_debugger=config.DEBUG)
def development(addr, port, application):
    from werkzeug import run_simple

    run_simple(
        addr,
        port,
        application,
        use_reloader=True,
        extra_files=None,
        reloader_interval=1,
        threaded=False,
        processes=1,
        request_handler=None,
    )
Beispiel #20
0
    def run(self):
        from werkzeug import run_simple
        def wsgi_app(*a):
            from solace.application import application
            return application(*a)

        # werkzeug restarts the interpreter with the same arguments
        # which would print "running runserver" a second time.  Because
        # of this we force distutils into quiet mode.
        import sys
        sys.argv.insert(1, '-q')

        run_simple(self.host, int(self.port), wsgi_app,
                   use_reloader=not self.no_reloader,
                   use_debugger=not self.no_debugger)
Beispiel #21
0
    def run(self, host=None, port=None, **options):
        """Runs the application on a local development server.  If the
        :attr:`debug` flag is set the server will automatically reload
        for code changes and show a debugger in case an exception happened.

        If you want to run the application in debug mode, but disable the
        code execution on the interactive debugger, you can pass
        ``use_evalex=False`` as parameter.  This will keep the debugger's
        traceback screen active, but disable code execution.

        .. admonition:: Keep in Mind

           Flask will suppress any server error with a generic error page
           unless it is in debug mode.  As such to enable just the
           interactive debugger without the code reloading, you have to
           invoke :meth:`run` with ``debug=True`` and ``use_reloader=False``.
           Setting ``use_debugger`` to `True` without being in debug mode
           won't catch any exceptions because there won't be any to
           catch.

        :param host: the hostname to listen on.  set this to ``'0.0.0.0'``
                     to have the server available externally as well.
        :param port: the port of the webserver
        :param options: the options to be forwarded to the underlying
                        Werkzeug server.  See :func:`werkzeug.run_simple`
                        for more information.
        """
        from werkzeug import run_simple
        if 'debug' in options:
            self.debug = options.pop('debug')
        options.setdefault('use_reloader', self.debug)
        options.setdefault('use_debugger', self.debug)
        return run_simple(host or self.host, port or self.port, self, **options)
Beispiel #22
0
def runserver(ip, port, settings_module=None, debug=False):
    if settings_module: os.environ["DJANGO_SETTINGS_MODULE"] = settings_module
    from django.core.handlers.wsgi import WSGIHandler

    app = WSGIHandler()

    if debug: app = DebuggedApplication(app, True)

    print "Started http server on %s:%s." % (ip, port)
    if debug: print "This is DEBUG server, HIGHLY INSECURE!"
    print "Hit ^C to exit."

    try:
        run_simple(ip, port, app)
    except KeyboardInterrupt:
        print "Shutting down gracefully."
Beispiel #23
0
 def run(self):
     """Start the debugger"""
     def setup_func():
         self.setup_500()
         self.setup_path(self.project)
     app = self.setup_app()
     try:
         run_simple(self.host, self.port, app
             , use_debugger=True, use_reloader=True, setup_func=setup_func
             )
     except TypeError as error:
         if error.message == "run_simple() got an unexpected keyword argument 'setup_func'":
             import traceback
             import sys
             traceback.print_exc()
             sys.exit("Please support https://github.com/mitsuhiko/werkzeug/issues/220")
         raise
Beispiel #24
0
def standalone_serve():
    """Standalone WSGI Server for debugging purposes"""
    from werkzeug import run_simple
    import sys

    port = 8080
    if len(sys.argv) > 1:
        port = int(sys.argv[1])

    app = TracWrapper()

    #from werkzeugprofiler import ProfilerMiddleware
    #app = ProfilerMiddleware(app, stream=open('profile_stats.txt', 'w'), accum_count=100, sort_by=('cumulative', 'calls'), restrictions=(.1,))

    run_simple('0.0.0.0', port, app, use_reloader=True,
            use_debugger=False, #use_evalex=True,
            )
Beispiel #25
0
 def inner_run():
     from django.conf import settings
     print 'Validating models...'
     self.validate(display_num_errors=True)
     print '\nDjango version %s, using settings %r' \
         % (django.get_version(), settings.SETTINGS_MODULE)
     print 'Development server is running at http://%s:%s/' \
         % (addr, port)
     print 'Using the Werkzeug debugger (http://werkzeug.pocoo.org/)'
     print 'Quit the server with %s.' % quit_command
     path = admin_media_path or django.__path__[0] \
         + '/contrib/admin/media'
     handler = AdminMediaHandler(WSGIHandler(), path)
     if open_browser:
         import webbrowser
         url = 'http://%s:%s/' % (addr, port)
         webbrowser.open(url)
     run_simple(addr, int(port), DebuggedApplication(handler,
                True), use_reloader=use_reloader,
                use_debugger=True)
Beispiel #26
0
    def serve(args):
        """ Runs development server for your application. Wrapper for Werkzeug's
        run_simple_ function.

        Note that without ``nodebug`` this will wrap the application into
        `werkzeug.debug.DebuggedApplication` without touching the application's
        WSGI stack, i.e. this middleware will *not* be visible in the output of
        :func:`tool.debug.print_wsgi_stack`. The reason is simple: this command
        only serves the application but does not configure it; therefore it should
        not modify the internals of the object being served.

        .. _run_simple: http://werkzeug.pocoo.org/documentation/dev/serving.html#werkzeug.run_simple
        """
        run_simple(
            application = application,
            hostname = args.host,
            port = args.port,
            use_reloader = not args.noreload,
            use_debugger = not args.nodebug,
        )
	def run(self, host="localhost", port=3044, **options):
		"""run muxi application~:root URL:~http://muxihost:304"""
		from werkzeug import run_simple
		if 'debug' in options:
			self.debug = options.pop('debug')
		if self.static_path is not None:
			options['static_files'] = {
					self.static_path:(self.package_name, 'static')
					}
			options.setdefault('use_reloader', self.debug)
		options.setdefault('use_debugger', self.debug)
		return run_simple(host, port, self, **options)
Beispiel #28
0
def dev(app, host='127.0.0.1', port='6060', **kwds):
    """
    Launches dev server.

    :param app: Application.
    :param host: Hostname.
    :param port: Port.
    :param auto_reload: If True check files changes and reload server if occured.
    """

    from werkzeug import run_simple
    return run_simple(host, port, app, use_reloader=kwds.get('auto_reload', True))
 def inner_run():
     from django.conf import settings
     print "Validating models..."
     self.validate(display_num_errors=True)
     print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
     print "Development server is running at http://%s:%s/" % (addr, port)
     print "Using the Werkzeug debugger (http://werkzeug.pocoo.org/)"
     print "Quit the server with %s." % quit_command
     path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
     handler = AdminMediaHandler(WSGIHandler(), path)
     if StaticFilesHandler is not None:
         use_static_handler = options.get('use_static_handler', True)
         insecure_serving = options.get('insecure_serving', False)
         if (settings.DEBUG and use_static_handler or
                 (use_static_handler and insecure_serving)):
             handler = StaticFilesHandler(handler)
     if open_browser:
         import webbrowser
         url = "http://%s:%s/" % (addr, port)
         webbrowser.open(url)
     run_simple(addr, int(port), DebuggedApplication(handler, True),
                use_reloader=use_reloader, use_debugger=True, threaded=threaded)
Beispiel #30
0
def run_server(hostname='', port=8080,
               docs=True,
               debug='off',
               user=None, group=None,
               threaded=True,
               **kw):
    app = flask.Flask(__name__)
    app.register_blueprint(easy_attach_page, url_prefix='/easy_attach')
    app.register_blueprint(sqlrun_page, url_prefix='/sqlrun')
    """ Run a standalone server on specified host/port. """
    application = make_application(shared=docs)
    application = DispatcherMiddleware(application, {
        '/': application,
      	'/__moinfbp': app,
    })


    if port < 1024:
        if os.name == 'posix' and os.getuid() != 0:
            raise RuntimeError('Must run as root to serve port number under 1024. '
                               'Run as root or change port setting.')

    if user:
        switch_user(user, group)

    if debug == 'external':
        # no threading is better for debugging, the main (and only)
        # thread then will just terminate when an exception happens
        threaded = False

    run_simple(hostname=hostname, port=port,
               application=application,
               threaded=threaded,
               use_debugger=(debug == 'web'),
               passthrough_errors=(debug == 'external'),
               request_handler=RequestHandler,
               **kw)