'''
'''
import functools
import operator
from .. import monads


def view(func, **constraints):
    '''Functions that decorates a view. This function can also checks the
    argument values
    '''
    func.is_view = True
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            if not functools.reduce(operator.__and__,
                                    [constraints[arg](kwargs[arg])
                                     for arg in constraints]):
                return monads.NoneMonad(ValueError(
                                                'Wrong view argument value'))
            return monads.ValueMonad(func(*args, **kwargs))
        except Exception as e:
            return monads.NoneMonad(e)
    return wrapper

'''
'''
import functools
import operator
from .. import monads


def view(func, **constraints):
    '''Functions that decorates a view. This function can also checks the
    argument values
    '''
    func.is_view = True
    @functools.wraps(func)
    @monads.handle_exception
    def wrapper(*args, **kwargs):
        if not functools.reduce(operator.__and__, 
                                [constraints[arg](kwargs[arg])
                                 for arg in constraints]):
            return monads.NoneMonad(ValueError('Wrong view argument value'))
        return monads.ValueMonad(func(*args, **kwargs))
    return wrapper

Use exception handling with decorator
Use exception handling with decorator

  '''
  '''
  import functools
  import operator
  from .. import monads
  
  
  def view(func, **constraints):
      '''Functions that decorates a view. This function can also checks the
      argument values
      '''
      func.is_view = True
      @functools.wraps(func)
+     @monads.handle_exception
      def wrapper(*args, **kwargs):
-         try:
-             if not functools.reduce(operator.__and__,
+         if not functools.reduce(operator.__and__, 
-                                     [constraints[arg](kwargs[arg])
+                                 [constraints[arg](kwargs[arg])
-                                      for arg in constraints]):
+                                  for arg in constraints]):
+             return monads.NoneMonad(ValueError('Wrong view argument value'))
-                 return monads.NoneMonad(ValueError(
-                                                 'Wrong view argument value'))
-             return monads.ValueMonad(func(*args, **kwargs))
+         return monads.ValueMonad(func(*args, **kwargs))
-         except Exception as e:
-             return monads.NoneMonad(e)
      return wrapper
  
Use exception handling with decorator
## Code Before:
'''
'''
import functools
import operator
from .. import monads


def view(func, **constraints):
    '''Functions that decorates a view. This function can also checks the
    argument values
    '''
    func.is_view = True
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            if not functools.reduce(operator.__and__,
                                    [constraints[arg](kwargs[arg])
                                     for arg in constraints]):
                return monads.NoneMonad(ValueError(
                                                'Wrong view argument value'))
            return monads.ValueMonad(func(*args, **kwargs))
        except Exception as e:
            return monads.NoneMonad(e)
    return wrapper

## Instruction:
Use exception handling with decorator
## Code After:
'''
'''
import functools
import operator
from .. import monads


def view(func, **constraints):
    '''Functions that decorates a view. This function can also checks the
    argument values
    '''
    func.is_view = True
    @functools.wraps(func)
    @monads.handle_exception
    def wrapper(*args, **kwargs):
        if not functools.reduce(operator.__and__, 
                                [constraints[arg](kwargs[arg])
                                 for arg in constraints]):
            return monads.NoneMonad(ValueError('Wrong view argument value'))
        return monads.ValueMonad(func(*args, **kwargs))
    return wrapper
