コード例 #1
0
def test_is_double_callable():
    """
    Tests that the signature matcher works as expected.
    """
    assert is_double_callable(double_application_function) == True
    assert is_double_callable(DoubleApplicationClass) == True
    assert is_double_callable(DoubleApplicationClassNestedFunction()) == True
    assert is_double_callable(single_application_function) == False
    assert is_double_callable(SingleApplicationClass()) == False
コード例 #2
0
def test_double_to_single_signature():
    """
    Test that the new object passes a signature test.
    """
    assert (
        is_double_callable(double_to_single_callable(double_application_function))
        == False
    )
コード例 #3
0
def test_is_single_callable():
    from asgiref.compatibility import is_double_callable

    wrapper = StaticFilesWrapper(None)

    assert not is_double_callable(wrapper), (
        "StaticFilesWrapper should be recognized as a single callable by "
        "asgiref compatibility tools")
コード例 #4
0
ファイル: cli.py プロジェクト: waikup83/daphne
    def run(self, args):
        """
        Pass in raw argument list and it will decode them
        and run the server.
        """
        # Decode args
        args = self.parser.parse_args(args)
        # Set up logging
        logging.basicConfig(
            level={
                0: logging.WARN,
                1: logging.INFO,
                2: logging.DEBUG,
                3: logging.DEBUG,  # Also turns on asyncio debug
            }[args.verbosity],
            format="%(asctime)-15s %(levelname)-8s %(message)s",
        )
        # If verbosity is 1 or greater, or they told us explicitly, set up access log
        access_log_stream = None
        if args.access_log:
            if args.access_log == "-":
                access_log_stream = sys.stdout
            else:
                self.access_log = args.access_log
                access_log_stream = open(args.access_log, "a", 1)
                signal.signal(signal.SIGUSR1, self.logrotate)
        elif args.verbosity >= 1:
            access_log_stream = sys.stdout
        # Import application
        sys.path.insert(0, ".")
        application = import_by_path(args.application)

        asgi_protocol = args.asgi_protocol
        if asgi_protocol == "auto":
            asgi_protocol = "asgi2" if is_double_callable(
                application) else "asgi3"

        if asgi_protocol == "asgi3":
            application = ASGI3Middleware(application)

        # Set up port/host bindings
        if not any([
                args.host,
                args.port is not None,
                args.unix_socket,
                args.file_descriptor is not None,
                args.socket_strings,
        ]):
            # no advanced binding options passed, patch in defaults
            args.host = DEFAULT_HOST
            args.port = DEFAULT_PORT
        elif args.host and args.port is None:
            args.port = DEFAULT_PORT
        elif args.port is not None and not args.host:
            args.host = DEFAULT_HOST
        # Build endpoint description strings from (optional) cli arguments
        endpoints = build_endpoint_description_strings(
            host=args.host,
            port=args.port,
            unix_socket=args.unix_socket,
            file_descriptor=args.file_descriptor,
        )
        endpoints = sorted(args.socket_strings + endpoints)
        # Start the server
        logger.info("Starting server at %s" % (", ".join(endpoints), ))
        self.server = self.server_class(
            application=application,
            endpoints=endpoints,
            http_timeout=args.http_timeout,
            ping_interval=args.ping_interval,
            ping_timeout=args.ping_timeout,
            websocket_timeout=args.websocket_timeout,
            websocket_connect_timeout=args.websocket_connect_timeout,
            websocket_handshake_timeout=args.websocket_connect_timeout,
            application_close_timeout=args.application_close_timeout,
            action_logger=AccessLogGenerator(access_log_stream)
            if access_log_stream else None,
            ws_protocols=args.ws_protocols,
            root_path=args.root_path,
            verbosity=args.verbosity,
            proxy_forwarded_address_header=self._get_forwarded_host(args=args),
            proxy_forwarded_port_header=self._get_forwarded_port(args=args),
            proxy_forwarded_proto_header="X-Forwarded-Proto"
            if args.proxy_headers else None,
            server_name=args.server_name,
        )
        self.server.run()