示例#1
0
    def pdb(self, additional_data: Sequence = ()) -> None:
        """Call the RemotePdb debugger; define some conveniance variables."""

        ad = additional_data  # noqa
        ba = self.backend  # noqa
        mo = self.backend.models  # noqa
        cl = self.backend.clients
        gcl = lambda user: cl[f"@{user}"]  # noqa

        rc = lambda c: asyncio.run_coroutine_threadsafe(c, self._loop)  # noqa

        p = print  # pdb's `p` doesn't print a class's __str__  # noqa
        try:
            log.warning("\nThe pprintpp python package is not installed.")
            from pprintpp import pprint as pp  # noqa
        except ModuleNotFoundError:
            pass

        try:
            import remote_pdb
        except ModuleNotFoundError:
            log.warning(
                "\nThe remote_pdb python package is not installed, falling "
                "back to pdb.", )
            import pdb
            pdb.set_trace()
        else:
            log.info(
                "\n=> Run `socat readline tcp:127.0.0.1:4444` in a terminal "
                "to connect to the debugger.", )
            remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
示例#2
0
    def doCommand(self, eCommand, iArg1, iArg2):
        if eCommand == CommandTypes.COMMAND_DELETE:
            if self.getX() == 51 and self.getY() == 44:
                remote_pdb.RemotePdb("192.168.0.21", 4444).set_trace()
                # raise Exception()

        self.doCommandBase(eCommand, iArg1, iArg2)
示例#3
0
def post_mortem(t=None, host='0.0.0.0', port=0, patch_stdstreams=False):
    # handling the default
    if t is None:
        # sys.exc_info() returns (type, value, traceback) if an exception is
        # being handled, otherwise it returns None
        t = sys.exc_info()[2]
    if t is None:
        raise ValueError("A valid traceback must be passed if no "
                         "exception is being handled")

    p = remote_pdb.RemotePdb(host=host,
                             port=port,
                             patch_stdstreams=patch_stdstreams)
    p.reset()
    p.interaction(None, t)
示例#4
0
    def __init__(self, config=None):
        logger.info("Blueflood Finder v1.1.4")
        threading.Thread.__init__(self)
        if os.path.isfile("/root/pdb-flag"):
            import remote_pdb
            remote_pdb.RemotePdb('127.0.0.1', 4444).set_trace()
        if config is not None:
            bf_config = config.get('blueflood', {})
            urls = bf_config.get('urls', bf_config.get('url', '').strip('/'))
            tenant = bf_config.get('tenant', None)
            authentication_module = bf_config.get('authentication_module',
                                                  None)
            authentication_class = bf_config.get('authentication_class', None)
            enable_statsd = bf_config.get('enable_statsd', False)
            enable_submetrics = bf_config.get('enable_submetrics', False)
            submetric_aliases = bf_config.get('submetric_aliases', {})
        else:
            from django.conf import settings
            urls = getattr(settings, 'BF_QUERY')
            tenant = getattr(settings, 'BF_TENANT')
            authentication_module = getattr(settings,
                                            'BF_AUTHENTICATION_MODULE', None)
            authentication_class = getattr(settings, 'BF_AUTHENTICATION_CLASS',
                                           None)
            enable_submetrics = getattr(settings, 'BF_ENABLE_SUBMETRICS',
                                        False)
            submetric_aliases = getattr(settings, 'BF_SUBMETRIC_ALIASES', {})

        if authentication_module:
            module = importlib.import_module(authentication_module)
            class_ = getattr(module, authentication_class)
            bfauth = class_(config)
            auth.set_auth(bfauth)

        self.exit_flag = 0
        self.metrics_q = Queue.Queue(1)
        self.data_q = Queue.Queue(1)

        self.tenant = tenant
        self.bf_query_endpoint = urls[0]
        self.enable_submetrics = enable_submetrics
        self.submetric_aliases = submetric_aliases
        self.client = BluefloodClient(self.bf_query_endpoint, self.tenant,
                                      self.enable_submetrics,
                                      self.submetric_aliases, enable_statsd)
        self.daemon = True
        self.start()
        logger.debug("BF finder submetrics enabled: %s", enable_submetrics)
