idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
20,800 | def can_import ( api ) : if not has_binding ( api ) : return False current = loaded_api ( ) if api == QT_API_PYQT_DEFAULT : return current in [ QT_API_PYQT , QT_API_PYQTv1 , QT_API_PYQT5 , None ] else : return current in [ api , None ] | Safely query whether an API is importable without importing it |
20,801 | def extended_blank_lines ( logical_line , blank_lines , blank_before , indent_level , previous_logical ) : if previous_logical . startswith ( 'def ' ) : if blank_lines and pycodestyle . DOCSTRING_REGEX . match ( logical_line ) : yield ( 0 , 'E303 too many blank lines ({0})' . format ( blank_lines ) ) elif pycodestyle .... | Check for missing blank lines after class declaration . |
20,802 | def fix_e265 ( source , aggressive = False ) : if '#' not in source : return source ignored_line_numbers = multiline_string_lines ( source , include_docstrings = True ) | set ( commented_out_code_lines ( source ) ) fixed_lines = [ ] sio = io . StringIO ( source ) for ( line_number , line ) in enumerate ( sio . readline... | Format block comments . |
20,803 | def refactor ( source , fixer_names , ignore = None , filename = '' ) : check_lib2to3 ( ) from lib2to3 import pgen2 try : new_text = refactor_with_2to3 ( source , fixer_names = fixer_names , filename = filename ) except ( pgen2 . parse . ParseError , SyntaxError , UnicodeDecodeError , UnicodeEncodeError ) : return sour... | Return refactored code using lib2to3 . |
20,804 | def _get_indentation ( line ) : if line . strip ( ) : non_whitespace_index = len ( line ) - len ( line . lstrip ( ) ) return line [ : non_whitespace_index ] else : return '' | Return leading whitespace . |
20,805 | def _priority_key ( pep8_result ) : priority = [ 'e701' , 'e702' , 'e225' , 'e231' , 'e201' , 'e262' ] middle_index = 10000 lowest_priority = [ 'e501' ] key = pep8_result [ 'id' ] . lower ( ) try : return priority . index ( key ) except ValueError : try : return middle_index + lowest_priority . index ( key ) + 1 except... | Key for sorting PEP8 results . |
20,806 | def normalize_multiline ( line ) : if line . startswith ( 'def ' ) and line . rstrip ( ) . endswith ( ':' ) : return line + ' pass' elif line . startswith ( 'return ' ) : return 'def _(): ' + line elif line . startswith ( '@' ) : return line + 'def _(): pass' elif line . startswith ( 'class ' ) : return line + ' pass' ... | Normalize multiline - related code that will cause syntax error . |
20,807 | def fix_whitespace ( line , offset , replacement ) : left = line [ : offset ] . rstrip ( '\n\r \t\\' ) right = line [ offset : ] . lstrip ( '\n\r \t\\' ) if right . startswith ( '#' ) : return line else : return left + replacement + right | Replace whitespace at offset and return fixed line . |
20,808 | def apply_global_fixes ( source , options , where = 'global' , filename = '' ) : if any ( code_match ( code , select = options . select , ignore = options . ignore ) for code in [ 'E101' , 'E111' ] ) : source = reindent ( source , indent_size = options . indent_size ) for ( code , function ) in global_fixes ( ) : if co... | Run global fixes on source code . |
20,809 | def main ( argv = None , apply_config = True ) : if argv is None : argv = sys . argv try : signal . signal ( signal . SIGPIPE , signal . SIG_DFL ) except AttributeError : pass try : args = parse_args ( argv [ 1 : ] , apply_config = apply_config ) if args . list_fixes : for code , description in sorted ( supported_fixes... | Command - line entry . |
20,810 | def fix_e722 ( self , result ) : ( line_index , _ , target ) = get_index_offset_contents ( result , self . source ) if BARE_EXCEPT_REGEX . search ( target ) : self . source [ line_index ] = '{0}{1}' . format ( target [ : result [ 'column' ] - 1 ] , "except Exception:" ) | fix bare except |
20,811 | def _split_after_delimiter ( self , item , indent_amt ) : self . _delete_whitespace ( ) if self . fits_on_current_line ( item . size ) : return last_space = None for item in reversed ( self . _lines ) : if ( last_space and ( not isinstance ( item , Atom ) or not item . is_colon ) ) : break else : last_space = None if i... | Split the line only after a delimiter . |
20,812 | def interact ( banner = None , readfunc = None , local = None ) : console = InteractiveConsole ( local ) if readfunc is not None : console . raw_input = readfunc else : try : import readline except ImportError : pass console . interact ( banner ) | Closely emulate the interactive Python interpreter . |
20,813 | def runsource ( self , source , filename = "<input>" , symbol = "single" ) : try : code = self . compile ( source , filename , symbol ) except ( OverflowError , SyntaxError , ValueError ) : self . showsyntaxerror ( filename ) return False if code is None : return True self . runcode ( code ) return False | Compile and run some source in the interpreter . |
20,814 | def push ( self , line ) : self . buffer . append ( line ) source = "\n" . join ( self . buffer ) more = self . runsource ( source , self . filename ) if not more : self . resetbuffer ( ) return more | Push a line to the interpreter . |
20,815 | def show_in_pager ( self , strng , * args , ** kwargs ) : if isinstance ( strng , dict ) : strng = strng . get ( 'text/plain' , strng ) print ( strng ) | Run a string through pager |
20,816 | def matchers ( self ) : return [ self . file_matches , self . magic_matches , self . python_func_kw_matches , self . dict_key_matches , ] | All active matcher routines for completion |
20,817 | def init_completer ( self ) : if IPythonRelease . _version_major >= 6 : self . Completer = self . _new_completer_600 ( ) elif IPythonRelease . _version_major >= 5 : self . Completer = self . _new_completer_500 ( ) elif IPythonRelease . _version_major >= 2 : self . Completer = self . _new_completer_234 ( ) elif IPythonR... | Initialize the completion machinery . |
20,818 | def open_handle ( self , dwDesiredAccess = win32 . PROCESS_ALL_ACCESS ) : hProcess = win32 . OpenProcess ( dwDesiredAccess , win32 . FALSE , self . dwProcessId ) try : self . close_handle ( ) except Exception : warnings . warn ( "Failed to close process handle: %s" % traceback . format_exc ( ) ) self . hProcess = hProc... | Opens a new handle to the process . |
20,819 | def close_handle ( self ) : try : if hasattr ( self . hProcess , 'close' ) : self . hProcess . close ( ) elif self . hProcess not in ( None , win32 . INVALID_HANDLE_VALUE ) : win32 . CloseHandle ( self . hProcess ) finally : self . hProcess = None | Closes the handle to the process . |
20,820 | def kill ( self , dwExitCode = 0 ) : hProcess = self . get_handle ( win32 . PROCESS_TERMINATE ) win32 . TerminateProcess ( hProcess , dwExitCode ) | Terminates the execution of the process . |
20,821 | def suspend ( self ) : self . scan_threads ( ) suspended = list ( ) try : for aThread in self . iter_threads ( ) : aThread . suspend ( ) suspended . append ( aThread ) except Exception : for aThread in suspended : try : aThread . resume ( ) except Exception : pass raise | Suspends execution on all threads of the process . |
20,822 | def resume ( self ) : if self . get_thread_count ( ) == 0 : self . scan_threads ( ) resumed = list ( ) try : for aThread in self . iter_threads ( ) : aThread . resume ( ) resumed . append ( aThread ) except Exception : for aThread in resumed : try : aThread . suspend ( ) except Exception : pass raise | Resumes execution on all threads of the process . |
20,823 | def is_debugged ( self ) : hProcess = self . get_handle ( win32 . PROCESS_QUERY_INFORMATION ) return win32 . CheckRemoteDebuggerPresent ( hProcess ) | Tries to determine if the process is being debugged by another process . It may detect other debuggers besides WinAppDbg . |
20,824 | def __fixup_labels ( self , disasm ) : for index in compat . xrange ( len ( disasm ) ) : ( address , size , text , dump ) = disasm [ index ] m = self . __hexa_parameter . search ( text ) while m : s , e = m . span ( ) value = text [ s : e ] try : label = self . get_label_at_address ( int ( value , 0x10 ) ) except Excep... | Private method used when disassembling from process memory . |
20,825 | def disassemble_current ( self , dwThreadId ) : aThread = self . get_thread ( dwThreadId ) return self . disassemble_instruction ( aThread . get_pc ( ) ) | Disassemble the instruction at the program counter of the given thread . |
20,826 | def is_wow64 ( self ) : try : wow64 = self . __wow64 except AttributeError : if ( win32 . bits == 32 and not win32 . wow64 ) : wow64 = False else : if win32 . PROCESS_ALL_ACCESS == win32 . PROCESS_ALL_ACCESS_VISTA : dwAccess = win32 . PROCESS_QUERY_LIMITED_INFORMATION else : dwAccess = win32 . PROCESS_QUERY_INFORMATION... | Determines if the process is running under WOW64 . |
20,827 | def get_start_time ( self ) : if win32 . PROCESS_ALL_ACCESS == win32 . PROCESS_ALL_ACCESS_VISTA : dwAccess = win32 . PROCESS_QUERY_LIMITED_INFORMATION else : dwAccess = win32 . PROCESS_QUERY_INFORMATION hProcess = self . get_handle ( dwAccess ) CreationTime = win32 . GetProcessTimes ( hProcess ) [ 0 ] return win32 . Fi... | Determines when has this process started running . |
20,828 | def get_exit_time ( self ) : if self . is_alive ( ) : ExitTime = win32 . GetSystemTimeAsFileTime ( ) else : if win32 . PROCESS_ALL_ACCESS == win32 . PROCESS_ALL_ACCESS_VISTA : dwAccess = win32 . PROCESS_QUERY_LIMITED_INFORMATION else : dwAccess = win32 . PROCESS_QUERY_INFORMATION hProcess = self . get_handle ( dwAccess... | Determines when has this process finished running . If the process is still alive the current time is returned instead . |
20,829 | def get_running_time ( self ) : if win32 . PROCESS_ALL_ACCESS == win32 . PROCESS_ALL_ACCESS_VISTA : dwAccess = win32 . PROCESS_QUERY_LIMITED_INFORMATION else : dwAccess = win32 . PROCESS_QUERY_INFORMATION hProcess = self . get_handle ( dwAccess ) ( CreationTime , ExitTime , _ , _ ) = win32 . GetProcessTimes ( hProcess ... | Determines how long has this process been running . |
20,830 | def get_services ( self ) : self . __load_System_class ( ) pid = self . get_pid ( ) return [ d for d in System . get_active_services ( ) if d . ProcessId == pid ] | Retrieves the list of system services that are currently running in this process . |
20,831 | def get_peb_address ( self ) : try : return self . _peb_ptr except AttributeError : hProcess = self . get_handle ( win32 . PROCESS_QUERY_INFORMATION ) pbi = win32 . NtQueryInformationProcess ( hProcess , win32 . ProcessBasicInformation ) address = pbi . PebBaseAddress self . _peb_ptr = address return address | Returns a remote pointer to the PEB . |
20,832 | def get_command_line_block ( self ) : peb = self . get_peb ( ) pp = self . read_structure ( peb . ProcessParameters , win32 . RTL_USER_PROCESS_PARAMETERS ) s = pp . CommandLine return ( s . Buffer , s . MaximumLength ) | Retrieves the command line block memory address and size . |
20,833 | def get_environment_block ( self ) : peb = self . get_peb ( ) pp = self . read_structure ( peb . ProcessParameters , win32 . RTL_USER_PROCESS_PARAMETERS ) Environment = pp . Environment try : EnvironmentSize = pp . EnvironmentSize except AttributeError : mbi = self . mquery ( Environment ) EnvironmentSize = mbi . Regio... | Retrieves the environment block memory address for the process . |
20,834 | def get_command_line ( self ) : ( Buffer , MaximumLength ) = self . get_command_line_block ( ) CommandLine = self . peek_string ( Buffer , dwMaxSize = MaximumLength , fUnicode = True ) gst = win32 . GuessStringType if gst . t_default == gst . t_ansi : CommandLine = CommandLine . encode ( 'cp1252' ) return CommandLine | Retrieves the command line with wich the program was started . |
20,835 | def get_environment_variables ( self ) : data = self . peek ( * self . get_environment_block ( ) ) tmp = ctypes . create_string_buffer ( data ) buffer = ctypes . create_unicode_buffer ( len ( data ) ) ctypes . memmove ( buffer , tmp , len ( data ) ) del tmp pos = 0 while buffer [ pos ] != u'\0' : pos += 1 pos += 1 envi... | Retrieves the environment variables with wich the program is running . |
20,836 | def get_environment_data ( self , fUnicode = None ) : warnings . warn ( "Process.get_environment_data() is deprecated" " since WinAppDbg 1.5." , DeprecationWarning ) block = [ key + u'=' + value for ( key , value ) in self . get_environment_variables ( ) ] if fUnicode is None : gst = win32 . GuessStringType fUnicode = ... | Retrieves the environment block data with wich the program is running . |
20,837 | def parse_environment_data ( block ) : warnings . warn ( "Process.parse_environment_data() is deprecated" " since WinAppDbg 1.5." , DeprecationWarning ) environment = dict ( ) if not block : return environment gst = win32 . GuessStringType if type ( block [ 0 ] ) == gst . t_ansi : equals = '=' terminator = '\0' else : ... | Parse the environment block into a Python dictionary . |
20,838 | def get_environment ( self , fUnicode = None ) : variables = self . get_environment_variables ( ) if fUnicode is None : gst = win32 . GuessStringType fUnicode = gst . t_default == gst . t_unicode if not fUnicode : variables = [ ( key . encode ( 'cp1252' ) , value . encode ( 'cp1252' ) ) for ( key , value ) in variables... | Retrieves the environment with wich the program is running . |
20,839 | def search_bytes ( self , bytes , minAddr = None , maxAddr = None ) : pattern = BytePattern ( bytes ) matches = Search . search_process ( self , pattern , minAddr , maxAddr ) for addr , size , data in matches : yield addr | Search for the given byte pattern within the process memory . |
20,840 | def search_text ( self , text , encoding = "utf-16le" , caseSensitive = False , minAddr = None , maxAddr = None ) : pattern = TextPattern ( text , encoding , caseSensitive ) matches = Search . search_process ( self , pattern , minAddr , maxAddr ) for addr , size , data in matches : yield addr , data | Search for the given text within the process memory . |
20,841 | def search_regexp ( self , regexp , flags = 0 , minAddr = None , maxAddr = None , bufferPages = - 1 ) : pattern = RegExpPattern ( regexp , flags ) return Search . search_process ( self , pattern , minAddr , maxAddr , bufferPages ) | Search for the given regular expression within the process memory . |
20,842 | def search_hexa ( self , hexa , minAddr = None , maxAddr = None ) : pattern = HexPattern ( hexa ) matches = Search . search_process ( self , pattern , minAddr , maxAddr ) for addr , size , data in matches : yield addr , data | Search for the given hexadecimal pattern within the process memory . |
20,843 | def read ( self , lpBaseAddress , nSize ) : hProcess = self . get_handle ( win32 . PROCESS_VM_READ | win32 . PROCESS_QUERY_INFORMATION ) if not self . is_buffer ( lpBaseAddress , nSize ) : raise ctypes . WinError ( win32 . ERROR_INVALID_ADDRESS ) data = win32 . ReadProcessMemory ( hProcess , lpBaseAddress , nSize ) if ... | Reads from the memory of the process . |
20,844 | def read_int ( self , lpBaseAddress ) : return self . __read_c_type ( lpBaseAddress , compat . b ( '@l' ) , ctypes . c_int ) | Reads a signed integer from the memory of the process . |
20,845 | def read_structure ( self , lpBaseAddress , stype ) : if type ( lpBaseAddress ) not in ( type ( 0 ) , type ( long ( 0 ) ) ) : lpBaseAddress = ctypes . cast ( lpBaseAddress , ctypes . c_void_p ) data = self . read ( lpBaseAddress , ctypes . sizeof ( stype ) ) buff = ctypes . create_string_buffer ( data ) ptr = ctypes . ... | Reads a ctypes structure from the memory of the process . |
20,846 | def read_string ( self , lpBaseAddress , nChars , fUnicode = False ) : if fUnicode : nChars = nChars * 2 szString = self . read ( lpBaseAddress , nChars ) if fUnicode : szString = compat . unicode ( szString , 'U16' , 'ignore' ) return szString | Reads an ASCII or Unicode string from the address space of the process . |
20,847 | def peek ( self , lpBaseAddress , nSize ) : data = '' if nSize > 0 : try : hProcess = self . get_handle ( win32 . PROCESS_VM_READ | win32 . PROCESS_QUERY_INFORMATION ) for mbi in self . get_memory_map ( lpBaseAddress , lpBaseAddress + nSize ) : if not mbi . is_readable ( ) : nSize = mbi . BaseAddress - lpBaseAddress br... | Reads the memory of the process . |
20,848 | def peek_char ( self , lpBaseAddress ) : char = self . peek ( lpBaseAddress , 1 ) if char : return ord ( char ) return 0 | Reads a single character from the memory of the process . |
20,849 | def peek_string ( self , lpBaseAddress , fUnicode = False , dwMaxSize = 0x1000 ) : if not lpBaseAddress or dwMaxSize == 0 : if fUnicode : return u'' return '' if not dwMaxSize : dwMaxSize = 0x1000 szString = self . peek ( lpBaseAddress , dwMaxSize ) if fUnicode : szString = compat . unicode ( szString , 'U16' , 'replac... | Tries to read an ASCII or Unicode string from the address space of the process . |
20,850 | def malloc ( self , dwSize , lpAddress = None ) : hProcess = self . get_handle ( win32 . PROCESS_VM_OPERATION ) return win32 . VirtualAllocEx ( hProcess , lpAddress , dwSize ) | Allocates memory into the address space of the process . |
20,851 | def mprotect ( self , lpAddress , dwSize , flNewProtect ) : hProcess = self . get_handle ( win32 . PROCESS_VM_OPERATION ) return win32 . VirtualProtectEx ( hProcess , lpAddress , dwSize , flNewProtect ) | Set memory protection in the address space of the process . |
20,852 | def free ( self , lpAddress ) : hProcess = self . get_handle ( win32 . PROCESS_VM_OPERATION ) win32 . VirtualFreeEx ( hProcess , lpAddress ) | Frees memory from the address space of the process . |
20,853 | def is_pointer ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . has_content ( ) | Determines if an address is a valid code or data pointer . |
20,854 | def is_address_valid ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return True | Determines if an address is a valid user mode address . |
20,855 | def is_address_free ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_free ( ) | Determines if an address belongs to a free page . |
20,856 | def is_address_reserved ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_reserved ( ) | Determines if an address belongs to a reserved page . |
20,857 | def is_address_commited ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_commited ( ) | Determines if an address belongs to a commited page . |
20,858 | def is_address_guard ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_guard ( ) | Determines if an address belongs to a guard page . |
20,859 | def is_address_readable ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_readable ( ) | Determines if an address belongs to a commited and readable page . The page may or may not have additional permissions . |
20,860 | def is_address_writeable ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_writeable ( ) | Determines if an address belongs to a commited and writeable page . The page may or may not have additional permissions . |
20,861 | def is_address_copy_on_write ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_copy_on_write ( ) | Determines if an address belongs to a commited copy - on - write page . The page may or may not have additional permissions . |
20,862 | def is_address_executable ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_executable ( ) | Determines if an address belongs to a commited and executable page . The page may or may not have additional permissions . |
20,863 | def is_address_executable_and_writeable ( self , address ) : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise return mbi . is_executable_and_writeable ( ) | Determines if an address belongs to a commited writeable and executable page . The page may or may not have additional permissions . |
20,864 | def is_buffer ( self , address , size ) : if size <= 0 : raise ValueError ( "The size argument must be greater than zero" ) while size > 0 : try : mbi = self . mquery ( address ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror == win32 . ERROR_INVALID_PARAMETER : return False raise if not mbi . has_c... | Determines if the given memory area is a valid code or data buffer . |
20,865 | def iter_memory_map ( self , minAddr = None , maxAddr = None ) : minAddr , maxAddr = MemoryAddresses . align_address_range ( minAddr , maxAddr ) prevAddr = minAddr - 1 currentAddr = minAddr while prevAddr < currentAddr < maxAddr : try : mbi = self . mquery ( currentAddr ) except WindowsError : e = sys . exc_info ( ) [ ... | Produces an iterator over the memory map to the process address space . |
20,866 | def get_mapped_filenames ( self , memoryMap = None ) : hProcess = self . get_handle ( win32 . PROCESS_VM_READ | win32 . PROCESS_QUERY_INFORMATION ) if not memoryMap : memoryMap = self . get_memory_map ( ) mappedFilenames = dict ( ) for mbi in memoryMap : if mbi . Type not in ( win32 . MEM_IMAGE , win32 . MEM_MAPPED ) :... | Retrieves the filenames for memory mapped files in the debugee . |
20,867 | def iter_memory_snapshot ( self , minAddr = None , maxAddr = None ) : memory = self . get_memory_map ( minAddr , maxAddr ) if not memory : return try : filenames = self . get_mapped_filenames ( memory ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror != win32 . ERROR_ACCESS_DENIED : raise filenames =... | Returns an iterator that allows you to go through the memory contents of a process . |
20,868 | def restore_memory_snapshot ( self , snapshot , bSkipMappedFiles = True , bSkipOnError = False ) : if not snapshot or not isinstance ( snapshot , list ) or not isinstance ( snapshot [ 0 ] , win32 . MemoryBasicInformation ) : raise TypeError ( "Only snapshots returned by " "take_memory_snapshot() can be used here." ) hP... | Attempts to restore the memory state as it was when the given snapshot was taken . |
20,869 | def inject_code ( self , payload , lpParameter = 0 ) : lpStartAddress = self . malloc ( len ( payload ) ) try : self . write ( lpStartAddress , payload ) aThread = self . start_thread ( lpStartAddress , lpParameter , bSuspended = False ) aThread . pInjectedMemory = lpStartAddress except Exception : self . free ( lpStar... | Injects relocatable code into the process memory and executes it . |
20,870 | def get_pid_from_tid ( self , dwThreadId ) : try : try : hThread = win32 . OpenThread ( win32 . THREAD_QUERY_LIMITED_INFORMATION , False , dwThreadId ) except WindowsError : e = sys . exc_info ( ) [ 1 ] if e . winerror != win32 . ERROR_ACCESS_DENIED : raise hThread = win32 . OpenThread ( win32 . THREAD_QUERY_INFORMATIO... | Retrieves the global ID of the process that owns the thread . |
20,871 | def argv_to_cmdline ( argv ) : cmdline = list ( ) for token in argv : if not token : token = '""' else : if '"' in token : token = token . replace ( '"' , '\\"' ) if ' ' in token or '\t' in token or '\n' in token or '\r' in token : token = '"%s"' % token cmdline . append ( token ) return ' ' . join ( cmdline ) | Convert a list of arguments to a single command line string . |
20,872 | def get_explorer_pid ( self ) : try : exp = win32 . SHGetFolderPath ( win32 . CSIDL_WINDOWS ) except Exception : exp = None if not exp : exp = os . getenv ( 'SystemRoot' ) if exp : exp = os . path . join ( exp , 'explorer.exe' ) exp_list = self . find_processes_by_filename ( exp ) if exp_list : return exp_list [ 0 ] [ ... | Tries to find the process ID for explorer . exe . |
20,873 | def scan ( self ) : has_threads = True try : try : self . scan_processes_and_threads ( ) except Exception : self . scan_processes_fast ( ) for aProcess in self . __processDict . values ( ) : if aProcess . _get_thread_ids ( ) : try : aProcess . scan_threads ( ) except WindowsError : has_threads = False finally : self . ... | Populates the snapshot with running processes and threads and loaded modules . |
20,874 | def scan_processes_and_threads ( self ) : our_pid = win32 . GetCurrentProcessId ( ) dead_pids = set ( compat . iterkeys ( self . __processDict ) ) found_tids = set ( ) if our_pid in dead_pids : dead_pids . remove ( our_pid ) dwFlags = win32 . TH32CS_SNAPPROCESS | win32 . TH32CS_SNAPTHREAD with win32 . CreateToolhelp32S... | Populates the snapshot with running processes and threads . |
20,875 | def scan_processes ( self ) : our_pid = win32 . GetCurrentProcessId ( ) dead_pids = set ( compat . iterkeys ( self . __processDict ) ) if our_pid in dead_pids : dead_pids . remove ( our_pid ) pProcessInfo = None try : pProcessInfo , dwCount = win32 . WTSEnumerateProcesses ( win32 . WTS_CURRENT_SERVER_HANDLE ) for index... | Populates the snapshot with running processes . |
20,876 | def scan_processes_fast ( self ) : new_pids = set ( win32 . EnumProcesses ( ) ) old_pids = set ( compat . iterkeys ( self . __processDict ) ) our_pid = win32 . GetCurrentProcessId ( ) if our_pid in new_pids : new_pids . remove ( our_pid ) if our_pid in old_pids : old_pids . remove ( our_pid ) for pid in new_pids . diff... | Populates the snapshot with running processes . Only the PID is retrieved for each process . |
20,877 | def scan_process_filenames ( self ) : complete = True for aProcess in self . __processDict . values ( ) : try : new_name = None old_name = aProcess . fileName try : aProcess . fileName = None new_name = aProcess . get_filename ( ) finally : if not new_name : aProcess . fileName = old_name complete = False except Except... | Update the filename for each process in the snapshot when possible . |
20,878 | def clear_dead_processes ( self ) : for pid in self . get_process_ids ( ) : aProcess = self . get_process ( pid ) if not aProcess . is_alive ( ) : self . _del_process ( aProcess ) | Removes Process objects from the snapshot referring to processes no longer running . |
20,879 | def clear_unattached_processes ( self ) : for pid in self . get_process_ids ( ) : aProcess = self . get_process ( pid ) if not aProcess . is_being_debugged ( ) : self . _del_process ( aProcess ) | Removes Process objects from the snapshot referring to processes not being debugged . |
20,880 | def close_process_handles ( self ) : for pid in self . get_process_ids ( ) : aProcess = self . get_process ( pid ) try : aProcess . close_handle ( ) except Exception : e = sys . exc_info ( ) [ 1 ] try : msg = "Cannot close process handle %s, reason: %s" msg %= ( aProcess . hProcess . value , str ( e ) ) warnings . warn... | Closes all open handles to processes in this snapshot . |
20,881 | def close_process_and_thread_handles ( self ) : for aProcess in self . iter_processes ( ) : aProcess . close_thread_handles ( ) try : aProcess . close_handle ( ) except Exception : e = sys . exc_info ( ) [ 1 ] try : msg = "Cannot close process handle %s, reason: %s" msg %= ( aProcess . hProcess . value , str ( e ) ) wa... | Closes all open handles to processes and threads in this snapshot . |
20,882 | def _add_process ( self , aProcess ) : dwProcessId = aProcess . dwProcessId self . __processDict [ dwProcessId ] = aProcess | Private method to add a process object to the snapshot . |
20,883 | def _del_process ( self , dwProcessId ) : try : aProcess = self . __processDict [ dwProcessId ] del self . __processDict [ dwProcessId ] except KeyError : aProcess = None msg = "Unknown process ID %d" % dwProcessId warnings . warn ( msg , RuntimeWarning ) if aProcess : aProcess . clear ( ) | Private method to remove a process object from the snapshot . |
20,884 | def ismethoddescriptor ( object ) : return ( hasattr ( object , "__get__" ) and not hasattr ( object , "__set__" ) and not ismethod ( object ) and not isfunction ( object ) and not isclass ( object ) ) | Return true if the object is a method descriptor . |
20,885 | def isroutine ( object ) : return ( isbuiltin ( object ) or isfunction ( object ) or ismethod ( object ) or ismethoddescriptor ( object ) ) | Return true if the object is any kind of function or method . |
20,886 | def classify_class_attrs ( cls ) : mro = getmro ( cls ) names = dir ( cls ) result = [ ] for name in names : if name in cls . __dict__ : obj = cls . __dict__ [ name ] else : obj = getattr ( cls , name ) homecls = getattr ( obj , "__objclass__" , None ) if homecls is None : for base in mro : if name in base . __dict__ :... | Return list of attribute - descriptor tuples . |
20,887 | def indentsize ( line ) : expline = string . expandtabs ( line ) return len ( expline ) - len ( string . lstrip ( expline ) ) | Return the indent size in spaces at the start of a line of text . |
20,888 | def getdoc ( object ) : try : doc = object . __doc__ except AttributeError : return None if not isinstance ( doc , ( str , unicode ) ) : return None try : lines = string . split ( string . expandtabs ( doc ) , '\n' ) except UnicodeError : return None else : margin = None for line in lines [ 1 : ] : content = len ( stri... | Get the documentation string for an object . |
20,889 | def getfile ( object ) : if ismodule ( object ) : if hasattr ( object , '__file__' ) : return object . __file__ raise TypeError , 'arg is a built-in module' if isclass ( object ) : object = sys . modules . get ( object . __module__ ) if hasattr ( object , '__file__' ) : return object . __file__ raise TypeError , 'arg i... | Work out which source or compiled file an object was defined in . |
20,890 | def getmoduleinfo ( path ) : filename = os . path . basename ( path ) suffixes = map ( lambda ( suffix , mode , mtype ) : ( - len ( suffix ) , suffix , mode , mtype ) , imp . get_suffixes ( ) ) suffixes . sort ( ) for neglen , suffix , mode , mtype in suffixes : if filename [ neglen : ] == suffix : return filename [ : ... | Get the module name suffix mode and module type for a given file . |
20,891 | def getsourcefile ( object ) : filename = getfile ( object ) if string . lower ( filename [ - 4 : ] ) in [ '.pyc' , '.pyo' ] : filename = filename [ : - 4 ] + '.py' for suffix , mode , kind in imp . get_suffixes ( ) : if 'b' in mode and string . lower ( filename [ - len ( suffix ) : ] ) == suffix : return None if os . ... | Return the Python source file an object was defined in if it exists . |
20,892 | def getabsfile ( object ) : return os . path . normcase ( os . path . abspath ( getsourcefile ( object ) or getfile ( object ) ) ) | Return an absolute path to the source or compiled file for an object . |
20,893 | def getmodule ( object ) : if ismodule ( object ) : return object if isclass ( object ) : return sys . modules . get ( object . __module__ ) try : file = getabsfile ( object ) except TypeError : return None if modulesbyfile . has_key ( file ) : return sys . modules [ modulesbyfile [ file ] ] for module in sys . modules... | Return the module an object was defined in or None if not found . |
20,894 | def findsource ( object ) : try : file = open ( getsourcefile ( object ) ) except ( TypeError , IOError ) : raise IOError , 'could not get source code' lines = file . readlines ( ) file . close ( ) if ismodule ( object ) : return lines , 0 if isclass ( object ) : name = object . __name__ pat = re . compile ( r'^\s*clas... | Return the entire source file and starting line number for an object . |
20,895 | def getcomments ( object ) : try : lines , lnum = findsource ( object ) except IOError : return None if ismodule ( object ) : start = 0 if lines and lines [ 0 ] [ : 2 ] == '#!' : start = 1 while start < len ( lines ) and string . strip ( lines [ start ] ) in [ '' , '#' ] : start = start + 1 if start < len ( lines ) and... | Get lines of comments immediately preceding an object s source code . |
20,896 | def getblock ( lines ) : try : tokenize . tokenize ( ListReader ( lines ) . readline , BlockFinder ( ) . tokeneater ) except EndOfBlock , eob : return lines [ : eob . args [ 0 ] ] return lines [ : 1 ] | Extract the block of code at the top of the given list of lines . |
20,897 | def getsourcelines ( object ) : lines , lnum = findsource ( object ) if ismodule ( object ) : return lines , 0 else : return getblock ( lines [ lnum : ] ) , lnum + 1 | Return a list of source lines and starting line number for an object . |
20,898 | def getclasstree ( classes , unique = 0 ) : children = { } roots = [ ] for c in classes : if c . __bases__ : for parent in c . __bases__ : if not children . has_key ( parent ) : children [ parent ] = [ ] children [ parent ] . append ( c ) if unique and parent in classes : break elif c not in roots : roots . append ( c ... | Arrange the given list of classes into a hierarchy of nested lists . |
20,899 | def getargs ( co ) : if not iscode ( co ) : raise TypeError , 'arg is not a code object' nargs = co . co_argcount names = co . co_varnames args = list ( names [ : nargs ] ) step = 0 if not sys . platform . startswith ( 'java' ) : code = co . co_code import dis for i in range ( nargs ) : if args [ i ] [ : 1 ] in [ '' , ... | Get information about the arguments accepted by a code object . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.