How to use the wsgiref.simple_server function in wsgiref

To help you get started, we’ve selected a few wsgiref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / grr / gui / runtests.py View on Github external
def run(self):
    """Run the django server in a thread."""
    logging.info("Base URL is %s", self.base_url)
    port = self.port
    logging.info("Django listening on port %d.", port)
    try:
      # Make a simple reference implementation WSGI server
      server = simple_server.make_server("0.0.0.0", port,
                                         django_lib.GetWSGIHandler())
    except socket.error as e:
      raise socket.error(
          "Error while listening on port %d: %s." % (port, str(e)))

    # We want to notify other threads that we are now ready to serve right
    # before we enter the serving loop.
    self.ready_to_serve.set()
    while self.keep_running:
      server.handle_request()
github JmilkFan / JmilkFan-s-Blog / jmilkfansblog / cmd / api.py View on Github external
def main():
    host = CONF.host
    port = CONF.api_port

    # Create the WSGI application object.
    wsgi_application = wsgi_app.setup_app()
    # Create the Simple process server.
    server = simple_server.make_server(host, port, wsgi_application)

    server.serve_forever()
github sgjava / byoc / streamer / GStreamerMjpeg.py View on Github external
def createServer(host, port, app, server_class=wsgiref.simple_server.WSGIServer, handler_class=wsgiref.simple_server.WSGIRequestHandler):
    return wsgiref.simple_server.make_server(host, port, app, server_class, handler_class)
github nico / collectiveintelligence-book / searchengine_web.py View on Github external
# several times (e.g. 'q=ddsview&q=makeicns'). Ignore all but the first
      # occurence of q.
      query_words = query_dict['q'][0]
      s = searchengine.searcher('searchindex.db')
      results = '<br>\n'.join(['%f: <a href="%s">%s</a>' % (score, url, url)
        for score, url in s.query(query_words)])
      results = results.encode('utf-8')

  # Note: this also returns html for favicon queries.
  start_response('200 OK',[('Content-type','text/html')])
  return [template % locals()]


if __name__ == '__main__':
  from wsgiref import simple_server
  httpd = simple_server.make_server('', 8000, serve_search)
  httpd.serve_forever()
github MasoniteFramework / masonite / masonite / commands / _devserver.py View on Github external
request_queue_size = 10

    def __init__(self, *args, ipv6=False, allow_reuse_address=True, **kwargs):
        if ipv6:
            self.address_family = socket.AF_INET6
        self.allow_reuse_address = allow_reuse_address
        super().__init__(*args, **kwargs)

    def handle_error(self, request, client_address):
        if is_broken_pipe_error():
            logging.info("- Broken pipe from %s\n", client_address)
        else:
            super().handle_error(request, client_address)


class ServerHandler(simple_server.ServerHandler):
    http_version = '1.1'

    def handle_error(self):
        # Ignore broken pipe errors, otherwise pass on
        if not is_broken_pipe_error():
            super().handle_error()


class WSGIRequestHandler(simple_server.WSGIRequestHandler):
    protocol_version = 'HTTP/1.1'

    def address_string(self):
        # Short-circuit parent method to not call socket.getfqdn
        return self.client_address[0]

    def log_message(self, message_format, *args):
github mozilla / verbatim / vendor / lib / python / django / core / servers / basehttp.py View on Github external
offset = 0
            while offset &lt; length:
                chunk_size = min(33554432, length)
                self._write(data[offset:offset+chunk_size])
                self._flush()
                offset += chunk_size
        else:
            self._write(data)
            self._flush()

    def error_output(self, environ, start_response):
        super(ServerHandler, self).error_output(environ, start_response)
        return ['\n'.join(traceback.format_exception(*sys.exc_info()))]


class WSGIServer(simple_server.WSGIServer, object):
    """BaseHTTPServer that implements the Python WSGI protocol"""

    def __init__(self, *args, **kwargs):
        if kwargs.pop('ipv6', False):
            self.address_family = socket.AF_INET6
        super(WSGIServer, self).__init__(*args, **kwargs)

    def server_bind(self):
        """Override server_bind to store the server name."""
        try:
            super(WSGIServer, self).server_bind()
        except Exception, e:
            raise WSGIServerException(e)
        self.setup_environ()
github mikemccand / luceneserver / examples / jirasearch / server.py View on Github external
try:
        print('%s: %s' % (index.upper(), util.ServerClient().send('startIndex', '{"indexName": "%s"}' % index)))
      except:
        pass

    try:
      idx = sys.argv.index('-port')
    except ValueError:
      if isDev:
        port = 10001
      else:
        port = 10000
    else:
      port = int(sys.argv[idx+1])

    httpd = wsgiref.simple_server.make_server('10.17.4.92', port, application)

    print('Ready on port %s' % port)
    httpd.serve_forever()
  finally:
    if isDev:
      svr.killServer()
github RedHatEMEA / demobuilder / utils / apiserver.py View on Github external
def log_request(*args, **kwargs):
                if not self.quiet:
                    return wsgiref.simple_server.WSGIRequestHandler.log_request(*args, **kwargs)
github faradayio / careplane / moz-addon-sdk / python-lib / cuddlefish / server.py View on Github external
def make_httpd(env_root, host=DEFAULT_HOST, port=DEFAULT_PORT,
               quiet=True):
    if not quiet:
        handler_class = simple_server.WSGIRequestHandler
    else:
        handler_class = QuietWSGIRequestHandler

    tq = Queue.Queue()
    url = get_url(host, port)
    web_docs = webdocs.WebDocs(env_root, url)
    httpd = simple_server.make_server(host, port,
                                      make_wsgi_app(env_root, web_docs, tq),
                                      ThreadedWSGIServer,
                                      handler_class)
    return httpd