From 9e2e8526d5e1e2c02767ade55b635f10de16d75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Can=20=C3=96zyurt?= Date: Mon, 15 Aug 2022 17:32:26 +0000 Subject: [PATCH 1/2] pincushion reserved names --- maas/client/bones/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/maas/client/bones/__init__.py b/maas/client/bones/__init__.py index 7b5b8d3..a87d78a 100644 --- a/maas/client/bones/__init__.py +++ b/maas/client/bones/__init__.py @@ -8,6 +8,8 @@ import typing +from keyword import iskeyword + from collections import namedtuple from collections.abc import Iterable import json @@ -177,7 +179,7 @@ def __populate(self): self.__doc__ = self.__handler["doc"] actions = self.__handler["actions"] for action in actions: - setattr(self, action["name"], ActionAPI(action, self)) + _setattr(self, action["name"], ActionAPI(action, self)) @property def name(self): @@ -520,3 +522,15 @@ def _prefer_json(headers): if not any(header.lower() == "accept" for header in headers): headers["Accept"] = "application/json,*/*;q=0.9" return headers + + +def _setattr(obj, name, value): + """Classic settatr(), also pincushions name if it's a reserved keyword. + + Although keywords can be used as object names, they cause a syntax error + upon call. This renders ActionAPIs with names like 'import' unusable, thus + we pincushion the names. + """ + if iskeyword(name): + name = name + "_" + setattr(obj, name, value) From 35fd3c8ba01cf21267d4e6c1622a713d5cdde1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Can=20=C3=96zyurt?= Date: Mon, 15 Aug 2022 17:55:02 +0000 Subject: [PATCH 2/2] fix typo --- maas/client/bones/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maas/client/bones/__init__.py b/maas/client/bones/__init__.py index a87d78a..801c5c0 100644 --- a/maas/client/bones/__init__.py +++ b/maas/client/bones/__init__.py @@ -525,7 +525,7 @@ def _prefer_json(headers): def _setattr(obj, name, value): - """Classic settatr(), also pincushions name if it's a reserved keyword. + """Classic setattr(), also pincushions name if it's a reserved keyword. Although keywords can be used as object names, they cause a syntax error upon call. This renders ActionAPIs with names like 'import' unusable, thus