id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
177,874 | import enum
import dis
import opcode as _opcode
import sys
from marshal import dumps as _dumps
from _pydevd_frame_eval.vendored import bytecode as _bytecode
def const_key(obj):
try:
return _dumps(obj)
except ValueError:
# For other types, we use the object identifier as an unique identifier
... | null |
177,875 | import enum
import dis
import opcode as _opcode
import sys
from marshal import dumps as _dumps
from _pydevd_frame_eval.vendored import bytecode as _bytecode
def _pushes_back(opname):
if opname in ["CALL_FINALLY"]:
# CALL_FINALLY pushes the address of the "finally" block instead of a
# value, hence ... | null |
177,876 | import enum
import dis
import opcode as _opcode
import sys
from marshal import dumps as _dumps
from _pydevd_frame_eval.vendored import bytecode as _bytecode
def _check_lineno(lineno):
if not isinstance(lineno, int):
raise TypeError("lineno must be an int")
if lineno < 1:
raise ValueError("inval... | null |
177,877 | import enum
import dis
import opcode as _opcode
import sys
from marshal import dumps as _dumps
from _pydevd_frame_eval.vendored import bytecode as _bytecode
def _check_arg_int(name, arg):
if not isinstance(arg, int):
raise TypeError(
"operation %s argument must be an int, "
"got %s"... | null |
177,878 | import sys
from enum import IntFlag
from _pydevd_frame_eval.vendored import bytecode as _bytecode
class CompilerFlags(IntFlag):
"""Possible values of the co_flags attribute of Code object.
Note: We do not rely on inspect values here as some of them are missing and
furthermore would be version dependent.
... | Infer the proper flags for a bytecode based on the instructions. Because the bytecode does not have enough context to guess if a function is asynchronous the algorithm tries to be conservative and will never turn a previously async code into a sync one. Parameters ---------- bytecode : Bytecode | ConcreteBytecode | Con... |
177,879 | import sys
from _pydevd_frame_eval.vendored import bytecode as _bytecode
from _pydevd_frame_eval.vendored.bytecode.concrete import ConcreteInstr
from _pydevd_frame_eval.vendored.bytecode.flags import CompilerFlags
from _pydevd_frame_eval.vendored.bytecode.instr import Label, SetLineno, Instr
class SetLineno:
__slo... | Generator used to reduce the use of function stacks. This allows to avoid nested recursion and allow to treat more cases. HOW-TO: Following the methods of Trampoline (see https://en.wikipedia.org/wiki/Trampoline_(computing)), We yield either: - the arguments that would be used in the recursive calls, i.e, 'yield block,... |
177,880 |
def _fix_contents(filename, contents):
import re
contents = re.sub(
r"from bytecode", r'from _pydevd_frame_eval.vendored.bytecode', contents, flags=re.MULTILINE
)
contents = re.sub(
r"import bytecode", r'from _pydevd_frame_eval.vendored import bytecode', contents, flags=re.MULTILINE
... | null |
177,881 | import sys
from _pydev_bundle import pydev_log
from _pydev_bundle._pydev_saved_modules import threading
from _pydevd_bundle.pydevd_comm import get_global_debugger
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER
from _pydevd_bundle.pydevd_additional_thread_info imp... | null |
177,882 | import sys
from _pydev_bundle import pydev_log
from _pydev_bundle._pydev_saved_modules import threading
from _pydevd_bundle.pydevd_comm import get_global_debugger
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER
from _pydevd_bundle.pydevd_additional_thread_info imp... | null |
177,883 | import sys
from _pydev_bundle import pydev_log
from _pydev_bundle._pydev_saved_modules import threading
from _pydevd_bundle.pydevd_comm import get_global_debugger
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER
from _pydevd_bundle.pydevd_additional_thread_info imp... | We separate the functionality into 2 functions so that we can generate a bytecode which generates a spurious line change so that we can do: if _pydev_needs_stop_at_break(): # Set line to line -1 _pydev_stop_at_break() # then, proceed to go to the current line # (which will then trigger a line event). |
177,884 | from collections import namedtuple
import dis
from functools import partial
import itertools
import os.path
import sys
from _pydevd_frame_eval.vendored import bytecode
from _pydevd_frame_eval.vendored.bytecode.instr import Instr, Label
from _pydev_bundle import pydev_log
from _pydevd_frame_eval.pydevd_frame_tracing imp... | Inserts pydevd programmatic breaks into the code (at the given lines). :param breakpoint_lines: set with the lines where we should add breakpoints. :return: tuple(boolean flag whether insertion was successful, modified code). |
177,885 | from . import VENDORED_ROOT
from ._util import cwd, iter_all_files
def prune_dir(dirname, basename):
if basename == '__pycache__':
return True
elif dirname != 'pydevd':
return False
elif basename.startswith('pydev'):
return False
elif basename.startswith('_pydev'):
return... | null |
177,886 | import json
version_json = '''
{
"date": "2023-04-03T17:37:14-0700",
"dirty": false,
"error": null,
"full-revisionid": "2f3e0bb7d5984486def3f2e3d246b974cf243b50",
"version": "1.6.7"
}
'''
def get_versions():
return json.loads(version_json) | null |
177,887 | import itertools
import os
import signal
import threading
import time
from debugpy import common
from debugpy.common import log, util
from debugpy.adapter import components, launchers, servers
_lock = threading.RLock()
_sessions = set()
def get(pid):
with _lock:
return next((session for session in _session... | null |
177,888 | import itertools
import os
import signal
import threading
import time
from debugpy import common
from debugpy.common import log, util
from debugpy.adapter import components, launchers, servers
_lock = threading.RLock()
_sessions = set()
_sessions_changed = threading.Event()
The provided code snippet includes necessary... | Blocks until all sessions have ended. A session ends when all components that it manages disconnect from it. |
177,889 | from __future__ import annotations
import atexit
import os
import sys
import debugpy
from debugpy import adapter, common, launcher
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components, servers, sessions
class Client(components.Component):
"""Handles the client side of a de... | null |
177,890 | from __future__ import annotations
import atexit
import os
import sys
import debugpy
from debugpy import adapter, common, launcher
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components, servers, sessions
def stop_serving():
try:
listener.close()
except Exceptio... | null |
177,891 | import functools
from debugpy.common import json, log, messaging, util
class ComponentNotAvailable(Exception):
def __init__(self, type):
def missing(session, type):
class Missing(object):
"""A dummy component that raises ComponentNotAvailable whenever some
attribute is accessed on it.
... | null |
177,892 | import argparse
import atexit
import codecs
import locale
import os
import sys
def _parse_argv(argv):
parser = argparse.ArgumentParser()
parser.add_argument(
"--for-server", type=int, metavar="PORT", help=argparse.SUPPRESS
)
parser.add_argument(
"--port",
type=int,
def... | null |
177,893 | import os
import subprocess
import sys
from debugpy import adapter, common
from debugpy.common import log, messaging, sockets
from debugpy.adapter import components, servers
class Launcher(components.Component):
"""Handles the launcher side of a debug session."""
message_handler = components.Component.message_h... | null |
177,894 | from __future__ import annotations
import os
import subprocess
import sys
import threading
import time
import debugpy
from debugpy import adapter
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components
import traceback
import io
listener = None
def is_serving():
return liste... | null |
177,895 | from __future__ import annotations
import os
import subprocess
import sys
import threading
import time
import debugpy
from debugpy import adapter
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components
import traceback
import io
listener = None
def stop_serving():
global lis... | null |
177,896 | from __future__ import annotations
import os
import subprocess
import sys
import threading
import time
import debugpy
from debugpy import adapter
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components
import traceback
import io
_lock = threading.RLock()
_connections = []
def co... | null |
177,897 | from __future__ import annotations
import os
import subprocess
import sys
import threading
import time
import debugpy
from debugpy import adapter
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components
import traceback
import io
_lock = threading.RLock()
_connections = []
_connec... | Blocks until all debug servers disconnect from the adapter. If there are no server connections, waits until at least one is established first, before waiting for it to disconnect. |
177,898 | from __future__ import annotations
import os
import subprocess
import sys
import threading
import time
import debugpy
from debugpy import adapter
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components
import traceback
import io
_lock = threading.RLock()
_connections_changed = th... | Unblocks any pending wait_until_disconnected() call that is waiting on the first server to connect. |
177,899 | from __future__ import annotations
import os
import subprocess
import sys
import threading
import time
import debugpy
from debugpy import adapter
from debugpy.common import json, log, messaging, sockets
from debugpy.adapter import components
import traceback
import io
access_token = None
listener = None
def inject(pid... | null |
177,900 | from __future__ import annotations
import functools
import typing
from debugpy import _version
def _api(cancelable=False):
def apply(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
from debugpy.server import api
wrapped = getattr(api, f.__name__)
return wr... | null |
177,901 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `log_to` function. Write a Python function `def log_to(__path: str) -> None` to solve the following problem:
Generate detailed debugpy logs in th... | Generate detailed debugpy logs in the specified directory. The directory must already exist. Several log files are generated, one for every process involved in the debug session. |
177,902 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `configure` function. Write a Python function `def configure(__properties: dict[str, typing.Any] | None = None, **kwargs) -> None` to solve the f... | Sets debug configuration properties that cannot be set in the "attach" request, because they must be applied as early as possible in the process being debugged. For example, a "launch" configuration with subprocess debugging disabled can be defined entirely in JSON:: { "request": "launch", "subProcess": false, ... } Bu... |
177,903 | from __future__ import annotations
import functools
import typing
from debugpy import _version
Endpoint = typing.Tuple[str, int]
The provided code snippet includes necessary dependencies for implementing the `listen` function. Write a Python function `def listen( __endpoint: Endpoint | int, *, in_process_debug_ada... | Starts a debug adapter debugging this process, that listens for incoming socket connections from clients on the specified address. `__endpoint` must be either a (host, port) tuple as defined by the standard `socket` module for the `AF_INET` address family, or a port number. If only the port is specified, host is "127.0... |
177,904 | from __future__ import annotations
import functools
import typing
from debugpy import _version
Endpoint = typing.Tuple[str, int]
The provided code snippet includes necessary dependencies for implementing the `connect` function. Write a Python function `def connect(__endpoint: Endpoint | int, *, access_token: str | Non... | Tells an existing debug adapter instance that is listening on the specified address to debug this process. `__endpoint` must be either a (host, port) tuple as defined by the standard `socket` module for the `AF_INET` address family, or a port number. If only the port is specified, host is "127.0.0.1". `access_token` mu... |
177,905 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `wait_for_client` function. Write a Python function `def wait_for_client() -> None` to solve the following problem:
If there is a client connecte... | If there is a client connected to the debug adapter that is debugging this process, returns immediately. Otherwise, blocks until a client connects to the adapter. While this function is waiting, it can be canceled by calling `wait_for_client.cancel()` from another thread. |
177,906 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `is_client_connected` function. Write a Python function `def is_client_connected() -> bool` to solve the following problem:
True if a client is c... | True if a client is connected to the debug adapter that is debugging this process. |
177,907 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `breakpoint` function. Write a Python function `def breakpoint() -> None` to solve the following problem:
If a client is connected to the debug a... | If a client is connected to the debug adapter that is debugging this process, pauses execution of all threads, and simulates a breakpoint being hit at the line following the call. It is also registered as the default handler for builtins.breakpoint(). |
177,908 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `debug_this_thread` function. Write a Python function `def debug_this_thread() -> None` to solve the following problem:
Makes the debugger aware ... | Makes the debugger aware of the current thread. Must be called on any background thread that is started by means other than the usual Python APIs (i.e. the "threading" module), in order for breakpoints to work on that thread. |
177,909 | from __future__ import annotations
import functools
import typing
from debugpy import _version
The provided code snippet includes necessary dependencies for implementing the `trace_this_thread` function. Write a Python function `def trace_this_thread(__should_trace: bool)` to solve the following problem:
Tells the deb... | Tells the debug adapter to enable or disable tracing on the current thread. When the thread is traced, the debug adapter can detect breakpoints being hit, but execution is slower, especially in functions that have any breakpoints set in them. Disabling tracing when breakpoints are not anticipated to be hit can improve ... |
177,910 | import ctypes
from ctypes.wintypes import BOOL, DWORD, HANDLE, LARGE_INTEGER, LPCSTR, UINT
from debugpy.common import log
def _errcheck(is_error_result=(lambda result: not result)):
def impl(result, func, args):
if is_error_result(result):
log.debug("{0} returned {1}", func.__name__, result)
... | null |
177,911 | import os
import sys
import debugpy
from debugpy import launcher
from debugpy.common import json
from debugpy.launcher import debuggee
import json
def launch_request(request):
debug_options = set(request("debugOptions", json.array(str)))
# Handling of properties that can also be specified as legacy "debugOpt... | null |
177,912 | import os
import sys
import debugpy
from debugpy import launcher
from debugpy.common import json
from debugpy.launcher import debuggee
def terminate_request(request):
del debuggee.wait_on_exit_predicates[:]
request.respond({})
debuggee.kill() | null |
177,913 | import os
import sys
import debugpy
from debugpy import launcher
from debugpy.common import json
from debugpy.launcher import debuggee
def disconnect():
del debuggee.wait_on_exit_predicates[:]
debuggee.kill() | null |
177,914 | import inspect
import os
import sys
def force_bytes(s, encoding, errors="strict"):
"""Converts s to bytes, using the provided encoding. If s is already bytes,
it is returned as is.
If errors="strict" and s is bytes, its encoding is verified by decoding it;
UnicodeError is raised if it cannot be decoded.... | Same as force_bytes(s, "ascii", errors) |
177,915 | import inspect
import os
import sys
def force_bytes(s, encoding, errors="strict"):
"""Converts s to bytes, using the provided encoding. If s is already bytes,
it is returned as is.
If errors="strict" and s is bytes, its encoding is verified by decoding it;
UnicodeError is raised if it cannot be decoded.... | Same as force_bytes(s, "utf8", errors) |
177,916 | from __future__ import annotations
import collections
import contextlib
import functools
import itertools
import os
import socket
import sys
import threading
from debugpy.common import json, log, util
from debugpy.common.util import hide_thread_from_debugger
class MessageDict(collections.OrderedDict):
"""A speciali... | JSON validator for message payload. If that value is missing or null, it is treated as if it were {}. |
177,917 | import os
import sys
import time
import threading
import traceback
from debugpy.common import log
def dump():
"""Dump stacks of all threads in this process, except for the current thread."""
tid = threading.current_thread().ident
pid = os.getpid()
log.info("Dumping stacks for process {0}...", pid)
f... | Invokes dump() on a background thread after waiting for the specified time. |
177,918 | import time
def reset():
global timestamp_zero
timestamp_zero = time.monotonic() | null |
177,919 | import functools
import threading
def threadsafe_method(func):
"""Marks a method of a ThreadSafeSingleton-derived class as inherently thread-safe.
A method so marked must either not use any singleton state, or lock it appropriately.
"""
func.is_threadsafe_method = True
return func
The provided code... | Automatically synchronizes all calls of a method of a ThreadSafeSingleton-derived class by locking the singleton for the duration of each call. |
177,920 | import socket
import sys
import threading
from debugpy.common import log
from debugpy.common.util import hide_thread_from_debugger
def _new_sock():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
# Set TCP keepalive on an open socket.
# It activates after 1 second (TCP_KEEPIDLE,... | Return a client socket that may be connected to a remote address. |
177,921 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
_files = {}
_levels = set()
def _update_levels():
global _levels
_levels = frozenset(level for file i... | null |
177,922 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
_lock = threading.RLock()
def write(level, text, _to_files=all):
assert level in LEVELS
t = timestamp... | null |
177,923 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
_tls = threading.local()
The provided code snippet includes necessary dependencies for implementing the `prefi... | Adds a prefix to all messages logged from the current thread for the duration of the context manager. |
177,924 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
_files = {}
def _close_files():
for file in tuple(_files.values()):
file.close() | null |
177,925 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
warning = functools.partial(write_format, "warning")
def _repr(value): # pragma: no cover
warning("$REPR ... | null |
177,926 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
warning = functools.partial(write_format, "warning")
def _vars(*names): # pragma: no cover
locals = inspe... | null |
177,927 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
warning = functools.partial(write_format, "warning")
def _stack(): # pragma: no cover
stack = "\n".join(t... | null |
177,928 | import atexit
import contextlib
import functools
import inspect
import io
import os
import platform
import sys
import threading
import traceback
import debugpy
from debugpy.common import json, timestamp, util
warning = functools.partial(write_format, "warning")
def _threads(): # pragma: no cover
output = "\n".joi... | null |
177,929 | import codecs
import os
import pydevd
import socket
import sys
import threading
import debugpy
from debugpy import adapter
from debugpy.common import json, log, sockets
from _pydevd_bundle.pydevd_constants import get_global_debugger
from pydevd_file_utils import absolute_path
from debugpy.common.util import hide_debugp... | null |
177,930 | import codecs
import os
import pydevd
import socket
import sys
import threading
import debugpy
from debugpy import adapter
from debugpy.common import json, log, sockets
from _pydevd_bundle.pydevd_constants import get_global_debugger
from pydevd_file_utils import absolute_path
from debugpy.common.util import hide_debugp... | null |
177,931 | import codecs
import os
import pydevd
import socket
import sys
import threading
import debugpy
from debugpy import adapter
from debugpy.common import json, log, sockets
from _pydevd_bundle.pydevd_constants import get_global_debugger
from pydevd_file_utils import absolute_path
from debugpy.common.util import hide_debugp... | null |
177,932 | import codecs
import os
import pydevd
import socket
import sys
import threading
import debugpy
from debugpy import adapter
from debugpy.common import json, log, sockets
from _pydevd_bundle.pydevd_constants import get_global_debugger
from pydevd_file_utils import absolute_path
from debugpy.common.util import hide_debugp... | null |
177,933 | import json
import os
import re
import sys
from importlib.util import find_spec
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
def in_range(parser, start, stop):
def parse(s):
n = parser(s)
if start is not ... | null |
177,934 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
HELP = """debugpy {0}
See https://aka.ms/debugpy for documentation.
U... | null |
177,935 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
import sys
if sys.version_info >= (3, 7):
from builtins import ... | null |
177,936 | import json
import os
import re
import sys
from importlib.util import find_spec
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": True}
def set_arg(varname, parser... | null |
177,937 | import json
import os
import re
import sys
from importlib.util import find_spec
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": True}
def set_const(varname, valu... | null |
177,938 | import json
import os
import re
import sys
from importlib.util import find_spec
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": True}
def set_address(mode):
... | null |
177,939 | import json
import os
import re
import sys
from importlib.util import find_spec
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": True}
def set_config(arg, it):
... | null |
177,940 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": Tru... | null |
177,941 | import json
import os
import re
import sys
from importlib.util import find_spec
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
TARGET = "<filename> | -m <module> | -c <code> | --pid <pid>"
options = Options()
options.config = {... | null |
177,942 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": Tru... | null |
177,943 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": Tru... | null |
177,944 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": Tru... | null |
177,945 | import json
import os
import re
import sys
from importlib.util import find_spec
assert "pydevd" in sys.modules
import pydevd
from _pydevd_bundle import pydevd_runpy as runpy
import debugpy
from debugpy.common import log
from debugpy.server import api
options = Options()
options.config = {"qt": "none", "subProcess": Tru... | null |
177,946 | import os
_debugpy_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
import sys
if sys.version_info >= (3, 7):
from builtins import _PathLike
if sys.version_info >= (3, 7):
class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer): # undocumented
import json
def attach(setup):
... | null |
177,947 | import sys
import locale
import warnings
def get_stream_enc(stream, default=None):
"""Return the given stream's encoding or a default.
There are cases where ``sys.std*`` might not actually be a stream, so
check for the encoding attribute prior to returning it, and return
a default if it doesn't exist or... | Return IPython's guess for the default encoding for bytes as text. If prefer_stream is True (default), asks for stdin.encoding first, to match the calling Terminal, but that is often None for subprocesses. Then fall back on locale.getpreferredencoding(), which should be a sensible platform default (that respects LANG e... |
177,948 | import os
import sys
import errno
import shutil
import random
from . import py3compat
def expand_path(s):
"""Expand $VARS and ~names in a string, like a shell
:Examples:
In [2]: os.environ['FOO']='test'
In [3]: expand_path('variable FOO is $FOO')
Out[3]: 'variable FOO is test'
"""
#... | Find a file by looking through a sequence of paths. This iterates through a sequence of paths looking for a file and returns the full, absolute path of the first occurence of the file. If no set of path dirs is given, the filename is tested as is, after running through :func:`expandvars` and :func:`expanduser`. Thus a ... |
177,949 | import os
import sys
import errno
import shutil
import random
from . import py3compat
def link(src, dst):
"""Hard links ``src`` to ``dst``, returning 0 or errno.
Note that the special errno ``ENOLINK`` will be returned if ``os.link`` isn't
supported by the operating system.
"""
if not hasattr(os, "l... | Attempts to hardlink ``src`` to ``dst``, copying if the link fails. Attempts to maintain the semantics of ``shutil.copy``. Because ``os.link`` does not overwrite files, a unique temporary file will be used if the target already exists, then that file will be moved into place. |
177,950 | import os
import sys
import errno
import shutil
import random
from . import py3compat
The provided code snippet includes necessary dependencies for implementing the `ensure_dir_exists` function. Write a Python function `def ensure_dir_exists(path, mode=0o755)` to solve the following problem:
ensure that a directory ex... | ensure that a directory exists If it doesn't exist, try to create it and protect against a race condition if another process is doing the same. The default permissions are 755, which differ from os.makedirs default of 777. |
177,951 | import os
import re
import sys
import textwrap
from string import Formatter
The provided code snippet includes necessary dependencies for implementing the `indent` function. Write a Python function `def indent(instr,nspaces=4, ntabs=0, flatten=False)` to solve the following problem:
Indent a string a given number of s... | Indent a string a given number of spaces or tabstops. indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces. Parameters ---------- instr : basestring The string to be indented. nspaces : int (default: 4) The number of spaces to be indented. ntabs : int (default: 0) The number of tabs to be indented. flatten : bo... |
177,952 | import os
import re
import sys
import textwrap
from string import Formatter
def dedent(text):
"""Equivalent of textwrap.dedent that ignores unindented first line.
This means it will still dedent strings like:
'''foo
is a bar
'''
For use in wrap_paragraphs.
"""
if text.startswith('\n'):
... | Wrap multiple paragraphs to fit a specified width. This is equivalent to textwrap.wrap, but with support for multiple paragraphs, as separated by empty lines. Returns ------- list of complete paragraphs, wrapped to fill `ncols` columns. |
177,953 | import os
import re
import sys
import textwrap
from string import Formatter
The provided code snippet includes necessary dependencies for implementing the `strip_ansi` function. Write a Python function `def strip_ansi(source)` to solve the following problem:
Remove ansi escape codes from text. Parameters ---------- so... | Remove ansi escape codes from text. Parameters ---------- source : str Source to remove the ansi from |
177,954 | import os
import re
import sys
import textwrap
from string import Formatter
def compute_item_matrix(items, empty=None, *args, **kwargs) :
"""Returns a nested list, and info to columnize items
Parameters
----------
items
list of strings to columize
empty : (default None)
default value... | Transform a list of strings into a single string with columns. Parameters ---------- items : sequence of strings The strings to process. separator : str, optional [default is two spaces] The string that separates columns. displaywidth : int, optional [default is 80] Width of the display in number of characters. Returns... |
177,955 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def no_code(x, encoding=None):
return x | null |
177,956 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
The provided code snippet includes necessary dependencies for implementing the `buffer_to_bytes` function. Write a Python function `def buffer_to_bytes(buf)` to solve the following problem:... | Cast a buffer or memoryview object to bytes |
177,957 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def _modify_str_or_docstring(str_change_func):
@functools.wraps(str_change_func)
def wrapper(func_or_str):
if isinstance(func_or_str, string_types):
func = None
... | null |
177,958 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
The provided code snippet includes necessary dependencies for implementing the `safe_unicode` function. Write a Python function `def safe_unicode(e)` to solve the following problem:
unicode... | unicode(e) with various fallbacks. Used for exceptions, which may not be safe to call unicode() on. |
177,959 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
if sys.version_info[0] >= 3 or platform.python_implementation() == 'IronPython':
str_to_unicode = no_code
unicode_to_str = no_code
str_to_bytes = encode
bytes_to_str = decode... | Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file. `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result of os.environ.get("PATH"), or can be overridden with a custom search path. This is a backport of shutil.which from... |
177,960 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def input(prompt=''):
return builtin_mod.input(prompt) | null |
177,961 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def isidentifier(s, dotted=False):
if dotted:
return all(isidentifier(a) for a in s.split("."))
return s.isidentifier() | null |
177,962 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def iteritems(d): return iter(d.items()) | null |
177,963 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def itervalues(d): return iter(d.values()) | null |
177,964 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def execfile(fname, glob, loc=None, compiler=None):
loc = loc if (loc is not None) else glob
with open(fname, 'rb') as f:
compiler = compiler or compile
... | null |
177,965 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
if sys.version_info[0] >= 3:
PY3 = True
# keep reference to builtin_mod because the kernel overrides that value
# to forward requests to a frontend.
builtin_mod_name = "built... | Refactor 'print x' statements in a doctest to print(x) style. 2to3 unfortunately doesn't pick up on our doctests. Can accept a string or a function, so it can be used as a decorator. |
177,966 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
The provided code snippet includes necessary dependencies for implementing the `u_format` function. Write a Python function `def u_format(s)` to solve the following problem:
{u}'abc'" --> "... | {u}'abc'" --> "'abc'" (Python 3) Accepts a string or a function, so it can be used as a decorator. |
177,967 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
The provided code snippet includes necessary dependencies for implementing the `get_closure` function. Write a Python function `def get_closure(f)` to solve the following problem:
Get a fun... | Get a function's closure attribute |
177,968 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def input(prompt=''):
return builtin_mod.raw_input(prompt) | null |
177,969 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def isidentifier(s, dotted=False):
if dotted:
return all(isidentifier(a) for a in s.split("."))
return bool(_name_re.match(s)) | null |
177,970 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def iteritems(d): return d.iteritems() | null |
177,971 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def itervalues(d): return d.itervalues() | null |
177,972 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def MethodType(func, instance):
return types.MethodType(func, instance, type(instance)) | null |
177,973 | import functools
import os
import sys
import re
import shutil
import types
from .encoding import DEFAULT_ENCODING
import platform
def doctest_refactor_print(func_or_str):
return func_or_str | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.