Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions addon/lib/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 12 additions & 13 deletions addon/lib/namedPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 10 additions & 10 deletions addon/lib/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} "
Expand All @@ -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__)
Expand All @@ -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):
Expand All @@ -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}")
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down