How to use the_handler method in devtools-proxy

Best Python code snippet using devtools-proxy_python

runlib.py

Source:runlib.py Github

copy

Full Screen

1""" Various (un)necessary stuff for runscripts """2from __future__ import print_function, unicode_literals, absolute_import, division3import os4import sys5import random6import time7import warnings8import logging9import signal10import atexit11import traceback12from six.moves import xrange13__all__ = [14 'init_logging',15 'sigeventer',16]17# TODO: lazy-imports18try:19 from pyaux.twisted_aux import (20 make_manhole_telnet,21 make_manhole,22 )23except ImportError:24 pass25def _make_short_levelnames(shortnum=True):26 """ Return a dict (levelnum -> levelname) with short names for logging.27 `shortnum`: also shorten all 'Level #' names to 'L##'.28 """29 _names = dict([30 (logging.DEBUG, 'DBG'),31 (logging.INFO, 'INFO'), # d'uh32 (logging.WARN, 'WARN'),33 (logging.ERROR, 'ERR'),34 (logging.CRITICAL, 'CRIT'),35 ])36 if shortnum:37 for i in xrange(1, 100):38 _names.setdefault(i, "L%02d" % (i,))39 return _names40# Current attempt: use bytes in py2, unicode in py3 (i.e. subvert unicode_literals just for these).41BASIC_LOG_FORMAT = str("%(asctime)s: %(levelname)-13s: %(name)s: %(message)s")42BASIC_LOG_FORMAT_TD = str("%(asctime)s(+%(time_diff)5.3fs): %(levelname)-13s: %(name)s: %(message)s")43def init_logging(*args, **kwargs):44 """ Simple shorthand for neat and customizable logging init """45 _td = kwargs.pop('_td', False)46 # Support for https://pypi.python.org/pypi/coloredlogs47 # Also, notable: https://pypi.python.org/pypi/verboselogs (but no special support here at the moment)48 _try_coloredlogs = kwargs.pop('_try_coloredlogs', False)49 if _try_coloredlogs:50 try:51 import coloredlogs52 except Exception:53 coloredlogs = None54 _try_coloredlogs = False55 colored = kwargs.pop('colored', True)56 if colored and not _try_coloredlogs:57 from . import use_colorer58 use_colorer()59 short_levelnames = kwargs.pop('short_levelnames', True)60 if short_levelnames:61 _names = _make_short_levelnames()62 for lvl, name in _names.items():63 logging.addLevelName(lvl, str(name))64 kwargs.setdefault('level', logging.DEBUG)65 logformat = BASIC_LOG_FORMAT66 if _td:67 logformat = BASIC_LOG_FORMAT_TD68 kwargs.setdefault('format', logformat)69 if _try_coloredlogs:70 kwargs['fmt'] = kwargs['format']71 coloredlogs.install(*args, **kwargs)72 else:73 logging.basicConfig(*args, **kwargs)74 if _td:75 # XX: do the same for all `logging.Logger.manager.loggerDict.values()`?76 from .logging_annotators import time_diff_annotator77 flt = time_diff_annotator()78 logging.root.addFilter(flt)79 for logger in logging.Logger.manager.loggerDict.values():80 if hasattr(logger, 'addFilter'):81 logger.addFilter(flt)82def argless_wrap(fn):83 """ Wrap function to re-try calling it if calling it with arguments84 failed """85 def argless_internal(*ar, **kwa):86 try:87 return fn(*ar, **kwa)88 except TypeError as e:89 try:90 return fn()91 except TypeError as e2:92 #raise e # - traceback-inconvenient93 raise # - error-inconvenient94 return argless_internal95# convenience wrappers:96def _sysexit_wrap(n=None, f=None):97 return sys.exit()98def _atexit_wrap(n=None, f=None):99 return atexit._run_exitfuncs()100class ListSigHandler(list):101 def __init__(self, try_argless, ignore_exc, verbose):102 self.try_argless = try_argless103 self.ignore_exc = ignore_exc104 self.verbose = verbose105 def __call__(self, n, f):106 for func in reversed(self):107 try:108 if self.verbose:109 print("ListSigHandler: running %r" % (func,))110 if self.try_argless:111 func = argless_wrap(func)112 func(n, f)113 except Exception as e:114 if self.ignore_exc:115 if self.verbose:116 traceback.print_exc()117 else:118 # Still print something119 print("Exception ignored: %r" % (e,))120 else:121 raise122def sigeventer(add_defaults=True, add_previous=True, do_sysexit=True,123 try_argless=True, ignore_exc=True, verbose=False):124 """125 Puts one list-based handler for SIGINT and SIGTERM that can be `append`ed to.126 NOTE: arguments are ignored if it was called previously.127 :param add_defaults: add the `atexit` handler.128 :param add_previous: add the previously-set handlers (NOTE: will129 mix sigterm/sigint handlers if different).130 :param try_argless: re-call handled function without parameters if131 they raise TypeError.132 :param do_sysexit: do `sys.exit()` at the end of handler.133 :param ignore_exc: ...134 Use `signal.getsignal(signal.SIGINT).append(some_func)` to add a handler.135 Handlers are called in reverse order (first in, last out).136 """137 # XXXX/TODO: a version that only sets itself on one of the signals138 # (optionally).139 # Check if already done something like this:140 curhandler_int = signal.getsignal(signal.SIGINT)141 curhandler_term = signal.getsignal(signal.SIGTERM)142 if isinstance(curhandler_int, list) and isinstance(curhandler_term, list):143 # probaby us already; just return144 assert curhandler_int is curhandler_term, \145 "unexpected: different list-based term/int handlers"146 return curhandler_term147 the_handler = ListSigHandler(try_argless=try_argless, ignore_exc=ignore_exc, verbose=verbose)148 signal.signal(signal.SIGINT, the_handler)149 signal.signal(signal.SIGTERM, the_handler)150 # Useful since this all will only be done once.151 if do_sysexit:152 the_handler.append(_sysexit_wrap)153 if add_previous:154 # Note that signal.SIG_DFL will be basically ignored.155 if callable(curhandler_term):156 the_handler.append(curhandler_term)157 if (callable(curhandler_int) and158 curhandler_int != curhandler_term):159 # (Note that same previous handler still can be called twice)160 the_handler.append(curhandler_int)161 if add_defaults:162 the_handler.append(_atexit_wrap)...

Full Screen

Full Screen

events.py

Source:events.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: iso-8859-15 -*-3# Created on 07/10/20154# Modified on 20/10/20155# Modified by asaelt6#7# This class is based on the definition of the Eagles Labeling standard:8# http://www.cs.upc.edu/~nlp/tools/parole-sp.html9#10# Source:11# https://github.com/uagdataanalysis/mosynapi12#13# @author: asaelt14class EventHook(object):15 """16 Represents a generic event handler.17 """18 def __init__(self):19 self.__handlers = []20 def __iadd__(self, handler):21 self.__handlers.append(handler)22 return self23 def __isub__(self, handler):24 self.__handlers.remove(handler)25 return self26 def fire(self, *args, **keywargs):27 for handler in self.__handlers:28 handler(*args, **keywargs)29 def clear_object_handlers(self, in_object):30 for the_handler in self.__handlers:31 if the_handler.im_self == in_object:...

Full Screen

Full Screen

entry_points.py

Source:entry_points.py Github

copy

Full Screen

...21 for p in the_handler.permissions:22 if p not in request.user.permissions():23 return "You do not have permission to access the API function of '{}'".format(request_mode)24 25 return the_handler()(request, test_mode=False)26 27 28 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devtools-proxy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful