Пример #1
0
def attach_listen(session, target, method, cwd=None, log_dir=None):
    log.info("Attaching {0} to {1} by socket using {2}.", session, target,
             method.upper())

    assert method in ("api", "cli")

    config = _attach_common_config(session, target, cwd)
    config["listen"] = {}
    config["listen"]["host"] = host = attach_listen.host
    config["listen"]["port"] = port = attach_listen.port

    if method == "cli":
        args = [
            os.path.dirname(debugpy.__file__),
            "--connect",
            compat.filename_str(host) + ":" + str(port),
        ]
        if log_dir is not None:
            args += ["--log-to", log_dir]
        if "subProcess" in config:
            args += ["--configure-subProcess", str(config["subProcess"])]
        debuggee_setup = None
    elif method == "api":
        args = []
        api_config = {k: v for k, v in config.items() if k in {"subProcess"}}
        debuggee_setup = """
import debugpy
if {log_dir!r}:
    debugpy.log_to({log_dir!r})
debugpy.configure({api_config!r})
debugpy.connect({address!r})
"""
        debuggee_setup = fmt(debuggee_setup,
                             address=(host, port),
                             log_dir=log_dir,
                             api_config=api_config)
    else:
        raise ValueError
    args += target.cli(session.spawn_debuggee.env)

    try:
        del config["subProcess"]
    except KeyError:
        pass

    def spawn_debuggee(occ):
        assert occ.body == some.dict.containing({"host": host, "port": port})
        session.spawn_debuggee(args, cwd=cwd, setup=debuggee_setup)

    session.timeline.when(timeline.Event("debugpyWaitingForServer"),
                          spawn_debuggee)
    session.spawn_adapter(
        args=[] if log_dir is None else ["--log-dir", log_dir])
    return session.request_attach()
Пример #2
0
def start_debugging(argv_0):
    # We need to set up sys.argv[0] before invoking either listen() or connect(),
    # because they use it to report the "process" event. Thus, we can't rely on
    # run_path() and run_module() doing that, even though they will eventually.
    sys.argv[0] = compat.filename_str(argv_0)

    log.debug("sys.argv after patching: {0!r}", sys.argv)

    debugpy.configure(options.config)

    if options.mode == "listen":
        debugpy.listen(options.address)
    elif options.mode == "connect":
        debugpy.connect(options.address,
                        access_token=options.adapter_access_token)
    else:
        raise AssertionError(repr(options.mode))

    if options.wait_for_client:
        debugpy.wait_for_client()
Пример #3
0
def connect_vscode_debugger(port=5678):
    """
	Connect to Visual Studio Code for debugging. This function blocks until the debugger
	is connected! Not recommended for use in startup.py

	.. note:: See https://docs.binary.ninja/dev/plugins.html#remote-debugging-with-vscode for step-by-step instructions on how to set up Python debugging.

	:param port: Port number for connecting to the debugger.
	"""
    # pip install --user debugpy
    import debugpy  # type: ignore
    import sys
    if sys.platform == "win32":
        debugpy.configure(python=f"{sys.base_exec_prefix}/python",
                          qt="pyside2")
    else:
        debugpy.configure(python=f"{sys.base_exec_prefix}/bin/python3",
                          qt="pyside2")
    debugpy.listen(("127.0.0.1", port))
    debugpy.wait_for_client()
    execute_on_main_thread(lambda: debugpy.debug_this_thread())
Пример #4
0
def start_dap():
    #pylint:disable=W0603
    global __debug_started, __debugpy_debug_port, __debugger
    if __debug_started:
        print(
            f"DAP already started with debugpy for port {__debugpy_debug_port}"
        )
        return
    try:

        if __natLinkPythonDebugPortEnviornmentVar in os.environ:
            natLinkPythonPortStringVal = os.environ[
                __natLinkPythonDebugPortEnviornmentVar]
            __debugpy_debug_port = int(natLinkPythonPortStringVal)
        print(f"Starting debugpy on port {natLinkPythonPortStringVal}")

        python_exec = __pyDefaultPythonExecutor  #for now, only the python in system path can be used for natlink and this module
        print(f"Python Executable (required for debugging): '{python_exec}'")
        debugpy.configure(python=f"{python_exec}")
        debugpy.listen(__debugpy_debug_port)
        print(f"debugpy listening on port {__debugpy_debug_port}")
        __debug_started = True
        __debugger = dap

        if __natLinkPythonDebugOnStartupVar in os.environ:
            dos_str = os.environ[__natLinkPythonDebugOnStartupVar]
            dos = len(dos_str) == 1 and dos_str in "YyTt"

            if dos:
                print(
                    f"Waiting for DAP debugger to attach now as {__natLinkPythonDebugOnStartupVar} is set to {dos_str}"
                )
                debugpy.wait_for_client()

    except Exception as ee:
        print(f"""
    Exception {ee} while starting debug.  Possible cause is incorrect python executable specified {python_exec}
""")
Пример #5
0
#!/usr/bin/python3

import os, sys, json
import debugpy
from pathlib import Path
from Pythonic.web_daemon import MainWorker
from PySide2.QtCore import QCoreApplication, QTimer


debugpy.configure({"subProcess": True})
debugpy.listen(5678)


def run():


    # Create home path (if not already existing)
    
    home_path = Path.home() / 'Pythonic'
    home_path.mkdir(exist_ok=True)

    # Create log path (if not already existing)

    logPath = home_path / 'log'
    logPath.mkdir(exist_ok=True)

    # Create directory for executables (if not already existing)

    execPath = home_path / 'executables'
    execPath.mkdir(exist_ok=True)
Пример #6
0
def is_debugger_listening(port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    return s.connect_ex(('127.0.0.1', port))


debugpy_port = os.environ.get("DD_DEBUG_PORT") if os.environ.get("DD_DEBUG_PORT") else 3000

# Checking for RUN_MAIN for those that want to run the app locally with the python interpreter instead of uwsgi
if os.environ.get("DD_DEBUG") == "True" and not os.getenv("RUN_MAIN") and is_debugger_listening(debugpy_port) != 0:
    logger.info("DD_DEBUG is set to True, setting remote debugging on port {}".format(debugpy_port))
    try:
        import debugpy

        # Required, otherwise debugpy will try to use the uwsgi binary as the python interpreter - https://github.com/microsoft/debugpy/issues/262
        debugpy.configure({
                            "python": "python",
                            "subProcess": True
                        })
        debugpy.listen(("0.0.0.0", debugpy_port))
        if os.environ.get("DD_DEBUG_WAIT_FOR_CLIENT") == "True":
            logger.info("Waiting for the debugging client to connect on port {}".format(debugpy_port))
            debugpy.wait_for_client()
            print("Debugging client connected, resuming execution")
    except Exception as e:
        logger.exception(e)
        pass

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
Пример #7
0
from saml2.authn_context import requested_authn_context
from saml2.metadata import entity_descriptor, sign_entity_descriptor
from saml2.saml import NAMEID_FORMAT_TRANSIENT
from saml2.sigver import security_context
from saml2.validate import valid_instance
from satosa.backends.saml2 import SAMLBackend
from satosa.context import Context
from satosa.exception import SATOSAAuthenticationError, SATOSAStateError
from satosa.response import SeeOther, Response
from satosa.saml_util import make_saml_response
from six import text_type

from .spidsaml2_validator import Saml2ResponseValidator

logger = logging.getLogger(__name__)
debugpy.configure(python="/usr/bin/python3")
debugpy.listen(('0.0.0.0', 4444))


class SpidSAMLBackend(SAMLBackend):
    """
    A saml2 backend module (acting as a SPID SP).
    """
    _authn_context = 'https://www.spid.gov.it/SpidL1'

    def _metadata_endpoint(self, context):
        """
        Endpoint for retrieving the backend metadata
        :type context: satosa.context.Context
        :rtype: satosa.response.Response