code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def decrypt(self, data, iv=None): '''Decrypts some data in CBC mode.''' if len(data) % self.aes.block_size: raise ValueError('Data is not aligned to block size!') if iv is None: iv = self.iv out = b'' while data: decb = sxor(self.aes.decrypt_block_ecb(data[:0x10]), iv) out += decb iv = data[:0x...
Decrypts some data in CBC mode.
decrypt
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def encrypt(self, data, ctr=None): '''Encrypts some data in CTR mode.''' if ctr is None: ctr = self.ctr return self.aes.encrypt(data)
Encrypts some data in CTR mode.
encrypt
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def get_tweak(self, sector=None): '''Gets tweak for use in XEX.''' if sector is None: sector = self.sector tweak = 0 for i in range(self.block_size): tweak |= (sector & 0xFF) << (i * 8) sector >>= 8 return tweak
Gets tweak for use in XEX.
get_tweak
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def encrypt(self, data): '''Encrypts some data in ECB mode.''' out = b'' while data: out += self.encrypt_block_ecb(data[:0x10]) data = data[0x10:] return out
Encrypts some data in ECB mode.
encrypt
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def decrypt(self, data): '''Decrypts some data in ECB mode.''' if len(data) % self.block_size: raise ValueError('Data is not aligned to block size!') out = b'' while data: out += self.decrypt_block_ecb(data[:0x10]) data = data[0x10:] return out
Decrypts some data in ECB mode.
decrypt
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def send_through_sbox(self, word, sbox=sbox_enc): '''Sends a 32-bit word through an sbox.''' return (sbox[((word & (0xFF << 0x18)) >> 0x18)] << 0x18) | \ (sbox[((word & (0xFF << 0x10)) >> 0x10)] << 0x10) | \ (sbox[((word & (0xFF << 0x08)) >> 0x08)] << 0x08) | \ (sbox[((word & (0xFF << 0x00)) >> 0x...
Sends a 32-bit word through an sbox.
send_through_sbox
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def mix_columns(self, words): '''Performs column mixing for 128-bit AES''' return [self.mix_column(words[0], self.mix_mults), self.mix_column(words[1], self.mix_mults), \ self.mix_column(words[2], self.mix_mults), self.mix_column(words[3], self.mix_mults)]
Performs column mixing for 128-bit AES
mix_columns
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def unmix_columns(self, words): '''Performs column unmixing for 128-bit AES''' return [self.mix_column(words[0], self.unmix_mults), self.mix_column(words[1], self.unmix_mults), \ self.mix_column(words[2], self.unmix_mults), self.mix_column(words[3], self.unmix_mults)]
Performs column unmixing for 128-bit AES
unmix_columns
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def mix_column(self, word, mults): '''Performs column mixing on a single column''' return ((self.mix(word, mults[0])) << 0x18) | \ ((self.mix(word, mults[1])) << 0x10) | \ ((self.mix(word, mults[2])) << 0x08) | \ ((self.mix(word, mults[3])) << 0x00)
Performs column mixing on a single column
mix_column
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def mix(self, word, mix): '''Mixes a word according to a given multiplier.''' return (self.mult_table[mix[0]][((word >> 0x18) & 0xFF)]) ^ \ (self.mult_table[mix[1]][((word >> 0x10) & 0xFF)]) ^ \ (self.mult_table[mix[2]][((word >> 0x08) & 0xFF)]) ^ \ (self.mult_table[mix[3]][((word >> 0x00) & 0xFF)]) & ...
Mixes a word according to a given multiplier.
mix
python
julesontheroad/NSC_BUILDER
py/ztools/lib/aes128.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/aes128.py
MIT
def register_node(self, address): """ Add a new node to the list of nodes :param address: Address of node. Eg. 'http://192.168.0.5:5000' """ parsed_url = urlparse(address) if parsed_url.netloc: self.nodes.add(parsed_url.netloc) elif parsed_url.path: # Accepts an URL without scheme like '192.168.0....
Add a new node to the list of nodes :param address: Address of node. Eg. 'http://192.168.0.5:5000'
register_node
python
julesontheroad/NSC_BUILDER
py/ztools/lib/blockchain.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/blockchain.py
MIT
def valid_chain(self, chain): """ Determine if a given blockchain is valid :param chain: A blockchain :return: True if valid, False if not """ last_block = chain[0] current_index = 1 while current_index < len(chain): block = chain[current_index] print(f'{last_block}') print(f'{block}') pr...
Determine if a given blockchain is valid :param chain: A blockchain :return: True if valid, False if not
valid_chain
python
julesontheroad/NSC_BUILDER
py/ztools/lib/blockchain.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/blockchain.py
MIT
def resolve_conflicts(self): """ This is our consensus algorithm, it resolves conflicts by replacing our chain with the longest one in the network. :return: True if our chain was replaced, False if not """ neighbours = self.nodes new_chain = None max_length = len(self.chain) for node in neighbours...
This is our consensus algorithm, it resolves conflicts by replacing our chain with the longest one in the network. :return: True if our chain was replaced, False if not
resolve_conflicts
python
julesontheroad/NSC_BUILDER
py/ztools/lib/blockchain.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/blockchain.py
MIT
def chain_streams(streams, buffer_size=io.DEFAULT_BUFFER_SIZE): """ Chain an iterable of streams together into a single buffered stream. Usage: def generate_open_file_streams(): for file in filenames: yield open(file, 'rb') f = chain_streams(generate_open_file_streams()) f.read() """ class ChainStrea...
Chain an iterable of streams together into a single buffered stream. Usage: def generate_open_file_streams(): for file in filenames: yield open(file, 'rb') f = chain_streams(generate_open_file_streams()) f.read()
chain_streams
python
julesontheroad/NSC_BUILDER
py/ztools/lib/File_chunk.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/File_chunk.py
MIT
def get_selected(self): """return the current selected option as a tuple: (option, index) or as a list of tuples (in case multi_select==True) """ if self.multi_select: return_tuples = [] for selected in self.all_selected: return_tuples.append((s...
return the current selected option as a tuple: (option, index) or as a list of tuples (in case multi_select==True)
get_selected
python
julesontheroad/NSC_BUILDER
py/ztools/lib/python_pick.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/python_pick.py
MIT
def draw(self): """draw the curses ui on the screen, handle scroll if needed""" self.screen.clear() x, y = 1, 1 # start point max_y, max_x = self.screen.getmaxyx() max_rows = max_y - y # the max rows we can draw lines, current_line = self.get_lines() # calcul...
draw the curses ui on the screen, handle scroll if needed
draw
python
julesontheroad/NSC_BUILDER
py/ztools/lib/python_pick.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/python_pick.py
MIT
def gen_nsp_header(files,fileSizes): ''' for i in range(len(files)): print (files[i]) print (fileSizes[i]) ''' filesNb = len(files) stringTable = '\x00'.join(str(nca) for nca in files) headerSize = 0x10 + (filesNb)*0x18 + len(stringTable) remainder = 0x10 - headerSize%0x10 headerSize += remainder fileOffse...
for i in range(len(files)): print (files[i]) print (fileSizes[i])
gen_nsp_header
python
julesontheroad/NSC_BUILDER
py/ztools/lib/sq_tools.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/lib/sq_tools.py
MIT
def sendCommand(self, code, args): """Send a PTP/MTP command without data phase""" params = self._initInitialCommand(WPD_COMMAND_MTP_EXT_EXECUTE_COMMAND_WITHOUT_DATA_PHASE, code, args) result = self._send(params) return self._getResponse(result)
Send a PTP/MTP command without data phase
sendCommand
python
julesontheroad/NSC_BUILDER
py/ztools/mtp/wpd.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/mtp/wpd.py
MIT
def sendWriteCommand(self, code, args, data): """Send a PTP/MTP command with write data phase""" params = self._initInitialCommand(WPD_COMMAND_MTP_EXT_EXECUTE_COMMAND_WITH_DATA_TO_WRITE, code, args) params.SetUnsignedLargeIntegerValue(WPD_PROPERTY_MTP_EXT_TRANSFER_TOTAL_DATA_SIZE, len(data)) result = self._send...
Send a PTP/MTP command with write data phase
sendWriteCommand
python
julesontheroad/NSC_BUILDER
py/ztools/mtp/wpd.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/mtp/wpd.py
MIT
def sendReadCommand(self, code, args): """Send a PTP/MTP command with read data phase""" params = self._initInitialCommand(WPD_COMMAND_MTP_EXT_EXECUTE_COMMAND_WITH_DATA_TO_READ, code, args) result = self._send(params) context = self._getContext(result) length = result.GetUnsignedIntegerValue(cast(WPD_PROPERTY...
Send a PTP/MTP command with read data phase
sendReadCommand
python
julesontheroad/NSC_BUILDER
py/ztools/mtp/wpd.py
https://github.com/julesontheroad/NSC_BUILDER/blob/master/py/ztools/mtp/wpd.py
MIT
def on_any_event(self, event: FileSystemEvent) -> None: """Catch-all event handler. :param event: The event object representing the file system event. :type event: :class:`FileSystemEvent` """
Catch-all event handler. :param event: The event object representing the file system event. :type event: :class:`FileSystemEvent`
on_any_event
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_moved(self, event: DirMovedEvent | FileMovedEvent) -> None: """Called when a file or a directory is moved or renamed. :param event: Event representing file/directory movement. :type event: :class:`DirMovedEvent` or :class:`FileMovedEvent` """
Called when a file or a directory is moved or renamed. :param event: Event representing file/directory movement. :type event: :class:`DirMovedEvent` or :class:`FileMovedEvent`
on_moved
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_created(self, event: DirCreatedEvent | FileCreatedEvent) -> None: """Called when a file or directory is created. :param event: Event representing file/directory creation. :type event: :class:`DirCreatedEvent` or :class:`FileCreatedEvent` """
Called when a file or directory is created. :param event: Event representing file/directory creation. :type event: :class:`DirCreatedEvent` or :class:`FileCreatedEvent`
on_created
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_deleted(self, event: DirDeletedEvent | FileDeletedEvent) -> None: """Called when a file or directory is deleted. :param event: Event representing file/directory deletion. :type event: :class:`DirDeletedEvent` or :class:`FileDeletedEvent` """
Called when a file or directory is deleted. :param event: Event representing file/directory deletion. :type event: :class:`DirDeletedEvent` or :class:`FileDeletedEvent`
on_deleted
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_modified(self, event: DirModifiedEvent | FileModifiedEvent) -> None: """Called when a file or directory is modified. :param event: Event representing file/directory modification. :type event: :class:`DirModifiedEvent` or :class:`FileModifiedEvent` """
Called when a file or directory is modified. :param event: Event representing file/directory modification. :type event: :class:`DirModifiedEvent` or :class:`FileModifiedEvent`
on_modified
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_closed(self, event: FileClosedEvent) -> None: """Called when a file opened for writing is closed. :param event: Event representing file closing. :type event: :class:`FileClosedEvent` """
Called when a file opened for writing is closed. :param event: Event representing file closing. :type event: :class:`FileClosedEvent`
on_closed
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_closed_no_write(self, event: FileClosedNoWriteEvent) -> None: """Called when a file opened for reading is closed. :param event: Event representing file closing. :type event: :class:`FileClosedNoWriteEvent` """
Called when a file opened for reading is closed. :param event: Event representing file closing. :type event: :class:`FileClosedNoWriteEvent`
on_closed_no_write
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def on_opened(self, event: FileOpenedEvent) -> None: """Called when a file is opened. :param event: Event representing file opening. :type event: :class:`FileOpenedEvent` """
Called when a file is opened. :param event: Event representing file opening. :type event: :class:`FileOpenedEvent`
on_opened
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def dispatch(self, event: FileSystemEvent) -> None: """Dispatches events to the appropriate methods. :param event: The event object representing the file system event. :type event: :class:`FileSystemEvent` """ if self.ignore_directories and event.is_direc...
Dispatches events to the appropriate methods. :param event: The event object representing the file system event. :type event: :class:`FileSystemEvent`
dispatch
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def generate_sub_moved_events( src_dir_path: bytes | str, dest_dir_path: bytes | str, ) -> Generator[DirMovedEvent | FileMovedEvent]: """Generates an event list of :class:`DirMovedEvent` and :class:`FileMovedEvent` objects for all the files and directories within the given moved directory that were ...
Generates an event list of :class:`DirMovedEvent` and :class:`FileMovedEvent` objects for all the files and directories within the given moved directory that were moved along with the directory. :param src_dir_path: The source path of the moved directory. :param dest_dir_path: The desti...
generate_sub_moved_events
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def generate_sub_created_events(src_dir_path: bytes | str) -> Generator[DirCreatedEvent | FileCreatedEvent]: """Generates an event list of :class:`DirCreatedEvent` and :class:`FileCreatedEvent` objects for all the files and directories within the given moved directory that were moved along with the director...
Generates an event list of :class:`DirCreatedEvent` and :class:`FileCreatedEvent` objects for all the files and directories within the given moved directory that were moved along with the directory. :param src_dir_path: The source path of the created directory. :returns: An iterable of ...
generate_sub_created_events
python
gorakhargosh/watchdog
src/watchdog/events.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/events.py
Apache-2.0
def command( args: list[Argument], *, parent: _SubParsersAction[ArgumentParser] = subparsers, cmd_aliases: list[str] | None = None, ) -> Callable: """Decorator to define a new command in a sanity-preserving way. The function will be stored in the ``func`` variable when the parser parses argu...
Decorator to define a new command in a sanity-preserving way. The function will be stored in the ``func`` variable when the parser parses arguments so that it can be called directly like so:: >>> args = cli.parse_args() >>> args.func(args)
command
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def load_config(tricks_file_pathname: str) -> dict: """Loads the YAML configuration from the specified file. :param tricks_file_path: The path to the tricks configuration file. :returns: A dictionary of configuration information. """ import yaml with open(tricks_file_pathname, ...
Loads the YAML configuration from the specified file. :param tricks_file_path: The path to the tricks configuration file. :returns: A dictionary of configuration information.
load_config
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def parse_patterns( patterns_spec: str, ignore_patterns_spec: str, *, separator: str = ";" ) -> tuple[list[str], list[str]]: """Parses pattern argument specs and returns a two-tuple of (patterns, ignore_patterns). """ patterns = patterns_spec.split(separator) ignore_patterns = ignore_patterns_sp...
Parses pattern argument specs and returns a two-tuple of (patterns, ignore_patterns).
parse_patterns
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def observe_with( observer: BaseObserver, event_handler: FileSystemEventHandler, pathnames: list[str], *, recursive: bool, ) -> None: """Single observer thread with a scheduled path and event handler. :param observer: The observer thread. :param event_handler: Event hand...
Single observer thread with a scheduled path and event handler. :param observer: The observer thread. :param event_handler: Event handler which will be called in response to file system events. :param pathnames: A list of pathnames to monitor. :param recursive: ``True`` ...
observe_with
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def schedule_tricks(observer: BaseObserver, tricks: list[dict], pathname: str, *, recursive: bool) -> None: """Schedules tricks with the specified observer and for the given watch path. :param observer: The observer thread into which to schedule the trick and watch. :param tricks: A lis...
Schedules tricks with the specified observer and for the given watch path. :param observer: The observer thread into which to schedule the trick and watch. :param tricks: A list of tricks. :param pathname: A path name which should be watched. :param recursive: ``True...
schedule_tricks
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def tricks_from(args: Namespace) -> None: """Command to execute tricks from a tricks configuration file.""" observer_cls: ObserverType if args.debug_force_polling: from watchdog.observers.polling import PollingObserver observer_cls = PollingObserver elif args.debug_force_kqueue: ...
Command to execute tricks from a tricks configuration file.
tricks_from
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def tricks_generate_yaml(args: Namespace) -> None: """Command to generate Yaml configuration for tricks named on the command line.""" import yaml python_paths = path_split(args.python_path) add_to_sys_path(python_paths) output = StringIO() for trick_path in args.trick_paths: trick_cls ...
Command to generate Yaml configuration for tricks named on the command line.
tricks_generate_yaml
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def log(args: Namespace) -> None: """Command to log file system events to the console.""" from watchdog.tricks import LoggerTrick patterns, ignore_patterns = parse_patterns(args.patterns, args.ignore_patterns) handler = LoggerTrick( patterns=patterns, ignore_patterns=ignore_patterns, ...
Command to log file system events to the console.
log
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def shell_command(args: Namespace) -> None: """Command to execute shell commands in response to file system events.""" from watchdog.tricks import ShellCommandTrick if not args.command: args.command = None observer_cls: ObserverType if args.debug_force_polling: from watchdog.observ...
Command to execute shell commands in response to file system events.
shell_command
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def auto_restart(args: Namespace) -> None: """Command to start a long-running subprocess and restart it on matched events.""" observer_cls: ObserverType if args.debug_force_polling: from watchdog.observers.polling import PollingObserver observer_cls = PollingObserver else: from ...
Command to start a long-running subprocess and restart it on matched events.
auto_restart
python
gorakhargosh/watchdog
src/watchdog/watchmedo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py
Apache-2.0
def queue_events(self, timeout: float) -> None: """Override this method to populate the event queue with events per interval period. :param timeout: Timeout (in seconds) between successive attempts at reading events. :type timeout: ``float`` "...
Override this method to populate the event queue with events per interval period. :param timeout: Timeout (in seconds) between successive attempts at reading events. :type timeout: ``float``
queue_events
python
gorakhargosh/watchdog
src/watchdog/observers/api.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/api.py
Apache-2.0
def dispatch_events(self, event_queue: EventQueue) -> None: """Override this method to consume events from an event queue, blocking on the queue for the specified timeout before raising :class:`queue.Empty`. :param event_queue: Event queue to populate with one set of events. ...
Override this method to consume events from an event queue, blocking on the queue for the specified timeout before raising :class:`queue.Empty`. :param event_queue: Event queue to populate with one set of events. :type event_queue: :class:`EventQueue` :raises: ...
dispatch_events
python
gorakhargosh/watchdog
src/watchdog/observers/api.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/api.py
Apache-2.0
def unschedule(self, watch: ObservedWatch) -> None: """Unschedules a watch. :param watch: The watch to unschedule. :type watch: An instance of :class:`ObservedWatch` or a subclass of :class:`ObservedWatch` """ with self._lock: emit...
Unschedules a watch. :param watch: The watch to unschedule. :type watch: An instance of :class:`ObservedWatch` or a subclass of :class:`ObservedWatch`
unschedule
python
gorakhargosh/watchdog
src/watchdog/observers/api.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/api.py
Apache-2.0
def unschedule_all(self) -> None: """Unschedules all watches and detaches all associated event handlers.""" with self._lock: self._handlers.clear() self._clear_emitters() self._watches.clear()
Unschedules all watches and detaches all associated event handlers.
unschedule_all
python
gorakhargosh/watchdog
src/watchdog/observers/api.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/api.py
Apache-2.0
def events_callback(self, paths: list[bytes], inodes: list[int], flags: list[int], ids: list[int]) -> None: """Callback passed to FSEventStreamCreate(), it will receive all FS events and queue them. """ cls = _fsevents.NativeEvent try: events = [ cls(p...
Callback passed to FSEventStreamCreate(), it will receive all FS events and queue them.
events_callback
python
gorakhargosh/watchdog
src/watchdog/observers/fsevents.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/fsevents.py
Apache-2.0
def _source_for_move(self, cookie: int) -> bytes | None: """The source path corresponding to the given MOVED_TO event. If the source path is outside the monitored directories, None is returned instead. """ src_event = self._move_event_grouper.get_queued_moved_from_event(cookie) ...
The source path corresponding to the given MOVED_TO event. If the source path is outside the monitored directories, None is returned instead.
_source_for_move
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def on_watch_deleted(self, wd: WatchDescriptor) -> None: """Called when a watch that ths callback is registered at is removed. This is the case when the watched object is deleted.""" with self._lock: if not self.is_active: return self._remove_watch_interna...
Called when a watch that ths callback is registered at is removed. This is the case when the watched object is deleted.
on_watch_deleted
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def on_event(self, event: InotifyEvent) -> None: """called for every event for each watch this callback is registered at.""" with self._lock: if not self.is_active: return src_path = self._build_event_source_path(event) if src_path is None: ...
called for every event for each watch this callback is registered at.
on_event
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _activate(self) -> None: """Adds a watch (optionally recursively) for the given directory path to monitor events specified by the mask. """ with self._lock: if self.is_active: # maybe wwe can remove this check... return self._add_all_callback...
Adds a watch (optionally recursively) for the given directory path to monitor events specified by the mask.
_activate
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _move_watches(self, move_src_path: bytes, move_dst_path: bytes) -> None: """moves all watches that are inside the directory move_src_path to move_dst_path""" moved_watch = self._active_callbacks_by_path.pop(move_src_path, None) if moved_watch is not None: self._active_callbacks_b...
moves all watches that are inside the directory move_src_path to move_dst_path
_move_watches
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _add_all_callbacks(self, path: bytes) -> None: """Adds a watch (optionally recursively) for the given directory path to monitor events specified by the mask. :param path: Path to monitor """ is_dir = os.path.isdir(path) self._add_callback(path) if...
Adds a watch (optionally recursively) for the given directory path to monitor events specified by the mask. :param path: Path to monitor
_add_all_callbacks
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _add_callback(self, path: bytes) -> None: """Adds a callback for the given path to monitor events specified by the mask. :param path: Path to monitor """ with contextlib.suppress(OSError): wd = self._inotify_fd.add_callback(path, self.event_mask, self...
Adds a callback for the given path to monitor events specified by the mask. :param path: Path to monitor
_add_callback
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _remove_callbacks(self, wds: list[WatchDescriptor]) -> None: """removes callbacks for the given paths. :param wds: a list of WatchDescriptors """ self._inotify_fd.remove_callbacks([(wd, self._id) for wd in wds]) for wd in wds: self._remove_watch_inter...
removes callbacks for the given paths. :param wds: a list of WatchDescriptors
_remove_callbacks
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _remove_watch_internally(self, wd: WatchDescriptor) -> None: """Removes a watch descriptor from internal dicts.""" path = self._active_callbacks_by_watch.pop(wd) wd2 = self._active_callbacks_by_path.pop(path) if wd2 != wd: # Oops. The path already belongs to a different w...
Removes a watch descriptor from internal dicts.
_remove_watch_internally
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def _select_event_type( dir_event: type[FileSystemEvent], file_event: type[FileSystemEvent], *, is_directory: bool, ) -> FileSystemEventCtor: """selects the correct FileSystemEvent Type based on `is_directory` and returns it.""" return cast(FileSystemEventCtor, dir_event if is_directory else fil...
selects the correct FileSystemEvent Type based on `is_directory` and returns it.
_select_event_type
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def get_event_mask_from_filter(self) -> Mask: """Optimization: Only include events we are filtering in inotify call.""" if self._event_filter is None: return WATCHDOG_ALL_EVENTS # Always listen to delete self event_mask = InotifyConstants.IN_DELETE_SELF for cls in s...
Optimization: Only include events we are filtering in inotify call.
get_event_mask_from_filter
python
gorakhargosh/watchdog
src/watchdog/observers/inotify.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify.py
Apache-2.0
def get_instance(cls) -> InotifyFD: """Use this class method to get a running InotifyFD instance.""" with cls._global_lock: # enforce that InotifyFD is a singleton. if cls._instance is None: cls._instance = InotifyFD() cls._instance.start() ...
Use this class method to get a running InotifyFD instance.
get_instance
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def add_callback(self, path: bytes, mask: Mask, callback: WatchCallback, id_: CallbackId) -> WatchDescriptor: """Adds a callback for the given path to monitor events specified by the mask. If a watch already exists for the given path, it is reused. If a callback with the given id_ already exists...
Adds a callback for the given path to monitor events specified by the mask. If a watch already exists for the given path, it is reused. If a callback with the given id_ already exists for this watch, it is overwritten and a warning is generated. :param path: Path to begin monitoring...
add_callback
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def remove_callbacks(self, callbacks: list[tuple[WatchDescriptor, CallbackId]]) -> None: """Removes callbacks from WatchDescriptors. If a callback was the last callback on a watch, the watch is removed. Otherwise, just the callback is removed from the watch. If no watch for a given Watc...
Removes callbacks from WatchDescriptors. If a callback was the last callback on a watch, the watch is removed. Otherwise, just the callback is removed from the watch. If no watch for a given WatchDescriptor exists or no callback with the given id_ for the watch exists, a warning is gene...
remove_callbacks
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def run(self) -> None: """Read events from `inotify` and handle them.""" while self.should_keep_running(): inotify_events = self.read_events() for event in inotify_events: self.handle_event(event)
Read events from `inotify` and handle them.
run
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def close(self) -> None: """Closes the inotify instance and removes all associated watches.""" delete_callbacks = [] with self._lock: if not self._closed: self._closed = True for wd in self._watch_for_wd.copy(): inotify_rm_watch(sel...
Closes the inotify instance and removes all associated watches.
close
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def read_events(self, *, event_buffer_size: int = DEFAULT_EVENT_BUFFER_SIZE) -> list[InotifyEvent]: """ Reads events from inotify and yields them. All appropriate exiting watches are automatically moved when a move event occurs. """ event_buffer = self._read_event_buffer(event_bu...
Reads events from inotify and yields them. All appropriate exiting watches are automatically moved when a move event occurs.
read_events
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def _check_inotify_fd(self) -> bool: """return true if we can read _inotify_fd without blocking""" if self._poller is not None: return any(fd == self._inotify_fd for fd, _ in self._poller.poll()) result = select.select([self._inotify_fd, self._kill_r], [], []) return self._i...
return true if we can read _inotify_fd without blocking
_check_inotify_fd
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def _read_event_buffer(self, event_buffer_size: int) -> bytes: """ Reads from inotify and returns what was read. If inotify got closed or if an errno.EBADF occurred during reading, None is returned. """ event_buffer = b"" while True: try: with ...
Reads from inotify and returns what was read. If inotify got closed or if an errno.EBADF occurred during reading, None is returned.
_read_event_buffer
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def _get_or_create_watch(self, path: bytes, mask: Mask) -> Watch: """Creates a watch for the given path to monitor events specified by the mask. :param path: Path to monitor :param mask: Event bit mask. """ # returns an existing watch descriptor, ...
Creates a watch for the given path to monitor events specified by the mask. :param path: Path to monitor :param mask: Event bit mask.
_get_or_create_watch
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def _remove_callback(self, wd: WatchDescriptor, id_: CallbackId) -> None: """Removes a callback for the given WatchDescriptor. If it was the last callback on the watch, the watch is removed. Otherwise, just the callback is removed from the watch. If no watch for the given WatchDescriptor...
Removes a callback for the given WatchDescriptor. If it was the last callback on the watch, the watch is removed. Otherwise, just the callback is removed from the watch. If no watch for the given WatchDescriptor exists or no callback with the given id_ for the watch exists, a warning is ...
_remove_callback
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def _remove_watch(self, wd: WatchDescriptor) -> Sequence[WatchCallback]: """Notifies all necessary objects of deleted watches and cleans up book-keeping. This does NOT call inotify_rm_watch.""" watch = self._watch_for_wd.pop(wd, None) return list(watch.callbacks.values()) if watch is not...
Notifies all necessary objects of deleted watches and cleans up book-keeping. This does NOT call inotify_rm_watch.
_remove_watch
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def _parse_event_buffer(event_buffer: bytes) -> Generator[tuple[WatchDescriptor, Mask, int, bytes]]: """Parses an event buffer of ``inotify_event`` structs returned by inotify:: struct inotify_event { __s32 wd; /* watch descriptor */ __u32 mask; ...
Parses an event buffer of ``inotify_event`` structs returned by inotify:: struct inotify_event { __s32 wd; /* watch descriptor */ __u32 mask; /* watch mask */ __u32 cookie; /* cookie to synchronize two events */ ...
_parse_event_buffer
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_c.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_c.py
Apache-2.0
def put_event(self, event: PathedInotifyEvent) -> None: """Add an event to the `queue`. When adding an IN_MOVE_TO event, remove the previous added matching IN_MOVE_FROM event and add them back to the queue as a tuple. """ logger.debug("in-event %s", event) # Only add dela...
Add an event to the `queue`. When adding an IN_MOVE_TO event, remove the previous added matching IN_MOVE_FROM event and add them back to the queue as a tuple.
put_event
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_move_event_grouper.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_move_event_grouper.py
Apache-2.0
def _group_moved_to_event(self, to_event: PathedInotifyEvent) -> GroupedInotifyEvent: """Group any matching move events by checking if a matching move_from is in delay queue already and removing it""" cookie = to_event.ev.cookie def matching_from_event(event: GroupedInotifyEvent) -> boo...
Group any matching move events by checking if a matching move_from is in delay queue already and removing it
_group_moved_to_event
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_move_event_grouper.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_move_event_grouper.py
Apache-2.0
def get_queued_moved_from_event(self, cookie: int) -> PathedInotifyEvent | None: """Finds a queued IN_MOVED_FROM event with the give cookie, but does not remove it.""" def matching_from_event(event: GroupedInotifyEvent) -> bool: return isinstance(event, PathedInotifyEvent) and event...
Finds a queued IN_MOVED_FROM event with the give cookie, but does not remove it.
get_queued_moved_from_event
python
gorakhargosh/watchdog
src/watchdog/observers/inotify_move_event_grouper.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/inotify_move_event_grouper.py
Apache-2.0
def is_modified(kev: select.kevent) -> bool: """Determines whether the given kevent represents modification.""" fflags = kev.fflags return (fflags & select.KQ_NOTE_EXTEND > 0) or (fflags & select.KQ_NOTE_WRITE > 0)
Determines whether the given kevent represents modification.
is_modified
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def get(self, path: bytes | str) -> KeventDescriptor: """Obtains a :class:`KeventDescriptor` object for the specified path. :param path: Path for which the descriptor will be obtained. """ with self._lock: path = absolute_path(path) return self._get(p...
Obtains a :class:`KeventDescriptor` object for the specified path. :param path: Path for which the descriptor will be obtained.
get
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def __contains__(self, path: bytes | str) -> bool: """Determines whether a :class:`KeventDescriptor has been registered for the specified path. :param path: Path for which the descriptor will be obtained. """ with self._lock: path = absolute_path(path) ...
Determines whether a :class:`KeventDescriptor has been registered for the specified path. :param path: Path for which the descriptor will be obtained.
__contains__
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def add(self, path: bytes | str, *, is_directory: bool) -> None: """Adds a :class:`KeventDescriptor` to the collection for the given path. :param path: The path for which a :class:`KeventDescriptor` object will be added. :param is_directory: ``True`` ...
Adds a :class:`KeventDescriptor` to the collection for the given path. :param path: The path for which a :class:`KeventDescriptor` object will be added. :param is_directory: ``True`` if the path refers to a directory; ``False`` otherwise. :type is_dir...
add
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def remove(self, path: bytes | str) -> None: """Removes the :class:`KeventDescriptor` object for the given path if it already exists. :param path: Path for which the :class:`KeventDescriptor` object will be removed. """ with self._lock: path =...
Removes the :class:`KeventDescriptor` object for the given path if it already exists. :param path: Path for which the :class:`KeventDescriptor` object will be removed.
remove
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def clear(self) -> None: """Clears the collection and closes all open descriptors.""" with self._lock: for descriptor in self._descriptors: descriptor.close() self._descriptors.clear() self._descriptor_for_fd.clear() self._descriptor_for_pa...
Clears the collection and closes all open descriptors.
clear
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def _add_descriptor(self, descriptor: KeventDescriptor) -> None: """Adds a descriptor to the collection. :param descriptor: An instance of :class:`KeventDescriptor` to be added. """ self._descriptors.add(descriptor) self._kevents.append(descriptor.kevent) sel...
Adds a descriptor to the collection. :param descriptor: An instance of :class:`KeventDescriptor` to be added.
_add_descriptor
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def _remove_descriptor(self, descriptor: KeventDescriptor) -> None: """Removes a descriptor from the collection. :param descriptor: An instance of :class:`KeventDescriptor` to be removed. """ self._descriptors.remove(descriptor) del self._descriptor_for_fd[descriptor...
Removes a descriptor from the collection. :param descriptor: An instance of :class:`KeventDescriptor` to be removed.
_remove_descriptor
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def _register_kevent(self, path: bytes | str, *, is_directory: bool) -> None: """Registers a kevent descriptor for the given path. :param path: Path for which a kevent descriptor will be created. :param is_directory: ``True`` if the path refers to a directory; ``False`` ...
Registers a kevent descriptor for the given path. :param path: Path for which a kevent descriptor will be created. :param is_directory: ``True`` if the path refers to a directory; ``False`` otherwise. :type is_directory: ``bool``
_register_kevent
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def queue_event(self, event: FileSystemEvent) -> None: """Handles queueing a single event object. :param event: An instance of :class:`watchdog.events.FileSystemEvent` or a subclass. """ # Handles all the book keeping for queued events. # We do not need t...
Handles queueing a single event object. :param event: An instance of :class:`watchdog.events.FileSystemEvent` or a subclass.
queue_event
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def _gen_kqueue_events( self, kev: select.kevent, ref_snapshot: DirectorySnapshot, new_snapshot: DirectorySnapshot ) -> Generator[FileSystemEvent]: """Generate events from the kevent list returned from the call to :meth:`select.kqueue.control`. .. NOTE:: kqueue only tells us about d...
Generate events from the kevent list returned from the call to :meth:`select.kqueue.control`. .. NOTE:: kqueue only tells us about deletions, file modifications, attribute modifications. The other events, namely, file creation, directory modification, file rename, ...
_gen_kqueue_events
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def _gen_renamed_events( self, src_path: bytes | str, ref_snapshot: DirectorySnapshot, new_snapshot: DirectorySnapshot, *, is_directory: bool, ) -> Generator[FileSystemEvent]: """Compares information from two directory snapshots (one taken before the r...
Compares information from two directory snapshots (one taken before the rename operation and another taken right after) to determine the destination path of the file system object renamed, and yields the appropriate events to be queued.
_gen_renamed_events
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def queue_events(self, timeout: float) -> None: """Queues events by reading them from a call to the blocking :meth:`select.kqueue.control()` method. :param timeout: Blocking timeout for reading events. :type timeout: ``float`` (seconds) """ with s...
Queues events by reading them from a call to the blocking :meth:`select.kqueue.control()` method. :param timeout: Blocking timeout for reading events. :type timeout: ``float`` (seconds)
queue_events
python
gorakhargosh/watchdog
src/watchdog/observers/kqueue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py
Apache-2.0
def __init__( self, stat: Callable[[str], os.stat_result], listdir: Callable[[str | None], Iterator[os.DirEntry]], *, polling_interval: int = 1, ) -> None: """:param stat: stat function. See ``os.stat`` for details. :param listdir: listdir function. See ``os.s...
:param stat: stat function. See ``os.stat`` for details. :param listdir: listdir function. See ``os.scandir`` for details. :type polling_interval: int :param polling_interval: interval in seconds between polling the file system.
__init__
python
gorakhargosh/watchdog
src/watchdog/observers/polling.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/polling.py
Apache-2.0
def get_directory_handle(path: str) -> HANDLE: """Returns a Windows handle to the specified directory path.""" return CreateFileW( path, FILE_LIST_DIRECTORY, WATCHDOG_FILE_SHARE_FLAGS, None, OPEN_EXISTING, WATCHDOG_FILE_FLAGS, None, )
Returns a Windows handle to the specified directory path.
get_directory_handle
python
gorakhargosh/watchdog
src/watchdog/observers/winapi.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/winapi.py
Apache-2.0
def read_directory_changes(handle: HANDLE, path: str, *, recursive: bool) -> tuple[bytes, int]: """Read changes to the directory using the specified directory handle. https://timgolden.me.uk/pywin32-docs/win32file__ReadDirectoryChangesW_meth.html """ event_buffer = ctypes.create_string_buffer(BUFFER_SI...
Read changes to the directory using the specified directory handle. https://timgolden.me.uk/pywin32-docs/win32file__ReadDirectoryChangesW_meth.html
read_directory_changes
python
gorakhargosh/watchdog
src/watchdog/observers/winapi.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/winapi.py
Apache-2.0
def translate(pat, *, recursive=False, include_hidden=False, seps=None): """Translate a pathname with shell wildcards to a regular expression. If `recursive` is true, the pattern segment '**' will match any number of path segments. If `include_hidden` is true, wildcards can match path segments beginni...
Translate a pathname with shell wildcards to a regular expression. If `recursive` is true, the pattern segment '**' will match any number of path segments. If `include_hidden` is true, wildcards can match path segments beginning with a dot ('.'). If a sequence of separator characters is given to ...
translate
python
gorakhargosh/watchdog
src/watchdog/utils/backwards_compat.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/backwards_compat.py
Apache-2.0
def put(self, item: Any, block: bool = True, timeout: float | None = None) -> None: # noqa: FBT001,FBT002 """This method will be used by `eventlet`, when enabled, so we cannot use force proper keyword-only arguments nor touch the signature. Also, the `timeout` argument will be ignored in that case. ...
This method will be used by `eventlet`, when enabled, so we cannot use force proper keyword-only arguments nor touch the signature. Also, the `timeout` argument will be ignored in that case.
put
python
gorakhargosh/watchdog
src/watchdog/utils/bricks.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/bricks.py
Apache-2.0
def close(self) -> None: """Close queue, indicating no more items will be added.""" self._closed = True # Interrupt the blocking _not_empty.wait() call in get self._not_empty.acquire() self._not_empty.notify() self._not_empty.release()
Close queue, indicating no more items will be added.
close
python
gorakhargosh/watchdog
src/watchdog/utils/delayed_queue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/delayed_queue.py
Apache-2.0
def get(self) -> T | None: """Remove and return an element from the queue, or this queue has been closed raise the Closed exception. """ while True: # wait for element to be added to queue self._not_empty.acquire() while len(self._queue) == 0 and not s...
Remove and return an element from the queue, or this queue has been closed raise the Closed exception.
get
python
gorakhargosh/watchdog
src/watchdog/utils/delayed_queue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/delayed_queue.py
Apache-2.0
def find(self, predicate: Callable[[T], bool]) -> T | None: """return the first item for which predicate is True, ignoring delay. """ with self._lock: i_item = self._index_and_item(predicate) return i_item[1] if i_item is not None else None
return the first item for which predicate is True, ignoring delay.
find
python
gorakhargosh/watchdog
src/watchdog/utils/delayed_queue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/delayed_queue.py
Apache-2.0
def remove(self, predicate: Callable[[T], bool]) -> T | None: """Remove and return the first item for which predicate is True, ignoring delay. """ with self._lock: i_item = self._index_and_item(predicate) if i_item is not None: del self._queue[i_it...
Remove and return the first item for which predicate is True, ignoring delay.
remove
python
gorakhargosh/watchdog
src/watchdog/utils/delayed_queue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/delayed_queue.py
Apache-2.0
def _index_and_item(self, predicate: Callable[[T], bool]) -> tuple[int, T] | None: """Return the index and value of the first item for which predicate is True, ignoring delay. Returns -1 if nothing is found. Requires a lock. """ for i, (elem, *_) in enumerate(self._queue): if...
Return the index and value of the first item for which predicate is True, ignoring delay. Returns -1 if nothing is found. Requires a lock.
_index_and_item
python
gorakhargosh/watchdog
src/watchdog/utils/delayed_queue.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/delayed_queue.py
Apache-2.0
def echo(fn: Callable, write: Callable[[str], int | None] = sys.stdout.write) -> Callable: """Echo calls to a function. Returns a decorated version of the input function which "echoes" calls made to it by writing out the function's name and the arguments it was called with. """ # Unpack functio...
Echo calls to a function. Returns a decorated version of the input function which "echoes" calls made to it by writing out the function's name and the arguments it was called with.
echo
python
gorakhargosh/watchdog
src/watchdog/utils/echo.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/echo.py
Apache-2.0
def _get_sep(path: PurePath) -> str: """ Python < 3.13 doesn't have a clean way to expose the path separator It's either this, or make use of `path._flavour.sep` """ if isinstance(path, PureWindowsPath): return "\\" if isinstance(path, PurePosixPath): return "/" raise TypeErr...
Python < 3.13 doesn't have a clean way to expose the path separator It's either this, or make use of `path._flavour.sep`
_get_sep
python
gorakhargosh/watchdog
src/watchdog/utils/patterns.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/patterns.py
Apache-2.0
def _match_path( raw_path: str, included_patterns: set[str], excluded_patterns: set[str], *, case_sensitive: bool, ) -> bool: """Internal function same as :func:`match_path` but does not check arguments.""" path: PurePosixPath | PureWindowsPath if case_sensitive: path = PurePosix...
Internal function same as :func:`match_path` but does not check arguments.
_match_path
python
gorakhargosh/watchdog
src/watchdog/utils/patterns.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/patterns.py
Apache-2.0
def filter_paths( paths: list[str], *, included_patterns: list[str] | None = None, excluded_patterns: list[str] | None = None, case_sensitive: bool = True, ) -> Iterator[str]: """Filters from a set of paths based on acceptable patterns and ignorable patterns. :param paths: A list...
Filters from a set of paths based on acceptable patterns and ignorable patterns. :param paths: A list of path names that will be filtered based on matching and ignored patterns. :param included_patterns: Allow filenames matching wildcard patterns specified in this list. If no...
filter_paths
python
gorakhargosh/watchdog
src/watchdog/utils/patterns.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/patterns.py
Apache-2.0
def match_any_paths( paths: list[str], *, included_patterns: list[str] | None = None, excluded_patterns: list[str] | None = None, case_sensitive: bool = True, ) -> bool: """Matches from a set of paths based on acceptable patterns and ignorable patterns. See ``filter_paths()`` for signatu...
Matches from a set of paths based on acceptable patterns and ignorable patterns. See ``filter_paths()`` for signature details.
match_any_paths
python
gorakhargosh/watchdog
src/watchdog/utils/patterns.py
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/patterns.py
Apache-2.0