def _generate_control_action(fp, s): ss = str.split(s, " ") if "get" == ss[0]: return partial_apply(_get_current_value, fp=fp, c=ss[1]) if "set" == ss[0]: return partial_apply(_update_value, fp=fp, c=ss[1], v=ss[2]) if "cyc" == ss[0]: return partial_apply(_cycle_value, fp=fp, c=ss[1]) return partial_apply(_nullary_nullity, s=s)
def _callmouse(self, *args): '''Run a mouse's callback. Saves invalid mouse data for next call''' chars = [i for i in args[-1] if i != curses.KEY_MOUSE] args = args[:-1] if chars[0] != -1: #control not returned to loop until later asyncio.get_event_loop().call_soon( partial_apply(self, chars, *args, raise_=False)) try: if self._last_mouse is not None: x, y, state = self._last_mouse #pylint: disable=unpacking-non-sequence KeyContainer._last_mouse = None else: _, x, y, _, state = curses.getmouse() error_sig = "..." if state not in self._mouse: if -1 not in self._mouse: KeyContainer._last_mouse = (x, y, state) raise KeyException error_sig = "..., state" args = (*args, state) state = -1 try: return self._mouse[state](chars, *args, x, y) except TypeError: return self._mouse[state](chars, *args) except TypeError as exc: raise TypeError(self._MOUSE_ERROR.format(error_sig , self._mouse[state])) from exc except curses.error: pass raise KeyException
def partial(f, *arguments): """ http://bugs.python.org/issue3445 https://docs.python.org/2/library/functools.html#partial-objects """ p = partial_apply(f, *arguments) p.__module__ = f.__module__ p.__name__ = "partial-{0}".format(f.__name__) return p
def staticize(func, *args, doc=None, **kwargs): '''functools.partial, but conserves or adds documentation''' ret = partial_apply(func, *args, **kwargs) ret.__doc__ = doc or func.__doc__ return ret