#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
    middleware/utils.py
    ~~~~~~~~~~~~~~~~~~

    Provide some convenient tools for the middlewares.

"""

from __future__ import absolute_import

from me_api.configs import Config


class MiddlewareConfig(object):
    """Get config for the given middleware."""
    def __init__(self, name):
        self.config = Config.modules['modules'][name]

    def __getattr__(self, attr):
        if attr in self.config:
            return self.config[attr]
        if attr in self.config['data']:
            return self.config['data'][attr]

@@ -193,16 +193,45 @@
 import%0A%0A
+from functools import wraps%0A%0A
 from me_
@@ -605,12 +605,954 @@
 ata'%5D%5Battr%5D%0A
+%0A%0Adef token_required(config):%0A    %22%22%22The index view for each middleware must have a token in the config.%0A%0A    :param config: the config for the middleware.%0A    %22%22%22%0A    def wrapper(func):%0A        @wraps(func)%0A        def inner(*args, **kwargs):%0A            if not config.access_token:%0A                return %22Need access token, please authenticate your app first.%22%0A            return func(*args, **kwargs)%0A        return inner%0A    return wrapper%0A%0A%0Adef reject_duplicated_auth(config):%0A    %22%22%22The authorization view for each middleware should reject authenticating%0A    again if there's a token in the config.%0A%0A    :param config: the config for the middleware.%0A    %22%22%22%0A    def wrapper(func):%0A        @wraps(func)%0A        def inner(*args, **kwargs):%0A            if config.access_token:%0A                return %22You've already had an access token in the config file.%22%0A            return func(*args, **kwargs)%0A        return inner%0A    return wrapper%0A

Add two decorators in utils.py