Skip to content

Commit

Permalink
Close HTTP sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
OneBlue committed Nov 16, 2024
1 parent dfb03a4 commit 8180483
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions events/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ def get_event(self, name: str):
return event

def lookup_event_by_uid(self, uid: str):
session = requests.Session()
session.auth = self.auth

query = f'''
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="UID">
<C:text-match>{escape(uid)}</C:text-match>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>'''

response = session.request(url=self.url, method='REPORT', data=query)
response.raise_for_status()
with requests.Session() as session:
session.auth = self.auth

query = f'''
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="UID">
<C:text-match>{escape(uid)}</C:text-match>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>'''

response = session.request(url=self.url, method='REPORT', data=query)
response.raise_for_status()

tree = ElementTree.fromstring(response.text)

Expand Down

0 comments on commit 8180483

Please sign in to comment.