def app_for_script(script):
    """Returns the WSGI app specified in the input string, or None on failure."""
    try:
        app, unused_filename, err = wsgi.LoadObject(script)
        if err:  # wsgi.LoadObject guarantees this is either None or ImportError.
            raise err
    except ImportError:
        # Despite returning an error object sometimes, LoadObject will other times
        # just raise an exception. By raising the err object if it exists, we
        # catch either.
        logging.exception('Failed to import %s', script)
        return None
    else:
        return app_wrapped_in_user_middleware(app)
Exemple #2
0
def app_for_script(script):
    """Returns the WSGI app specified in the input string, or None on failure."""
    try:
        app, filename, err = wsgi.LoadObject(script)  # pylint: disable=unused-variable
    except ImportError as e:
        # Despite nominally returning an error object, LoadObject will sometimes
        # just result in an exception. Since we're already processing the err
        # object, we might as well just use that variable to store the exception.
        err = e
    if err:
        # Log the exception but do not reraise.
        logging.exception('Failed to import %s: %s', script, err)
        return None
    else:
        return app_wrapped_in_user_middleware(app)
Exemple #3
0
def _AppFrom27StyleScript(script):
    """Returns application given a python2.7 app.yaml script specification.

  Args:
    script: A script specification from a python27 app.yaml. e.g. my.module.app

  Returns:
    (app, filename) The application as extracted from the script, and the name
    of the file containing the app.

  Raises:
    ImportError: If the given script specification is malformed.
  """
    app, filename, err = wsgi.LoadObject(script)
    if err:
        raise err
    return app, filename