__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
import contextlib
import logging
import os
import subprocess
import shlex
import sys
import sysconfig
import tempfile
import venv
class VirtualEnvironment:
def __init__(self, prefix, **venv_create_args):
self._logger = logging.getLogger(self.__class__.__name__)
venv.create(prefix, **venv_create_args)
self._prefix = prefix
self._paths = sysconfig.get_paths(
scheme='venv',
vars={'base': self.prefix},
expand=True,
)
@classmethod
@contextlib.contextmanager
def from_tmpdir(cls, *, prefix=None, dir=None, **venv_create_args):
delete = not bool(os.environ.get('PYTHON_TESTS_KEEP_VENV'))
with tempfile.TemporaryDirectory(prefix=prefix, dir=dir, delete=delete) as tmpdir:
yield cls(tmpdir, **venv_create_args)
@property
def prefix(self):
return self._prefix
@property
def paths(self):
return self._paths
@property
def interpreter(self):
return os.path.join(self.paths['scripts'], os.path.basename(sys.executable))
def _format_output(self, name, data, indent='\t'):
if not data:
return indent + f'{name}: (none)'
if len(data.splitlines()) == 1:
return indent + f'{name}: {data}'
else:
prefixed_lines = '\n'.join(indent + '> ' + line for line in data.splitlines())
return indent + f'{name}:\n' + prefixed_lines
def run(self, *args, **subprocess_args):
if subprocess_args.get('shell'):
raise ValueError('Running the subprocess in shell mode is not supported.')
default_args = {
'capture_output': True,
'check': True,
}
try:
result = subprocess.run([self.interpreter, *args], **default_args | subprocess_args)
except subprocess.CalledProcessError as e:
if e.returncode != 0:
self._logger.error(
f'Interpreter returned non-zero exit status {e.returncode}.\n'
+ self._format_output('COMMAND', shlex.join(e.cmd)) + '\n'
+ self._format_output('STDOUT', e.stdout.decode()) + '\n'
+ self._format_output('STDERR', e.stderr.decode()) + '\n'
)
raise
else:
return result
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| _hypothesis_stubs | Folder | 0755 |
|
|
| interpreters | Folder | 0755 |
|
|
| __init__.py | File | 89.22 KB | 0644 |
|
| ast_helper.py | File | 1.79 KB | 0644 |
|
| asynchat.py | File | 11.33 KB | 0644 |
|
| asyncore.py | File | 19.9 KB | 0644 |
|
| bytecode_helper.py | File | 5.63 KB | 0644 |
|
| hashlib_helper.py | File | 1.86 KB | 0644 |
|
| hypothesis_helper.py | File | 1.35 KB | 0644 |
|
| i18n_helper.py | File | 1.98 KB | 0644 |
|
| import_helper.py | File | 10.44 KB | 0644 |
|
| logging_helper.py | File | 916 B | 0644 |
|
| numbers.py | File | 1.5 KB | 0644 |
|
| os_helper.py | File | 24.52 KB | 0644 |
|
| pty_helper.py | File | 2.98 KB | 0644 |
|
| refleak_helper.py | File | 165 B | 0644 |
|
| script_helper.py | File | 12.29 KB | 0644 |
|
| smtpd.py | File | 30.01 KB | 0755 |
|
| socket_helper.py | File | 13.23 KB | 0644 |
|
| testcase.py | File | 4.64 KB | 0644 |
|
| threading_helper.py | File | 7.86 KB | 0644 |
|
| venv.py | File | 2.3 KB | 0644 |
|
| warnings_helper.py | File | 6.69 KB | 0644 |
|