<s> from __future__ import with_statement <EOL> from watchdog . utils import platform <EOL> if not platform . is_windows ( ) : <EOL> raise ImportError <EOL> import ctypes . wintypes <EOL> import struct <EOL> try : <EOL> LPVOID = ctypes . wintypes . LPVOID <EOL> except AttributeError : <EOL> LPVOID = ctypes . c_void_p <EOL> INVALID_HANDLE_VALUE = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_FILE_NAME = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_DIR_NAME = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_ATTRIBUTES = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_SIZE = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_LAST_WRITE = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_LAST_ACCESS = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_CREATION = <NUM_LIT> <EOL> FILE_NOTIFY_CHANGE_SECURITY = <NUM_LIT> <EOL> FILE_FLAG_BACKUP_SEMANTICS = <NUM_LIT> <EOL> FILE_FLAG_OVERLAPPED = <NUM_LIT> <EOL> FILE_LIST_DIRECTORY = <NUM_LIT> <EOL> FILE_SHARE_READ = <NUM_LIT> <EOL> FILE_SHARE_WRITE = <NUM_LIT> <EOL> FILE_SHARE_DELETE = <NUM_LIT> <EOL> OPEN_EXISTING = <NUM_LIT:3> <EOL> FILE_ACTION_CREATED = <NUM_LIT:1> <EOL> FILE_ACTION_DELETED = <NUM_LIT:2> <EOL> FILE_ACTION_MODIFIED = <NUM_LIT:3> <EOL> FILE_ACTION_RENAMED_OLD_NAME = <NUM_LIT:4> <EOL> FILE_ACTION_RENAMED_NEW_NAME = <NUM_LIT:5> <EOL> FILE_ACTION_OVERFLOW = <NUM_LIT> <EOL> FILE_ACTION_ADDED = FILE_ACTION_CREATED <EOL> FILE_ACTION_REMOVED = FILE_ACTION_DELETED <EOL> THREAD_TERMINATE = <NUM_LIT> <EOL> WAIT_ABANDONED = <NUM_LIT> <EOL> WAIT_IO_COMPLETION = <NUM_LIT> <EOL> WAIT_OBJECT_0 = <NUM_LIT> <EOL> WAIT_TIMEOUT = <NUM_LIT> <EOL> class OVERLAPPED ( ctypes . Structure ) : <EOL> _fields_ = [ ( '<STR_LIT>' , LPVOID ) , <EOL> ( '<STR_LIT>' , LPVOID ) , <EOL> ( '<STR_LIT>' , ctypes . wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , ctypes . wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , LPVOID ) , <EOL> ( '<STR_LIT>' , ctypes . wintypes . HANDLE ) , <EOL> ] <EOL> def _errcheck_bool ( value , func , args ) : <EOL> if not value : <EOL> raise ctypes . WinError ( ) <EOL> return args <EOL> def _errcheck_handle ( value , func , args ) : <EOL> if not value : <EOL> raise ctypes . WinError ( ) <EOL> if value == INVALID_HANDLE_VALUE : <EOL> raise ctypes . WinError ( ) <EOL> return args <EOL> def _errcheck_dword ( value , func , args ) : <EOL> if value == <NUM_LIT> : <EOL> raise ctypes . WinError ( ) <EOL> return args <EOL> try : <EOL> ReadDirectoryChangesW = ctypes . windll . kernel32 . ReadDirectoryChangesW <EOL> except AttributeError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> ReadDirectoryChangesW . restype = ctypes . wintypes . BOOL <EOL> ReadDirectoryChangesW . errcheck = _errcheck_bool <EOL> ReadDirectoryChangesW . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> LPVOID , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . wintypes . BOOL , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . POINTER ( ctypes . wintypes . DWORD ) , <EOL> ctypes . POINTER ( OVERLAPPED ) , <EOL> LPVOID <EOL> ) <EOL> CreateFileW = ctypes . windll . kernel32 . CreateFileW <EOL> CreateFileW . restype = ctypes . wintypes . HANDLE <EOL> CreateFileW . errcheck = _errcheck_handle <EOL> CreateFileW . argtypes = ( <EOL> ctypes . wintypes . LPCWSTR , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . wintypes . DWORD , <EOL> LPVOID , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . wintypes . HANDLE <EOL> ) <EOL> CloseHandle = ctypes . windll . kernel32 . CloseHandle <EOL> CloseHandle . restype = ctypes . wintypes . BOOL <EOL> CloseHandle . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> ) <EOL> CancelIoEx = ctypes . windll . kernel32 . CancelIoEx <EOL> CancelIoEx . restype = ctypes . wintypes . BOOL <EOL> CancelIoEx . errcheck = _errcheck_bool <EOL> CancelIoEx . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> ctypes . POINTER ( OVERLAPPED ) <EOL> ) <EOL> CreateEvent = ctypes . windll . kernel32 . CreateEventW <EOL> CreateEvent . restype = ctypes . wintypes . HANDLE <EOL> CreateEvent . errcheck = _errcheck_handle <EOL> CreateEvent . argtypes = ( <EOL> LPVOID , <EOL> ctypes . wintypes . BOOL , <EOL> ctypes . wintypes . BOOL , <EOL> ctypes . wintypes . LPCWSTR , <EOL> ) <EOL> SetEvent = ctypes . windll . kernel32 . SetEvent <EOL> SetEvent . restype = ctypes . wintypes . BOOL <EOL> SetEvent . errcheck = _errcheck_bool <EOL> SetEvent . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> ) <EOL> WaitForSingleObjectEx = ctypes . windll . kernel32 . WaitForSingleObjectEx <EOL> WaitForSingleObjectEx . restype = ctypes . wintypes . DWORD <EOL> WaitForSingleObjectEx . errcheck = _errcheck_dword <EOL> WaitForSingleObjectEx . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . wintypes . BOOL , <EOL> ) <EOL> CreateIoCompletionPort = ctypes . windll . kernel32 . CreateIoCompletionPort <EOL> CreateIoCompletionPort . restype = ctypes . wintypes . HANDLE <EOL> CreateIoCompletionPort . errcheck = _errcheck_handle <EOL> CreateIoCompletionPort . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> ctypes . wintypes . HANDLE , <EOL> LPVOID , <EOL> ctypes . wintypes . DWORD , <EOL> ) <EOL> GetQueuedCompletionStatus = ctypes . windll . kernel32 . GetQueuedCompletionStatus <EOL> GetQueuedCompletionStatus . restype = ctypes . wintypes . BOOL <EOL> GetQueuedCompletionStatus . errcheck = _errcheck_bool <EOL> GetQueuedCompletionStatus . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> LPVOID , <EOL> LPVOID , <EOL> ctypes . POINTER ( OVERLAPPED ) , <EOL> ctypes . wintypes . DWORD , <EOL> ) <EOL> PostQueuedCompletionStatus = ctypes . windll . kernel32 . PostQueuedCompletionStatus <EOL> PostQueuedCompletionStatus . restype = ctypes . wintypes . BOOL <EOL> PostQueuedCompletionStatus . errcheck = _errcheck_bool <EOL> PostQueuedCompletionStatus . argtypes = ( <EOL> ctypes . wintypes . HANDLE , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . wintypes . DWORD , <EOL> ctypes . POINTER ( OVERLAPPED ) , <EOL> ) <EOL> class FILE_NOTIFY_INFORMATION ( ctypes . Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , ctypes . wintypes . DWORD ) , <EOL> ( "<STR_LIT>" , ctypes . wintypes . DWORD ) , <EOL> ( "<STR_LIT>" , ctypes . wintypes . DWORD ) , <EOL> ( "<STR_LIT>" , ( ctypes . c_char * <NUM_LIT:1> ) ) ] <EOL> LPFNI = ctypes . POINTER ( FILE_NOTIFY_INFORMATION ) <EOL> def get_FILE_NOTIFY_INFORMATION ( readBuffer , nBytes ) : <EOL> results = [ ] <EOL> while nBytes > <NUM_LIT:0> : <EOL> fni = ctypes . cast ( readBuffer , LPFNI ) [ <NUM_LIT:0> ] <EOL> ptr = ctypes . addressof ( fni ) + FILE_NOTIFY_INFORMATION . FileName . offset <EOL> filename = ctypes . string_at ( ptr , fni . FileNameLength ) <EOL> results . append ( ( fni . Action , filename . decode ( '<STR_LIT>' ) ) ) <EOL> numToSkip = fni . NextEntryOffset <EOL> if numToSkip <= <NUM_LIT:0> : <EOL> break <EOL> readBuffer = readBuffer [ numToSkip : ] <EOL> nBytes -= numToSkip <EOL> return results <EOL> def get_FILE_NOTIFY_INFORMATION_alt ( event_buffer , nBytes ) : <EOL> """<STR_LIT>""" <EOL> pos = <NUM_LIT:0> <EOL> event_buffer = event_buffer [ : nBytes ] <EOL> while pos < len ( event_buffer ) : <EOL> jump , action , namelen = struct . unpack ( "<STR_LIT>" , event_buffer [ pos : pos + <NUM_LIT:12> ] ) <EOL> name = event_buffer [ pos + <NUM_LIT:12> : pos + <NUM_LIT:12> + namelen ] . decode ( "<STR_LIT>" ) <EOL> yield ( name , action ) <EOL> if not jump : <EOL> break <EOL> pos += jump </s>
