test whether it is a middleware
    :return: Boolean
760947
def is_middleware(func) -> bool:
    

    if inspect.isfunction(func):
        _check = func
        _name = func.__name__
    else:
        _check = func.__call__
        _name = func.__class__.__name__

    if not inspect.iscoroutinefunction(_check):
        raise UnknownMiddlewareException("Middleware {} should be async function".format(_name))

    args = list(inspect.signature(_check).parameters.keys())

    if set(args) - MIDDLEWARE_PARAMETER_BOUNDARY:
        raise UnknownMiddlewareException("Parameters of middleware {} "
                                         "must be in list ['app', 'request', 'response', 'next']".format(_name))

    return True
585825
def _exc_middleware_factory(app):
    

    @web.middleware
    async def middleware(request, handler):
        try:
            return await handler(request)
        except Exception as exc:
            for cls in type(exc).mro():
                if cls in app._error_handlers:
                    request.exception = exc
                    response = await app._error_handlers[cls](request)
                    return response
            raise

    return middleware
401956
function before(ctx) {
  var fn = lookup(ctx.operation, 'middleware', 'before');
  var prefix = describe(ctx);

  if (fn) {
    return fn(ctx);
  } else {
    debug(prefix + 'before middleware disabled (not defined)');
  }
}
6368
function(middleware) {
        this.middlewares = this.middlewares.filter(function(element) {
            if (element.fun === middleware)
                return false;
            return true;
        });
    }
1299929
def is_active(self, timeout=2):
        
        try:
            result = Result(*self.perform_request('HEAD', '/', params={'request_timeout': timeout}))
        except ConnectionError:
            return False
        except TransportError:
            return False

        if result.response.status_code == 200:
            return True

        return False
557663
def _is_valid_endpoint(endpoint):
    """"""
    return any([is_number(endpoint),
                isinstance(endpoint, Timestamp),
                isinstance(endpoint, Timedelta),
                endpoint is None])
554393
def token_middleware(ctx, get_response):
    
    async def middleware(request):
        params = request.setdefault('params', {})
        if params.get("token") is None:
            params['token'] = ctx.token
        return await get_response(request)
    return middleware
186691
function middlewareF (req, res, end) {
    var index = 0

    // inject stats middleware
    if (middlewareF.options && middlewareF.options.stats) {
      middlewareF.stack = middlewareF.stack.map(function (mw) {
        var fn
        if (typeof mw === 'object') {
          var key = Object.keys(mw)[0]
          if (!mw[key].stats) {
            fn = {}
            fn[key] = middlewareF.options.stats(mw[key])
          }
        } else {
          if (!mw.stats) {
            fn = middlewareF.options.stats(mw)
          }
        }
        return fn
      })
    }

    // looping over all middleware functions defined by stack
    ;(function next (err) {
      var arity
      var middleware = middlewareF.stack[index++] // obtain the current middleware from the stack

      if (!middleware) {
        // we are at the end of the stack
        end && end(err)
        return
      } else {
        // extract middleware from object
        if (typeof (middleware) === 'object') {
          var name = Object.keys(middleware)[0]
          if (typeof (middleware[name]) === 'function') {
            middleware = middleware[name]
          } else {
            middleware = function (req, res, next) {
              next(new Error('missing middleware'))
            }
          }
        }

        try {
          arity = middleware.length // number of arguments function middleware requires
          // handle errors
          if (err) {
            // If the middleware function contains 4 arguments than this will act as an "error trap"
            if (arity === 4) {
              middleware(err, req, res, function (err) {
                nextTick(next, err)
              })
            } else {
              // otherwise check the next middleware
              next(err)
            }
          } else if (arity < 4) {
            // process non "error trap" stack
            middleware(req, res, function (err) {
              nextTick(next, err)
            })
          } else {
            // loop over "error traps" if no error `err` is set.
            next()
          }
        } catch (e) {
          next(e)
        }
      }
    })()
  }
254443
def middleware(self, func):
        """"""
        self.middlewares.append(web.middleware(to_coroutine(func)))
1143684
function middlewares() {
        app.middlewares = {}
        const basePath = path.join(app.root, '/middlewares')
        let middlewares = app.config.get('express').middlewares
        if (middlewares && Array.isArray(middlewares) && middlewares.length) {
            for (let m of middlewares) {
                let middleware = require(path.join(basePath, m.dest))(app)
                app.middlewares[m.dest.toLowerCase()] = middleware

                if (middleware.length == 4) { //error handler
                    errorHandlers.push(middleware)
                    continue
                }

                if (m.src)
                    server.use(m.src, wrapper(middleware))
                else
                    server.use(wrapper(middleware))
            }
            if (middlewares.length)
                app.drivers.logger.success('Middleware', 'initialized')
        }
    }
609838
function (routerMiddelware, req, res, next) {
		var middlewareFilename = routerMiddelware.split('.')[0];
		var middlewareFunction = routerMiddelware.split('.')[1];

		if (!req.pipa) req.pipa = {};

		this.middlewares[middlewareFilename][middlewareFunction](req, res, function (data) {
			_.extend(req.pipa, data); next();
		});
	}
1035167
private static function runAppMiddleware()
    {
        $appMiddleware = Filter::$middleware;

        foreach ($appMiddleware as $middleware) {
            $middleware = instance($middleware);

            $middleware->handle(new Request());
        }

        return true;
    }
968211
function middlewareFunction (req,res,next){

  return ipToLocation(req.ip)
    .then(function (location) {
      req.location = location;
      next();
    })
    .catch(function (error) {
      req.locationError = error;
      next();
    })

}
1159334
function compose(middleware){
	return function *(next){
		if (!next) next = noop();

		var i = middleware.length;

		while (i--) {
			next = middleware[i].call(this, next);
		}

		yield *next;
	}
}
871273
function () {
    var middlewares = Array.prototype.slice.apply(arguments)
      , req = middlewares.splice(0, 1)
      , next = middlewares.pop()
    
    // Check other middlewares for client objects. If we find one, merge
    // it and ours together.
    for (var i = 0; i < middlewares.length; i++) {
      var middleware_obj = middlewares[i]
      if (middleware_obj.type == 'client') {
        utils.merge(middlewares[i], hist_obj)
        return undefined
      }
    }
    
    // If we get this far, no other middlewares match client type. So pass
    // our middleware object.
    next({'history': hist_obj})
    return undefined
  }
36673
def _make_middleware_stack(middleware, base):
        
        for ware in reversed(middleware):
            base = ware(base)
        return base
237084
def hasmethod(obj, meth):
  
  if hasattr(obj, meth):
    return callable(getattr(obj,meth))
  return False