PHP 8.2.30
Preview: _shell_utils.py Size: 2.55 KB
//opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/distutils/_shell_utils.py

"""
Helper functions for interacting with the shell, and consuming shell-style
parameters provided in config files.
"""
import os
import shlex
import subprocess
try:
    from shlex import quote
except ImportError:
    from pipes import quote

__all__ = ['WindowsParser', 'PosixParser', 'NativeParser']


class CommandLineParser:
    """
    An object that knows how to split and join command-line arguments.

    It must be true that ``argv == split(join(argv))`` for all ``argv``.
    The reverse neednt be true - `join(split(cmd))` may result in the addition
    or removal of unnecessary escaping.
    """
    @staticmethod
    def join(argv):
        """ Join a list of arguments into a command line string """
        raise NotImplementedError

    @staticmethod
    def split(cmd):
        """ Split a command line string into a list of arguments """
        raise NotImplementedError


class WindowsParser:
    """
    The parsing behavior used by `subprocess.call("string")` on Windows, which
    matches the Microsoft C/C++ runtime.

    Note that this is _not_ the behavior of cmd.
    """
    @staticmethod
    def join(argv):
        # note that list2cmdline is specific to the windows syntax
        return subprocess.list2cmdline(argv)

    @staticmethod
    def split(cmd):
        import ctypes  # guarded import for systems without ctypes
        try:
            ctypes.windll
        except AttributeError:
            raise NotImplementedError

        # Windows has special parsing rules for the executable (no quotes),
        # that we do not care about - insert a dummy element
        if not cmd:
            return []
        cmd = 'dummy ' + cmd

        CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
        CommandLineToArgvW.restype = ctypes.POINTER(ctypes.c_wchar_p)
        CommandLineToArgvW.argtypes = (ctypes.c_wchar_p, ctypes.POINTER(ctypes.c_int))

        nargs = ctypes.c_int()
        lpargs = CommandLineToArgvW(cmd, ctypes.byref(nargs))
        args = [lpargs[i] for i in range(nargs.value)]
        assert not ctypes.windll.kernel32.LocalFree(lpargs)

        # strip the element we inserted
        assert args[0] == "dummy"
        return args[1:]


class PosixParser:
    """
    The parsing behavior used by `subprocess.call("string", shell=True)` on Posix.
    """
    @staticmethod
    def join(argv):
        return ' '.join(quote(arg) for arg in argv)

    @staticmethod
    def split(cmd):
        return shlex.split(cmd, posix=True)


if os.name == 'nt':
    NativeParser = WindowsParser
elif os.name == 'posix':
    NativeParser = PosixParser

Directory Contents

Dirs: 6 × Files: 28

Name Size Perms Modified Actions
checks DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
command DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
fcompiler DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
mingw DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
tests DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
962 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
27.95 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
97.98 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
9.31 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
7.98 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
22.11 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
10.04 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.48 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
7.73 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
834 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.13 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.54 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.98 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.81 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
21.55 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
87.26 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.14 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.58 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
12.67 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
634 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
713 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
634 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
110.53 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.30 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.55 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.02 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.03 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
119 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).