Generate a webapp2.RequestHandler class for the pale endpoint.

    webapp2 handles requests with subclasses of the RequestHandler class,
    instead of using functions like Flask, so we need to generate a new class
    for each pale endpoint.

def pale_webapp2_request_handler_generator(pale_endpoint):
    """Generate a webapp2.RequestHandler class for the pale endpoint.

    webapp2 handles requests with subclasses of the RequestHandler class,
    instead of using functions like Flask, so we need to generate a new class
    for each pale endpoint.
    """
    def pale_handler(self, *args, **kwargs):
        if self.request.method == "OPTIONS":
            origin = self.request.headers.get("Origin", None)
            self.response.headers['Access-Control-Allow-Origin'] = origin
            self.response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
            self.response.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE'
            self.response.headers['Access-Control-Allow-Credentials'] = 'true'
            return self.response

        try:
            return pale_endpoint._execute(self.request)
        finally:
            pale_endpoint._finally()

    cls = type(pale_endpoint._route_name,
            (webapp2.RequestHandler,),
            dict(pale_handler=pale_handler))
    return cls