From b5abba44115053d0c4836afd2936225e9f9ee7ad Mon Sep 17 00:00:00 2001 From: Josiah Schwab Date: Sat, 9 Feb 2019 11:42:45 -0800 Subject: [PATCH] Fix case in which x and y are not specified in panning The regular expression that extracts the panning values has optional matches for the named groups x and y. Previously, the case in which there is no match for x and y looks to have been attempted to be handled by doing detail.get("x", "0") This is a bug. The default argument to dict.get is only returned when the key is not a member of the dictionary. However, when a group fails to participate in the regex match, the dict does have a key. The default value of this default key is None. This would lead to an error when the get returned None and None was then cast to an integer. This resolves the issue by explicitly setting the groupdict default to be "0", which is appropriate for the two groups (x and y) that may optionally participate in the match. --- autorandr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autorandr.py b/autorandr.py index 1e980f6..7359aa2 100755 --- a/autorandr.py +++ b/autorandr.py @@ -656,9 +656,9 @@ def get_fb_dimensions(configuration): if "panning" in output.options: match = re.match("(?P[0-9]+)x(?P[0-9]+)(?:\+(?P[0-9]+))?(?:\+(?P[0-9]+))?.*", output.options["panning"]) if match: - detail = match.groupdict() - o_width = int(detail.get("w")) + int(detail.get("x", "0")) - o_height = int(detail.get("h")) + int(detail.get("y", "0")) + detail = match.groupdict(default="0") + o_width = int(detail.get("w")) + int(detail.get("x")) + o_height = int(detail.get("h")) + int(detail.get("y")) width = max(width, o_width) height = max(height, o_height) return int(width), int(height) -- 2.39.2