Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def match_indexes(self, prop, tzify):
return any(self.match(vDDDTypes(vDatetime.from_ical(p)), tzify)
for p in prop[None])
for num, transtime in enumerate(tz._utc_transition_times):
if first_date > transtime > first_tt:
first_num = num
first_tt = transtime
if last_tt > transtime > last_date:
last_num = num
last_tt = transtime
timezones = dict()
for num in range(first_num, last_num + 1):
name = tz._transition_info[num][2]
if name in timezones:
ttime = tz.fromutc(tz._utc_transition_times[num]).replace(tzinfo=None)
if 'RDATE' in timezones[name]:
timezones[name]['RDATE'].dts.append(
icalendar.prop.vDDDTypes(ttime))
else:
timezones[name].add('RDATE', ttime)
continue
if dst[name] or bst[name]:
subcomp = icalendar.TimezoneDaylight()
else:
subcomp = icalendar.TimezoneStandard()
subcomp.add('TZNAME', tz._transition_info[num][2])
subcomp.add(
'DTSTART',
tz.fromutc(tz._utc_transition_times[num]).replace(tzinfo=None))
subcomp.add('TZOFFSETTO', tz._transition_info[num][0])
subcomp.add('TZOFFSETFROM', tz._transition_info[num - 1][0])
timezones[name] = subcomp
def match_indexes(self, indexes, tzify):
vs = {}
for name, value in indexes.items():
if name and name[2:] in self.all_props:
if value and value[0]:
if not isinstance(value[0], vDDDTypes):
vs[name[2:]] = vDDDTypes(vDatetime.from_ical(value[0]))
else:
vs[name[2:]] = value[0]
try:
component_handler = self.component_handlers[self.comp]
except KeyError:
logging.warning('unknown component %r in time-range filter',
self.comp)
return False
return component_handler(self.start, self.end, vs, tzify)
def default(self, obj):
if isinstance(obj, icalendar.prop.vDDDLists):
return [self.default(elem.dt) for elem in obj.dts]
elif isinstance(obj, icalendar.prop.vDDDTypes):
return self.default(obj.dt)
else:
return super(ICalJSONEncoder, self).default(obj)
def as_vevent(self):
revent = self.source.copy()
revent["DTSTART"] = vDDDTypes(self.start)
revent["DTEND"] = vDDDTypes(self.stop)
for attribute in self.ATTRIBUTES_TO_DELETE_ON_COPY:
if attribute in revent:
del revent[attribute]
for subcomponent in self.source.subcomponents:
revent.add_component(subcomponent)
return revent
def _parse_time_range(el):
start = el.get('start')
end = el.get('end')
# Either start OR end OR both need to be specified.
# https://tools.ietf.org/html/rfc4791, section 9.9
assert start is not None or end is not None
if start is None:
start = "00010101T000000Z"
if end is None:
end = "99991231T235959Z"
start = vDDDTypes.from_ical(start)
end = vDDDTypes.from_ical(end)
assert end > start
assert end.tzinfo
assert start.tzinfo
return (start, end)
requested = el
else:
raise AssertionError("unexpected XML element")
tz = get_calendar_timezone(base_resource)
def tzify(dt):
return as_tz_aware_ts(dt, tz).astimezone(pytz.utc)
(start, end) = _parse_time_range(requested)
assert start.tzinfo
assert end.tzinfo
ret = ICalendar()
ret['VERSION'] = '2.0'
ret['PRODID'] = PRODID
fb = FreeBusy()
fb['DTSTAMP'] = vDDDTypes(tzify(datetime.datetime.now()))
fb['DTSTART'] = vDDDTypes(start)
fb['DTEND'] = vDDDTypes(end)
fb['FREEBUSY'] = [item async for item in iter_freebusy(
webdav.traverse_resource(base_resource, base_href, depth),
start, end, tzify)]
ret.add_component(fb)
return webdav.Response(status='200 OK', body=[ret.to_ical()])