1.1 --- a/imiptools/content.py Tue Oct 31 23:46:20 2017 +0100
1.2 +++ b/imiptools/content.py Tue Oct 31 23:47:31 2017 +0100
1.3 @@ -129,32 +129,56 @@
1.4 """
1.5
1.6 itip = parse_itip_part(part)
1.7 + if itip:
1.8 + handle_calendar_data(itip, handlers)
1.9 +
1.10 + return not not itip
1.11 +
1.12 +def handle_calendar_data(itip, handlers):
1.13 +
1.14 + """
1.15 + Handle the calendar data provided by 'itip' using the given 'handlers'
1.16 + dictionary. Responses are set in each handler used to handle a message.
1.17 + Return all handled objects.
1.18 + """
1.19 +
1.20 method = itip and get_value(itip, "METHOD")
1.21 + handled = []
1.22
1.23 for obj in get_objects_from_itip(itip, handlers):
1.24 + handle_calendar_object(obj, handlers, method)
1.25 + handled.append(obj)
1.26
1.27 - # Get a handler for the given object type.
1.28 + return handled
1.29 +
1.30 +def handle_calendar_object(obj, handlers, method):
1.31
1.32 - handler = handlers.get(obj.objtype)
1.33 - if not handler:
1.34 - continue
1.35 + """
1.36 + Handle the calendar data provided by 'obj' using the given 'handlers'
1.37 + dictionary and 'method' information. Responses are set in each handler used
1.38 + to handle a message.
1.39 + """
1.40
1.41 - # Dispatch to a handler and obtain any response.
1.42 -
1.43 - handler.set_object(obj)
1.44 - handler.set_identity(method)
1.45 + # Get a handler for the given object type.
1.46
1.47 - if handler.is_usable(method):
1.48 + handler = handlers.get(obj.objtype)
1.49 + if not handler:
1.50 + return
1.51
1.52 - # Perform the method in a critical section.
1.53 + # Dispatch to a handler and obtain any response.
1.54 +
1.55 + handler.set_object(obj)
1.56 + handler.set_identity(method)
1.57
1.58 - handler.acquire_lock()
1.59 - try:
1.60 - methods[method](handler)()
1.61 - finally:
1.62 - handler.release_lock()
1.63 + if handler.is_usable(method):
1.64 +
1.65 + # Perform the method in a critical section.
1.66
1.67 - return not not itip
1.68 + handler.acquire_lock()
1.69 + try:
1.70 + methods[method](handler)()
1.71 + finally:
1.72 + handler.release_lock()
1.73
1.74 # Handler registry.
1.75