Context manager that ensures that a hook is not re-triggered by one of its handlers.
5103
def _triggering_ctx(self):
        
        if self._is_triggering:
            raise RuntimeError('{} cannot be triggered while it is being handled'.format(self))
        self._is_triggering = True
        try:
            yield self
        finally:
            self._is_triggering = False
834960
def handler(self, event):
        """"""

        if self.escape(event):  # A chance to escape
            self.stop()
        elif self.diagnostic:
            self._diagnostic(event)
        else:
            self._tap(event)
        #This is needed according to the pyHook tutorials 'http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=PyHook_Tutorial'
        return True
804157
def set_execution_context(self, execution_context):
        """"""
        if self._execution_context:
            raise errors.AlreadyInContextError

        self._execution_context = execution_context
636683
function(name, action, context) {
        if (!name || !action) {
            return;
        }
        var self = this;
        function wrapper() {
            self.off(name, wrapper);
            action.apply(this, arguments);
        }
        return this.on(name, wrapper, context);
    }
875798
def update_handler(feeds):
		''''''
		# Check if this call is a result of actions initiated from
		#  one of the hooks in a higher frame (resulting in recursion).
		if Feed._filters_update_handler_lock: return
		return Feed._filters_update_handler(Feed, feeds, force=True)
594304
function ( fn, context ) {

		// Initialize variables
		this.state = Promise.STATE.INITIALIZED;
		this.handlers = [];
		this.value = fn;

		// Rebind control functions to be run always on this promise
		this.resolve = this.resolve.bind( this );
		this.fulfill = this.fulfill.bind( this );
		this.reject = this.reject.bind( this );

		// Set fn and context
		if ( fn ) {
			if ( typeof fn !== 'function' ) throw new TypeError("fn is not a function");

			this.fn = fn;
			this.context = context || this;

			this.run();

		}

		return this;
	}
1264695
def on_release(callback, suppress=False):
    
    return hook(lambda e: e.event_type == KEY_DOWN or callback(e), suppress=suppress)
1197592
function(name, callback, context) {
      if (!eventsApi(this, 'once', name, [callback, context]) || !callback) return this;
      var self = this;
      var once = _.once(function() {
        self.off(name, once);
        callback.apply(this, arguments);
      });
      once._callback = callback;
      return this.on(name, once, context);
    }
1209677
def deregister_hook(self, event, hook):
        

        try:
            self.hooks[event].remove(hook)
            return True
        except ValueError:
            return False
685302
public static void checkUnWritabilityAndNotify(ChannelHandlerContext context,
                                                   BackPressureHandler backpressureHandler) {
        if (backpressureHandler != null) {
            Channel channel = context.channel();
            if (!channel.isWritable() && channel.isActive()) {
                backpressureHandler.getBackPressureObservable().notifyUnWritable();
            }
        }
    }
422725
def trigger(self, name, *a, **ka):
        '''  '''
        hooks = self.hooks[name]
        if ka.pop('reversed', False): hooks = hooks[::-1]
        return [hook(*a, **ka) for hook in hooks]
1317571
def handle_hooks(self, hooks, hook_type, *args):
        '''
        
        '''
        if hook_type not in ['before', 'on_route']:
            hooks = reversed(hooks)

        for hook in hooks:
            result = getattr(hook, hook_type)(*args)
            # on_error hooks can choose to return a Response, which will
            # be used instead of the standard error pages.
            if hook_type == 'on_error' and isinstance(result, WebObResponse):
                return result
457459
function (name, handler, options) {
            var _listeners = this.__handlers__[name]||[], _listener;
            var _context = options && options.context;
            if (handler) {
                for (var i = _listeners.length - 1; i >= 0; i--) {
                    _listener = _listeners[i];
                    if (_listener.handler === handler && (!_context || _listener.context === _context )) {
                        this.__handlers__[name].splice(i, 1);
                    }
                }
            }
            else {
                this.__handlers__[name] = [
                    {
                        owner: null,
                        handler: null,
                        context: null
                    }
                ];
            }

            return this;
        }
195862
function callHook(name, getArgument, handleResult, output) {
    getArgument = getArgument || defaultGetArgument;
    handleResult = handleResult || defaultHandleResult;

    var logger = output.getLogger();
    var plugins = output.getPlugins();

    logger.debug.ln('calling hook "' + name + '"');

    // Create the JS context for plugins
    var context = Api.encodeGlobal(output);

    return timing.measure(
        'call.hook.' + name,

        // Get the arguments
        Promise(getArgument(output))

        // Call the hooks in serie
        .then(function(arg) {
            return Promise.reduce(plugins, function(prev, plugin) {
                var hook = plugin.getHook(name);
                if (!hook) {
                    return prev;
                }

                return hook.call(context, prev);
            }, arg);
        })

        // Handle final result
        .then(function(result) {
            output = Api.decodeGlobal(output, context);
            return handleResult(output, result);
        })
    );
}
1261666
def derive_child_context(self, whence):
        """"""
        return _HandlerContext(
            container=self.container,
            queue=self.queue,
            field_name=None,
            annotations=None,
            depth=self.depth,
            whence=whence,
            value=bytearray(),  # children start without a value
            ion_type=None,
            pending_symbol=None
        )
351823
function (name, fn, ctx) {
        // If the context is not passed, use `this`.
        ctx = ctx || this;

        var self = this;

        function onHandler() {
            fn.apply(ctx, arguments);
            self.off(name, onHandler);
        }

        this.on(name, onHandler, ctx);

        return this;
    }
132007
def wraps_with_context(func, context):
    """"""
    wrapped = functools.partial(func, context)
    wrapped = functools.wraps(func)(wrapped)
    if asyncio.iscoroutinefunction(func):
        wrapped = asyncio.coroutine(wrapped)
    return wrapped