ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- PK]9].-AA_win_subprocess.pynu[# flake8: noqa # fmt: off ## issue: https://bugs.python.org/issue19264 import ctypes import os import platform import subprocess from ctypes import Structure, WinError, byref, c_char_p, c_void_p, c_wchar, c_wchar_p, sizeof, windll from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPCWSTR, LPVOID, LPWSTR, WORD import _subprocess ## ## Types ## CREATE_UNICODE_ENVIRONMENT = 0x00000400 LPCTSTR = c_char_p LPTSTR = c_wchar_p LPSECURITY_ATTRIBUTES = c_void_p LPBYTE = ctypes.POINTER(BYTE) class STARTUPINFOW(Structure): _fields_ = [ ("cb", DWORD), ("lpReserved", LPWSTR), ("lpDesktop", LPWSTR), ("lpTitle", LPWSTR), ("dwX", DWORD), ("dwY", DWORD), ("dwXSize", DWORD), ("dwYSize", DWORD), ("dwXCountChars", DWORD), ("dwYCountChars", DWORD), ("dwFillAtrribute", DWORD), ("dwFlags", DWORD), ("wShowWindow", WORD), ("cbReserved2", WORD), ("lpReserved2", LPBYTE), ("hStdInput", HANDLE), ("hStdOutput", HANDLE), ("hStdError", HANDLE), ] LPSTARTUPINFOW = ctypes.POINTER(STARTUPINFOW) class PROCESS_INFORMATION(Structure): _fields_ = [ ("hProcess", HANDLE), ("hThread", HANDLE), ("dwProcessId", DWORD), ("dwThreadId", DWORD), ] LPPROCESS_INFORMATION = ctypes.POINTER(PROCESS_INFORMATION) class DUMMY_HANDLE(ctypes.c_void_p): def __init__(self, *a, **kw): super(DUMMY_HANDLE, self).__init__(*a, **kw) self.closed = False def Close(self): if not self.closed: windll.kernel32.CloseHandle(self) self.closed = True def __int__(self): return self.value CreateProcessW = windll.kernel32.CreateProcessW CreateProcessW.argtypes = [ LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION, ] CreateProcessW.restype = BOOL ## ## Patched functions/classes ## def CreateProcess( executable, args, _p_attr, _t_attr, inherit_handles, creation_flags, env, cwd, startup_info, ): """Create a process supporting unicode executable and args for win32 Python implementation of CreateProcess using CreateProcessW for Win32 """ si = STARTUPINFOW( dwFlags=startup_info.dwFlags, wShowWindow=startup_info.wShowWindow, cb=sizeof(STARTUPINFOW), ## XXXvlab: not sure of the casting here to ints. hStdInput=startup_info.hStdInput if startup_info.hStdInput is None else int(startup_info.hStdInput), hStdOutput=startup_info.hStdOutput if startup_info.hStdOutput is None else int(startup_info.hStdOutput), hStdError=startup_info.hStdError if startup_info.hStdError is None else int(startup_info.hStdError), ) wenv = None if env is not None: ## LPCWSTR seems to be c_wchar_p, so let's say CWSTR is c_wchar env = ( unicode("").join([ unicode("%s=%s\0") % (k, v) for k, v in env.items() ]) ) + unicode("\0") wenv = (c_wchar * len(env))() wenv.value = env wcwd = None if cwd is not None: wcwd = unicode(cwd) pi = PROCESS_INFORMATION() creation_flags |= CREATE_UNICODE_ENVIRONMENT if CreateProcessW( executable, args, None, None, inherit_handles, creation_flags, wenv, wcwd, byref(si), byref(pi), ): return ( DUMMY_HANDLE(pi.hProcess), DUMMY_HANDLE(pi.hThread), pi.dwProcessId, pi.dwThreadId, ) raise WinError() class Popen(subprocess.Popen): """This superseeds Popen and corrects a bug in cPython 2.7 implem""" def _execute_child( self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, ): """Code from part of _execute_child from Python 2.7 (9fbb65e) There are only 2 little changes concerning the construction of the the final string in shell mode: we preempt the creation of the command string when shell is True, because original function will try to encode unicode args which we want to avoid to be able to sending it as-is to ``CreateProcess``. """ if startupinfo is None: startupinfo = subprocess.STARTUPINFO() if not isinstance(args, subprocess.types.StringTypes): args = [i if isinstance(i, bytes) else i.encode('utf-8') for i in args] args = subprocess.list2cmdline(args) if platform.python_implementation() == "CPython": args = args.decode('utf-8') startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = _subprocess.SW_HIDE env = os.environ if env is None else env comspec = env.get("COMSPEC", unicode("cmd.exe")) if ( _subprocess.GetVersion() >= 0x80000000 or os.path.basename(comspec).lower() == "command.com" ): w9xpopen = self._find_w9xpopen() args = unicode('"%s" %s') % (w9xpopen, args) creationflags |= _subprocess.CREATE_NEW_CONSOLE super(Popen, self)._execute_child( args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, False, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, ) _subprocess.CreateProcess = CreateProcess # fmt: on PK]9]9P^^#__pycache__/__init__.cpython-37.pycnu[B a!@sfddlmZmZddlZddlZddlZejrLejdkrLddlm Z e j Z nej Z dZ ddZ d Z dS) )absolute_importunicode_literalsNwin32)_win_subprocesslc Cspy.t|dtjtjtjd}|\}}|j}Wn6tk rd}z|jd|j}}}Wdd}~XYnX|||fS)NT)universal_newlinesstdinstderrstdout)Popen subprocessPIPE communicate returncodeOSErrorerrnostrerror)cmdprocessouterrcodeZos_errorrT/opt/alt/python37/lib/python3.7/site-packages/virtualenv/util/subprocess/__init__.pyrun_cmds   &r)r r rCREATE_NO_WINDOW) __future__rrr sysZsixPY2platformr rr rr__all__rrrrs PK]9]H7*__pycache__/_win_subprocess.cpython-37.pycnu[B aA @s(ddlZddlZddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z ddl mZmZmZmZmZmZmZmZddlZdZeZe ZeZeeZGdddeZeeZGdddeZeeZ Gd d d ejZ!e j"j#Z#eeeeeeeeee g e#_$ee#_%d d Z&Gd ddej'Z'e&e_&dS)N) StructureWinErrorbyrefc_char_pc_void_pc_wchar c_wchar_psizeofwindll)BOOLBYTEDWORDHANDLELPCWSTRLPVOIDLPWSTRWORDic@s|eZdZdefdefdefdefdefdefdefdefd efd efd efd efd efdefdefdefdefdefgZdS) STARTUPINFOWcbZ lpReservedZ lpDesktopZlpTitleZdwXZdwYZdwXSizeZdwYSizeZ dwXCountCharsZ dwYCountCharsZdwFillAtrributedwFlags wShowWindowZ cbReserved2Z lpReserved2 hStdInput hStdOutput hStdErrorN) __name__ __module__ __qualname__r rrLPBYTEr_fields_rr[/opt/alt/python37/lib/python3.7/site-packages/virtualenv/util/subprocess/_win_subprocess.pyrs        rc@s(eZdZdefdefdefdefgZdS)PROCESS_INFORMATIONhProcesshThread dwProcessId dwThreadIdN)rrrrr rrrrr r!(s r!cs,eZdZfddZddZddZZS) DUMMY_HANDLEcstt|j||d|_dS)NF)superr&__init__closed)selfakw) __class__rr r(3szDUMMY_HANDLE.__init__cCs|jstj|d|_dS)NT)r)r kernel32Z CloseHandle)r*rrr Close7s zDUMMY_HANDLE.ClosecCs|jS)N)value)r*rrr __int__<szDUMMY_HANDLE.__int__)rrrr(r/r1 __classcell__rr)r-r r&1s r&c Cst|j|jtt|jdkr |jnt|j|jdkr8|jnt|j|jdkrP|jnt|jd} d} |dk rtd dd| Dtd}t t |} || _ d} |dk rt|} t} |tO}t||dd||| | t| t|  rt| jt| j| j| jfStdS)zCreate a process supporting unicode executable and args for win32 Python implementation of CreateProcess using CreateProcessW for Win32 N)rrrrrrcSs g|]\}}td||fqS)z%s=%s)unicode).0kvrrr gsz!CreateProcess..)rrrr rintrrr4joinitemsrlenr0r!CREATE_UNICODE_ENVIRONMENTCreateProcessWrr&r"r#r$r%r) executableargsZ_p_attrZ_t_attrZinherit_handlesZcreation_flagsenvcwdZ startup_infosiZwenvZwcwdpirrr CreateProcessMs6    rFcs eZdZdZfddZZS)Popenz>This superseeds Popen and corrects a bug in cPython 2.7 implemcs|dkrt}t|tjjsLdd|D}t|}tdkrL|d}|j t j O_ t j |_ |dkrrtjn|}|dtd}t dkstj|d kr|}td ||f}| t jO} tt|||||||||| d | | | ||||dS) aCode from part of _execute_child from Python 2.7 (9fbb65e) There are only 2 little changes concerning the construction of the the final string in shell mode: we preempt the creation of the command string when shell is True, because original function will try to encode unicode args which we want to avoid to be able to sending it as-is to ``CreateProcess``. NcSs$g|]}t|tr|n|dqS)zutf-8) isinstancebytesencode)r5irrr r8sz(Popen._execute_child..CPythonzutf-8ZCOMSPECzcmd.exelz command.comz"%s" %sF) subprocessZ STARTUPINFOrHtypesZ StringTypes list2cmdlineplatformpython_implementationdecoder _subprocessZSTARTF_USESHOWWINDOWZSW_HIDErosenvirongetr4Z GetVersionpathbasenamelowerZ_find_w9xpopenZCREATE_NEW_CONSOLEr'rG_execute_child)r*rAr@ preexec_fn close_fdsrCrBuniversal_newlines startupinfo creationflagsshellto_closep2creadp2cwritec2preadc2pwriteerrreaderrwriteZcomspecZw9xpopen)r-rr rZs*        zPopen._execute_child)rrr__doc__rZr2rr)r-r rGsrG)(ctypesrTrPrMrrrrrrrr r Zctypes.wintypesr r r rrrrrrSr>ZLPCTSTRZLPTSTRZLPSECURITY_ATTRIBUTESPOINTERrrZLPSTARTUPINFOWr!ZLPPROCESS_INFORMATIONr&r.r?argtypesrestyperFrGrrrr s0,(     4.PK]9]y#!! __init__.pynu[from __future__ import absolute_import, unicode_literals import subprocess import sys import six if six.PY2 and sys.platform == "win32": from . import _win_subprocess Popen = _win_subprocess.Popen else: Popen = subprocess.Popen CREATE_NO_WINDOW = 0x80000000 def run_cmd(cmd): try: process = Popen( cmd, universal_newlines=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, ) out, err = process.communicate() # input disabled code = process.returncode except OSError as os_error: code, out, err = os_error.errno, "", os_error.strerror return code, out, err __all__ = ( "subprocess", "Popen", "run_cmd", "CREATE_NO_WINDOW", ) PK]9].-AA_win_subprocess.pynu[PK]9]9P^^#__pycache__/__init__.cpython-37.pycnu[PK]9]H7*4__pycache__/_win_subprocess.cpython-37.pycnu[PK]9]y#!! #.__init__.pynu[PKj1