diff --git a/.gitattributes b/.gitattributes index a1a1316..f623683 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ # Set default behaviour, in case users don't have core.autocrlf set. * text=auto +*.py text eol=lf # Try to ensure that po files in the repo does not include # source code line numbers. diff --git a/addon/lib/configuration.py b/addon/lib/configuration.py index c217662..32b8c55 100644 --- a/addon/lib/configuration.py +++ b/addon/lib/configuration.py @@ -81,8 +81,8 @@ def _displayStringLabels(self): def _getSetting(setting: str, fromCache: bool) -> Any: if not initialized: initializeConfig() - section = _cachedConfig if fromCache else config.conf[CONFIG_SECTION_NAME] - return section[setting] + configSection = _cachedConfig if fromCache else config.conf[CONFIG_SECTION_NAME] + return configSection[setting] def getOperatingMode(fromCache: bool = False) -> OperatingMode: diff --git a/addon/lib/namedPipe.py b/addon/lib/namedPipe.py index b42dfb5..e4e30c3 100644 --- a/addon/lib/namedPipe.py +++ b/addon/lib/namedPipe.py @@ -36,27 +36,26 @@ def getParentProcessId(processId: int) -> int | None: - FSnapshotHandle = windll.kernel32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) + snapshotHandle = windll.kernel32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) try: - FProcessEntry32 = PROCESSENTRY32W() - FProcessEntry32.dwSize = sizeof(PROCESSENTRY32W) - ContinueLoop = windll.kernel32.Process32FirstW(FSnapshotHandle, byref(FProcessEntry32)) - while ContinueLoop: - if FProcessEntry32.th32ProcessID == processId: - return FProcessEntry32.th32ParentProcessID - ContinueLoop = windll.kernel32.Process32NextW(FSnapshotHandle, byref(FProcessEntry32)) - else: - return None + processEntry = PROCESSENTRY32W() + processEntry.dwSize = sizeof(PROCESSENTRY32W) + hasEntry = windll.kernel32.Process32FirstW(snapshotHandle, byref(processEntry)) + while hasEntry: + if processEntry.th32ProcessID == processId: + return processEntry.th32ParentProcessID + hasEntry = windll.kernel32.Process32NextW(snapshotHandle, byref(processEntry)) + return None finally: - windll.kernel32.CloseHandle(FSnapshotHandle) + windll.kernel32.CloseHandle(snapshotHandle) def getNamedPipes() -> Iterator[str]: - yield from iglob(os.path.join(PIPE_DIRECTORY, "*")) + return iglob(os.path.join(PIPE_DIRECTORY, "*")) def getRdPipeNamedPipes() -> Iterator[str]: - yield from iglob(RD_PIPE_GLOB_PATTERN) + return iglob(RD_PIPE_GLOB_PATTERN) class PipeMode(IntFlag): diff --git a/addon/lib/protocol/__init__.py b/addon/lib/protocol/__init__.py index 085aad8..d1b79df 100644 --- a/addon/lib/protocol/__init__.py +++ b/addon/lib/protocol/__init__.py @@ -265,7 +265,7 @@ def isAttributeRequestPending(self, attribute: AttributeT) -> bool: def hasNewValueSince(self, attribute: AttributeT, t: float) -> bool: return t <= self._valueTimes[attribute] - def _getDefaultValue(self, attribute: AttributeT) -> Any: + def _getDefaultAttributeValue(self, attribute: AttributeT) -> Any: handler = self._getRawHandler(attribute) log.debug( f"Getting default value for attribute {attribute!r} on {self!r} " @@ -274,7 +274,7 @@ def _getDefaultValue(self, attribute: AttributeT) -> Any: getter = handler._defaultValueGetter.__get__(handler.__self__) return getter(attribute) - def _invokeUpdateCallback(self, attribute: AttributeT, value: Any): + def _submitAttributeUpdateCallback(self, attribute: AttributeT, value: Any): handler = self._getRawHandler(attribute) if handler._updateCallback is not None: callback = handler._updateCallback.__get__(handler.__self__) @@ -284,7 +284,7 @@ def _invokeUpdateCallback(self, attribute: AttributeT, value: Any): def getValue(self, attribute: AttributeT, fallBackToDefault: bool = False): if fallBackToDefault and attribute not in self._values: log.debug(f"No value for attribute {attribute!r} on {self!r}, falling back to default") - self._values[attribute] = self._getDefaultValue(attribute) + self._values[attribute] = self._getDefaultAttributeValue(attribute) return self._values[attribute] def clearValue(self, attribute): @@ -293,7 +293,7 @@ def clearValue(self, attribute): def setValue(self, attribute: AttributeT, value): self._values[attribute] = value self._valueTimes[attribute] = time.perf_counter() - self._invokeUpdateCallback(attribute, value) + self._submitAttributeUpdateCallback(attribute, value) def __call__(self, attribute: AttributeT, rawValue: bytes): log.debug(f"Getting handler on {self!r} to process attribute {attribute!r}") @@ -386,17 +386,17 @@ def _onReceive(self, message: bytes): @commandHandler(GenericCommand.ATTRIBUTE) def _command_attribute(self, payload: bytes): - attribute, value = payload[1:].split(b"`", 1) - log.debug(f"Handling attribute {attribute!r} on {self!r}, value {value!r}") - if not value: + attribute, rawValue = payload[1:].split(ATTRIBUTE_SEPARATOR, 1) + log.debug(f"Handling attribute {attribute!r} on {self!r}, value {rawValue!r}") + if not rawValue: log.debug(f"No value sent for attribute {attribute!r} on {self!r}, expecting a reply") self._attributeSenderStore(attribute) else: log.debug( - f"Value of length {len(value)} sent for attribute {attribute!r} " + f"Value of length {len(rawValue)} sent for attribute {attribute!r} " f"on {self!r}, direction incoming", ) - self._attributeValueProcessor(attribute, value) + self._attributeValueProcessor(attribute, rawValue) @abstractmethod def _incoming_setting(self, attribute: AttributeT, payLoad: bytes): @@ -449,7 +449,7 @@ def _getRemoteAttributeValueWithFallback(self, attribute: AttributeT): try: return self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False) except KeyError: - value = self._attributeValueProcessor._getDefaultValue(attribute) + value = self._attributeValueProcessor._getDefaultAttributeValue(attribute) self.requestRemoteAttribute(attribute) return value