<commit_before>"""
High level code related to the server that provides a mainloop and
serves the pages and websocket. Also provides call_later().
"""

from ..event import _loop
from .. import config


# There is always a single current server (except initially there is None)
_current_server = None


def create_server(host=None, port=None, new_loop=False, backend='tornado',
                  **server_kwargs):
    """
    Create a new server object. This is automatically called; users generally
    don't need this, unless they want to explicitly specify host/port,
    create a fresh server in testing scenarios, or run Flexx in a thread.
    
    Flexx uses a notion of a single current server object. This function
    (re)creates that object. If there already was a server object, it is
    replaced. It is an error to call this function if the current server
    is still running.
    
    Arguments:
        host (str): The hostname to serve on. By default
            ``flexx.config.hostname`` is used. If ``False``, do not listen
            (e.g. when integrating with an existing Tornado application).
        port (int, str): The port number. If a string is given, it is
            hashed to an ephemeral port number. By default
            ``flexx.config.port`` is used.
        new_loop (bool): Whether to create a fresh Tornado IOLoop instance,
            which is made current when ``start()`` is called. If ``False``
            (default) will use the current IOLoop for this thread.
        backend (str): Stub argument; only Tornado is currently supported.
        **server_kwargs: keyword arguments passed to the server constructor.
    
    Returns:
        server: The server object, see ``current_server()``.

    Examples:

        Configuring the server to use HTTPS with Tornado server:
    
        .. code-block:: py
        
            app.create_server(ssl_options = {'certfile' : '/path/to/certfile',
                                             'keyfile' : '/path/to/keyfile'})
            app.serve(Example, 'Example')
            app.run()

        Alternately, cert and key files can be provided through
           ``ssl_certfile`` and ``ssl_keyfile`` configuration variables.
    """
    # Lazy load tornado, so that we can use anything we want there without
    # preventing other parts of flexx.app from using *this* module.
    from ._tornadoserver import TornadoServer  # noqa - circular dependency
    
    global _current_server
    if backend.lower() != 'tornado':<commit_msg>no longer the preferred method for ssl configuration<commit_after>"""
High level code related to the server that provides a mainloop and
serves the pages and websocket. Also provides call_later().
"""

from ..event import _loop
from .. import config


# There is always a single current server (except initially there is None)
_current_server = None


def create_server(host=None, port=None, new_loop=False, backend='tornado',
                  **server_kwargs):
    """
    Create a new server object. This is automatically called; users generally
    don't need this, unless they want to explicitly specify host/port,
    create a fresh server in testing scenarios, or run Flexx in a thread.
    
    Flexx uses a notion of a single current server object. This function
    (re)creates that object. If there already was a server object, it is
    replaced. It is an error to call this function if the current server
    is still running.
    
    Arguments:
        host (str): The hostname to serve on. By default
            ``flexx.config.hostname`` is used. If ``False``, do not listen
            (e.g. when integrating with an existing Tornado application).
        port (int, str): The port number. If a string is given, it is
            hashed to an ephemeral port number. By default
            ``flexx.config.port`` is used.
        new_loop (bool): Whether to create a fresh Tornado IOLoop instance,
            which is made current when ``start()`` is called. If ``False``
            (default) will use the current IOLoop for this thread.
        backend (str): Stub argument; only Tornado is currently supported.
        **server_kwargs: keyword arguments passed to the server constructor.
    
    Returns:
        server: The server object, see ``current_server()``.
    """
    # Lazy load tornado, so that we can use anything we want there without
    # preventing other parts of flexx.app from using *this* module.
    from ._tornadoserver import TornadoServer  # noqa - circular dependency
    
    global _current_server
    if backend.lower() != 'tornado':
{'fraction_non_alphanumeric': 0.07490230134607034, 'fraction_numerical': 0.0, 'mean_word_length': 2.6563492063492062, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5680745', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1176, 'n_words': 558}