示例#5
0
    def pdb(self, additional_data: Sequence = ()) -> None:
        """Call the RemotePdb debugger; define some conveniance variables."""

        ad = additional_data  # noqa
        ba = self.backend  # noqa
        mo = self.backend.models  # noqa
        cl = self.backend.clients
        gcl = lambda user: cl[f"@{user}:matrix.org"]  # noqa

        rc = lambda c: asyncio.run_coroutine_threadsafe(c, self._loop)  # noqa

        p = print  # pdb's `p` doesn't print a class's __str__  # noqa
        try:
            from pprintpp import pprint as pp  # noqa
        except ModuleNotFoundError:
            pass

        log.info("\n=> Run `socat readline tcp:127.0.0.1:4444` in a terminal "
                 "to connect to pdb.")
        import remote_pdb
        remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
示例#6
0
    def pdb(self, extra_data: Sequence = (), remote: bool = False) -> None:
        """Call the python debugger, defining some conveniance variables."""

        ad = extra_data  # noqa
        ba = self.backend  # noqa
        mo = self.backend.models  # noqa
        cl = self.backend.clients
        gcl = lambda user: cl[f"@{user}"]  # noqa

        rc = lambda c: asyncio.run_coroutine_threadsafe(c, self._loop)  # noqa

        try:
            from devtools import debug  # noqa
            d = debug  # noqa
        except ModuleNotFoundError:
            log.warning("Module python-devtools not found, can't use debug()")

        if remote:
            # Run `socat readline tcp:127.0.0.1:4444` in a terminal to connect
            import remote_pdb
            remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
        else:
            import pdb
            pdb.set_trace()
    def onKbdEvent(self, argsList):
        'keypress handler - return 1 if the event was consumed'
        """
        Handles onKbdEvent by firing the keystroke's handler if it has one registered.
        """

        eventType, key, mx, my, px, py = argsList
        game = gc.getGame()

        # if self.bAllowCheats:
        if gc.getGame().isDebugMode():
            # notify debug tools of input to allow it to override the control
            argsList = (eventType, key, self.bCtrl, self.bShift, self.bAlt, mx,
                        my, px, py, game.isNetworkMultiPlayer())
            if CvDebugTools.g_CvDebugTools.notifyInput(argsList):
                return 0

        if eventType == self.EventKeyDown and not InputUtil.isModifier(key):
            theKey = int(key)
            # <f1rpo> (advc.007b)
            # Added not bCtrl/bAlt/bShift checks so that each cheat is triggered by only one combination of modifier keys
            if not self.bShift and self.bCtrl and self.bAlt and theKey == int(
                    InputTypes.KB_R):
                BugUtil.warn(
                    "Note (K-Mod): Reloading of Art Defines (Ctrl+Alt+R) is disabled"
                )
                return 1  # Don't use this key combination for anything else
            # </f1rpo>

            stroke = InputUtil.Keystroke(key, self.bAlt, self.bCtrl,
                                         self.bShift)
            if stroke in self.shortcuts:
                BugUtil.debug(
                    "BugEventManager - calling handler for shortcut %s",
                    stroke)
                self.shortcuts[stroke](argsList)
                return 1

            # From FfH-Mod: by Kael 07/05/2008
            if theKey == int(InputTypes.KB_LEFT):
                if self.bCtrl:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() - 45.0)
                    return 1
                elif self.bShift:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() - 10.0)
                    return 1

            if theKey == int(InputTypes.KB_RIGHT):
                if self.bCtrl:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() + 45.0)
                    return 1
                elif self.bShift:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() + 10.0)
                    return 1
            # From FfH: End

            # PAE Spieler am Zug Message aktivieren/deaktvieren: STRG+P / CTRL+P --
            if theKey == int(InputTypes.KB_P):
                if self.bCtrl:
                    if self.bPAE_ShowMessagePlayerTurn:
                        self.bPAE_ShowMessagePlayerTurn = False
                        CyInterface().addMessage(
                            gc.getGame().getActivePlayer(), True, 5,
                            CyTranslator().getText(
                                "TXT_KEY_MESSAGE_PAE_CIV_TURN_DEACTIVATED",
                                ("", )), None, 2, None, ColorTypes(14), 0, 0,
                            False, False)
                    else:
                        self.bPAE_ShowMessagePlayerTurn = True
                        self.iPAE_ShowMessagePlayerHumanID = gc.getGame(
                        ).getActivePlayer()
                        CyInterface().addMessage(
                            gc.getGame().getActivePlayer(), True, 5,
                            CyTranslator().getText(
                                "TXT_KEY_MESSAGE_PAE_CIV_TURN_ACTIVATED",
                                ("", )), None, 2, None, ColorTypes(14), 0, 0,
                            False, False)
                    return 1

            CvCameraControls.g_CameraControls.handleInput(theKey)

            ## AI AutoPlay ##
            if CyGame().getAIAutoPlay():
                if theKey == int(InputTypes.KB_SPACE) or theKey == int(
                        InputTypes.KB_ESCAPE):
                    CyGame().setAIAutoPlay(0)
                    return 1
            ## AI AutoPlay ##

            # <f1rpo> (advc.007b) Cheats copied from CvEventManager
            # if self.bAllowCheats:
            if gc.getGame().isDebugMode():
                # Shift - T (Debug - No MP)
                if self.bShift and not self.bCtrl and not self.bAlt and theKey == int(
                        InputTypes.KB_T):
                    self.beginEvent(CvUtil.EventAwardTechsAndGold)
                    return 1
                if self.bShift and self.bCtrl and not self.bAlt and theKey == int(
                        InputTypes.KB_W):
                    self.beginEvent(CvUtil.EventShowWonder)
                    return 1
                # Shift - ] Debug - currently mouse-over'd unit, health += 10
                elif theKey == int(
                        InputTypes.KB_LBRACKET
                ) and self.bShift and not self.bCtrl and not self.bAlt:
                    unit = CyMap().plot(px, py).getUnit(0)
                    if not unit.isNone():
                        d = min(unit.maxHitPoints() - 1, unit.getDamage() + 10)
                        unit.setDamage(d, PlayerTypes.NO_PLAYER)
                # Shift - [ Debug - currently mouse-over'd unit, health -= 10
                elif theKey == int(
                        InputTypes.KB_RBRACKET
                ) and self.bShift and not self.bCtrl and not self.bAlt:
                    unit = CyMap().plot(px, py).getUnit(0)
                    if not unit.isNone():
                        d = max(0, unit.getDamage() - 10)
                        unit.setDamage(d, PlayerTypes.NO_PLAYER)
                # <advc.gfd> Keep Nightinggale's key combination
                elif theKey == int(
                        InputTypes.KB_F1
                ) and self.bShift and self.bCtrl and not self.bAlt:
                    GameFontDisplay.GameFontDisplay().interfaceScreen()
                    return 1  # </advc.gfd>
                elif theKey == int(InputTypes.KB_F1):
                    if self.bShift and self.bAlt:
                        CyInterface().addImmediateMessage(
                            "BEGIN Python file optimization", "")
                        import ResolveConstantFunctions
                        ResolveConstantFunctions.main(True)
                        CyInterface().addImmediateMessage(
                            "END Python file optimization", "")
                        return 1
                    elif self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.replayScreen.showScreen(False)
                        return 1
                    # don't return 1 unless you want the input consumed

                elif theKey == int(InputTypes.KB_F2):
                    if self.bShift and not self.bCtrl and self.bAlt:
                        import remote_pdb
                        remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
                        return 1
                    elif self.bShift and not self.bCtrl and not self.bAlt:
                        import CvDebugInfoScreen
                        CvScreensInterface.showDebugInfoScreen()
                        return 1
                elif theKey == int(InputTypes.KB_F3):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.showDanQuayleScreen(())
                        return 1
                elif theKey == int(InputTypes.KB_F4):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.showUnVictoryScreen(())
                        return 1
                # </f1rpo>
        return 0
示例#8
0
import os
import remote_pdb

r = remote_pdb.RemotePdb('0.0.0.0', 4444)
"""
I want a remote debugging session where I can periodically check whether a file
or directory still exists. So let's add a function "f" to the remote debugger.
"""


def f(*args):
    x = os.path.isfile('rdb_fun.py') and 'still exists' or 'is gone!'
    print >> r.stdout, 'rdb_fun.py ' + x


r.do_f = f
r.set_trace()


def fac(n):
    p = 1
    for i in range(2, n + 1):
        p *= i
    return p


print fac(5)