def with_connection(func):
@wraps(func)<EOL>def wrapped(*args, **kwargs):<EOL><INDENT>if kwargs.get('<STR_LIT>') is None:<EOL><INDENT>kwargs['<STR_LIT>'] = _choose_connection(host=kwargs.get('<STR_LIT:host>'),<EOL>port=kwargs.get('<STR_LIT:port>'))<EOL><DEDENT>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>except HTTPException:<EOL><INDENT>kwargs['<STR_LIT>'] = reconnect(kwargs['<STR_LIT>'])<EOL>return func(*args, **kwargs)<EOL><DEDENT><DEDENT>return wrapped<EOL>
Decorate a function to open a new datafind connection if required

    This method will inspect the ``connection`` keyword, and if `None`
    (or missing), will use the ``host`` and ``port`` keywords to open
    a new connection and pass it as ``connection=<new>`` to ``func``.