Skip to content

Commit

Permalink
copy resolve mut arg in funcs, methods (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemIsmagilov authored Jun 12, 2024
1 parent 7681cd9 commit f3b83d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
27 changes: 17 additions & 10 deletions caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]:
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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()

Expand Down Expand Up @@ -586,17 +590,21 @@ 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:
"""
Expand All @@ -623,8 +631,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)
Expand Down
5 changes: 1 addition & 4 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f3b83d6

Please sign in to comment.