human
Complete this python program:
def expected_errors(errors):
assistant
#Here is the Python code you requested.

    """Decorator for v2.1 API methods which specifies expected exceptions.
    Specify which exceptions may occur when an API method is called. If an
    unexpected exception occurs then return a 500 instead and ask the user
    of the API to file a bug report.
    """
    def decorator(f):
        @functools.wraps(f)
        def wrapped(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as exc:
                if isinstance(exc, webob.exc.WSGIHTTPException):
                    if isinstance(errors, int):
                        t_errors = (errors,)
                    else:
                        t_errors = errors
                    if (exc.code in t_errors):
                        raise
                elif isinstance(exc, exception.Forbidden):
                    raise
                elif isinstance(exc, exception.ValidationError):
                    raise
                elif isinstance(exc, exception.Unauthorized):
                    raise
                LOG.exception('Unexpected    exception    in    API    method')
                msg = (_('Unexpected    API    Error.    Please    report    this    at    http://bugs.launchpad.net/nova/    and    attach    the    Nova    API    log    if    possible.\n%s') % type(exc))
                raise webob.exc.HTTPInternalServerError(explanation=msg)
        return wrapped
    return decorator