From af51c23252618e0c85da296fcb1da7ea3de63cfa Mon Sep 17 00:00:00 2001 From: ArtemIsmagilov Date: Wed, 12 Jun 2024 19:27:10 +0400 Subject: [PATCH 1/2] copy resolve mut arg in funcs, methods --- caldav/davclient.py | 23 +++++++++++++---------- caldav/objects.py | 5 +---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/caldav/davclient.py b/caldav/davclient.py index 89edc96..75fe8b1 100644 --- a/caldav/davclient.py +++ b/caldav/davclient.py @@ -50,7 +50,7 @@ class DAVResponse: raw = "" reason: str = "" tree: Optional[_Element] = None - headers: CaseInsensitiveDict = {} + headers: CaseInsensitiveDict = None status: int = 0 davclient = None huge_tree: bool = False @@ -310,8 +310,8 @@ def _expand_simple_prop( ## TODO: "expand" does not feel quite right. def expand_simple_props( self, - props: Iterable[BaseElement] = [], - multi_value_props: Iterable[typing.Any] = [], + props: Iterable[BaseElement] = None, + multi_value_props: Iterable[typing.Any] = None, xpath: Optional[str] = None, ) -> typing.Dict[str, typing.Dict[str, str]]: """ @@ -322,6 +322,9 @@ def expand_simple_props( Executes find_objects_and_props if not run already, then modifies and returns self.objects. """ + props = props or [] + multi_value_props = multi_value_props or [] + if not hasattr(self, "objects"): self.find_objects_and_props() for href in self.objects: @@ -367,7 +370,7 @@ def __init__( timeout: Optional[int] = None, ssl_verify_cert: Union[bool, str] = True, ssl_cert: Union[str, typing.Tuple[str, str], None] = None, - headers: typing.Dict[str, str] = {}, + headers: typing.Dict[str, str] = None, huge_tree: bool = False, ) -> None: """ @@ -385,6 +388,7 @@ def __init__( username and password may be omitted. Known bug: .netrc is honored even if a username/password is given, ref https://github.com/python-caldav/caldav/issues/206 """ + headers = headers or {} self.session = requests.Session() @@ -586,17 +590,17 @@ def mkcalendar(self, url: str, body: str = "", dummy: None = None) -> DAVRespons """ return self.request(url, "MKCALENDAR", body) - def put(self, url: str, body: str, headers: Mapping[str, str] = {}) -> DAVResponse: + def put(self, url: str, body: str, headers: Mapping[str, str] = None) -> DAVResponse: """ Send a put request. """ - return self.request(url, "PUT", body, headers) + return self.request(url, "PUT", body, headers or {}) - def post(self, url: str, body: str, headers: Mapping[str, str] = {}) -> DAVResponse: + def post(self, url: str, body: str, headers: Mapping[str, str] = None) -> DAVResponse: """ Send a POST request. """ - return self.request(url, "POST", body, headers) + return self.request(url, "POST", body, headers or {}) def delete(self, url: str) -> DAVResponse: """ @@ -623,8 +627,7 @@ def request( """ Actually sends the request, and does the authentication """ - if headers is None: - headers = {} + headers = headers or {} combined_headers = self.headers.copy() combined_headers.update(headers) diff --git a/caldav/objects.py b/caldav/objects.py index 62a0d27..fbf2971 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -121,10 +121,7 @@ def __init__( self.parent = parent self.name = name self.id = id - if props is None: - self.props = {} - else: - self.props = props + self.props = props or {} self.extra_init_options = extra # url may be a path relative to the caldav root if client and url: From 67eb35e82cf399e38d7df8f1b59288bb07e04d1f Mon Sep 17 00:00:00 2001 From: ArtemIsmagilov Date: Wed, 12 Jun 2024 19:30:49 +0400 Subject: [PATCH 2/2] formatting by black --- caldav/davclient.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/caldav/davclient.py b/caldav/davclient.py index 75fe8b1..67bc970 100644 --- a/caldav/davclient.py +++ b/caldav/davclient.py @@ -590,13 +590,17 @@ def mkcalendar(self, url: str, body: str = "", dummy: None = None) -> DAVRespons """ return self.request(url, "MKCALENDAR", body) - def put(self, url: str, body: str, headers: Mapping[str, str] = None) -> DAVResponse: + def put( + self, url: str, body: str, headers: Mapping[str, str] = None + ) -> DAVResponse: """ Send a put request. """ return self.request(url, "PUT", body, headers or {}) - def post(self, url: str, body: str, headers: Mapping[str, str] = None) -> DAVResponse: + def post( + self, url: str, body: str, headers: Mapping[str, str] = None + ) -> DAVResponse: """ Send a POST request. """