def expected_errors(errors):
 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(_LE('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

def expected_errors ( errors ) : 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 ( _LE ( '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
decorator for v2 .