
import decorator
import pecan

from magnum.common import exception
from magnum import objects


def enforce_bay_types(*bay_types):
    def decorate(func):
        @decorator.decorator
        def handler(func, *args, **kwargs):
            obj = args[1]
            bay = objects.Bay.get_by_uuid(pecan.request.context, obj.bay_uuid)
            baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
                                                    bay.baymodel_id)
            if baymodel.coe not in bay_types:
                raise exception.InvalidParameterValue(
                    'Cannot fulfill request with a %(bay_type)s bay, '
                    'expecting a %(supported_bay_types)s bay.' %
                    {'bay_type': baymodel.coe,
                     'supported_bay_types': '/'.join(bay_types)})

            return func(*args, **kwargs)
        return handler(func)

    return decorate


import decorator
import pecan

from magnum.common import exception
from magnum import objects


def enforce_bay_types(*bay_types):
    @decorator.decorator
    def wrapper(func, *args, **kwargs):
        obj = args[1]
        bay = objects.Bay.get_by_uuid(pecan.request.context, obj.bay_uuid)
        baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
                                                bay.baymodel_id)
        if baymodel.coe not in bay_types:
            raise exception.InvalidParameterValue(
                'Cannot fulfill request with a %(bay_type)s bay, '
                'expecting a %(supported_bay_types)s bay.' %
                {'bay_type': baymodel.coe,
                 'supported_bay_types': '/'.join(bay_types)})

        return func(*args, **kwargs)

    return wrapper

Correct the usage of decorator.decorator
Correct the usage of decorator.decorator

Correct the usage of decorator.decorator as described in [1].

[1]http://pythonhosted.org/decorator/documentation.html#decorator-decorator

Change-Id: Ia71b751f364e09541faecf6a43f252e0b856558e
Closes-Bug: #1483464

  
  import decorator
  import pecan
  
  from magnum.common import exception
  from magnum import objects
  
  
  def enforce_bay_types(*bay_types):
-     def decorate(func):
-         @decorator.decorator
+     @decorator.decorator
-         def handler(func, *args, **kwargs):
+     def wrapper(func, *args, **kwargs):
-             obj = args[1]
+         obj = args[1]
-             bay = objects.Bay.get_by_uuid(pecan.request.context, obj.bay_uuid)
+         bay = objects.Bay.get_by_uuid(pecan.request.context, obj.bay_uuid)
-             baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
+         baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
-                                                     bay.baymodel_id)
+                                                 bay.baymodel_id)
-             if baymodel.coe not in bay_types:
+         if baymodel.coe not in bay_types:
-                 raise exception.InvalidParameterValue(
+             raise exception.InvalidParameterValue(
-                     'Cannot fulfill request with a %(bay_type)s bay, '
+                 'Cannot fulfill request with a %(bay_type)s bay, '
-                     'expecting a %(supported_bay_types)s bay.' %
+                 'expecting a %(supported_bay_types)s bay.' %
-                     {'bay_type': baymodel.coe,
+                 {'bay_type': baymodel.coe,
-                      'supported_bay_types': '/'.join(bay_types)})
+                  'supported_bay_types': '/'.join(bay_types)})
  
-             return func(*args, **kwargs)
+         return func(*args, **kwargs)
-         return handler(func)
  
-     return decorate
+     return wrapper
  
Correct the usage of decorator.decorator
## Code Before:

import decorator
import pecan

from magnum.common import exception
from magnum import objects


def enforce_bay_types(*bay_types):
    def decorate(func):
        @decorator.decorator
        def handler(func, *args, **kwargs):
            obj = args[1]
            bay = objects.Bay.get_by_uuid(pecan.request.context, obj.bay_uuid)
            baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
                                                    bay.baymodel_id)
            if baymodel.coe not in bay_types:
                raise exception.InvalidParameterValue(
                    'Cannot fulfill request with a %(bay_type)s bay, '
                    'expecting a %(supported_bay_types)s bay.' %
                    {'bay_type': baymodel.coe,
                     'supported_bay_types': '/'.join(bay_types)})

            return func(*args, **kwargs)
        return handler(func)

    return decorate

## Instruction:
Correct the usage of decorator.decorator
## Code After:

import decorator
import pecan

from magnum.common import exception
from magnum import objects


def enforce_bay_types(*bay_types):
    @decorator.decorator
    def wrapper(func, *args, **kwargs):
        obj = args[1]
        bay = objects.Bay.get_by_uuid(pecan.request.context, obj.bay_uuid)
        baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
                                                bay.baymodel_id)
        if baymodel.coe not in bay_types:
            raise exception.InvalidParameterValue(
                'Cannot fulfill request with a %(bay_type)s bay, '
                'expecting a %(supported_bay_types)s bay.' %
                {'bay_type': baymodel.coe,
                 'supported_bay_types': '/'.join(bay_types)})

        return func(*args, **kwargs)

    return wrapper
