Ejemplo n.º 1
0
def get_server(port):
    """
    Call proxyd.shutdown() to stop the server
    """

    proxyd = TCPServer(("", port), Proxy)
    return proxyd
Ejemplo n.º 2
0
    def get_server(cls, port):
        """
        Call httpd.shutdown() to stop the server
        """

        httpd = TCPServer(("", port), TestWebServerHandler)
        return httpd
Ejemplo n.º 3
0
def preview_main(gen_script, default_port):
    """Main entrypoint for previewing documentation.

    Args:
        gen_script: Generation script, required to generate docs.
        default_port: Default port for local HTTP server.
    """
    assert isfile(_SPHINX_BUILD), "Please execute via 'bazel run'"
    parser = argparse.ArgumentParser()
    parser.register('type', 'bool', _str2bool)
    parser.add_argument(
        "--browser", type='bool', default=True, metavar='BOOL',
        help="Open browser. Disable this if you are frequently recompiling.")
    parser.add_argument(
        "--port", type=int, default=default_port, metavar='PORT',
        help="Port for serving doc pages with a HTTP server.")
    args = parser.parse_args()
    # Choose an arbitrary location for generating documentation.
    out_dir = abspath("sphinx-tmp")
    if isdir(out_dir):
        rmtree(out_dir)
    # Generate.
    check_call([sys.executable, gen_script, "--out_dir", out_dir])
    print("Sphinx preview docs are available at:")
    file_url = "file://{}".format(join(out_dir, "index.html"))
    browser_url = file_url
    print()
    print("  {}".format(file_url))
    # Serve the current directory for local browsing. Required for MacOS.
    # N.B. We serve the preview via a HTTP server because it is necessary for
    # certain browsers (Safari on MacOS, possibly Chrome) due to local file
    # restrictions.
    os.chdir(out_dir)
    sockaddr = ("127.0.0.1", args.port)
    TCPServer.allow_reuse_address = True
    httpd = TCPServer(sockaddr, _Handler)
    http_url = "http://{}:{}/index.html".format(*sockaddr)
    print()
    print("  {}".format(http_url))
    # Default to using HTTP serving only on MacOS; on Ubuntu, it can spit
    # out errors and exceptions about broken pipes, 404 files, etc.
    if sys.platform == "darwin":
        browser_url = http_url
    # Try the default browser.
    if args.browser:
        webbrowser.open(browser_url)
    # Wait for server.
    print()
    print("Serving and waiting ... use Ctrl-C to exit.")
    httpd.serve_forever()
Ejemplo n.º 4
0
def get_auth_code(hostname='localhost', port=8080, listen_path='/'):
    """Listens for an incoming auth code redirect

    This will probably need to be called in a thread so that an initial request
    can be sent while the redirect listener is listening.

    Args:
        hostname (str, optional): The hostname to listen on.
        port (int, optional): What port to listen on
        listen_path (str, optional): What path to listen on"""

    httpd = TCPServer((hostname, port), AuthCodeListener)
    while httpd.RequestHandlerClass.keep_listening:
        httpd.handle_request()

    return httpd.RequestHandlerClass.code
Ejemplo n.º 5
0
    def start(self, bind_ip='0.0.0.0', bind_port=3240):
        """ Start the server """
        LOGGER.info('Starting USBIP server on {}:{}'.format(
            bind_ip, bind_port))

        # Configure the socket server
        TCPServer.allow_reuse_address = True
        TCPServer.timeout = RECV_TIMEOUT_SEC
        self.server = TCPServer((bind_ip, bind_port), UsbIpHandler)
        self.server.controller = self.controller
        self.server.keep_alive = threading.Event()
        self.server.keep_alive.set()

        # Start the server in it's own thread
        signal.signal(signal.SIGINT, self._interrupt_handler)
        self.should_stop.clear()
        self.thread = threading.Thread(target=self._serve)
        self.thread.start()
Ejemplo n.º 6
0
with zipfile.ZipFile("bindings/pydrake/doc/sphinx.zip", "r") as archive:
    archive.extractall("sphinx-tmp")
os.chdir("sphinx-tmp")
file_url = "file://%s/index.html " % os.path.abspath(os.getcwd())


# An HTTP handler without logging.
class Handler(SimpleHTTPRequestHandler):
    def log_request(*_):
        pass


# Serve the current directory for local browsing.
sockaddr = ("127.0.0.1", args.port)
TCPServer.allow_reuse_address = True
httpd = TCPServer(sockaddr, Handler)
http_url = "http://%s:%s/index.html" % sockaddr

# Users can click these as a backup, if the auto-open below doesn't work.
print("Sphinx preview docs are available at:", file=sys.stderr)
print("", file=sys.stderr)
print("  " + http_url, file=sys.stderr)
print("", file=sys.stderr)
print("  " + file_url, file=sys.stderr)
print("", file=sys.stderr)

# Try the default browser, then wait.
if args.browser:
    print("Opening webbrowser", file=sys.stderr)
    if sys.platform == "darwin":
        # macOS
Ejemplo n.º 7
0
def serve():
    httpd = TCPServer((_host, _port), MockHTTPHandler)
    httpd.serve_forever()