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

    """Wraps a request handler with CORS headers checking.
    """
    @wraps(f)
    def decorated(*args, **kwargs):
        self = args[0]
        request = args[1]
        origin = request.getHeader(u'Origin')
        if origin:
            if (u'*' in self.config[u'cors_origins']):
                request.setHeader(u'Access-Control-Allow-Origin', u'*')
            elif (origin in self.config[u'cors_origins']):
                request.setHeader(u'Access-Control-Allow-Origin', origin)
            else:
                request.setResponseCode(403)
                return u'forbidden'
        return f(*args, **kwargs)
    return decorated