本文整理汇总了Python中icalendar.cal.Component.from_ical方法的典型用法代码示例。如果您正苦于以下问题:Python Component.from_ical方法的具体用法?Python Component.from_ical怎么用?Python Component.from_ical使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类icalendar.cal.Component
的用法示例。
在下文中一共展示了Component.from_ical方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cal_Component_from_ical
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import from_ical [as 别名]
def test_cal_Component_from_ical(self):
# RecurrenceIDs may contain a TZID parameter, if so, they should create
# a tz localized datetime, otherwise, create a naive datetime
Component = icalendar.cal.Component
componentStr = 'BEGIN:VEVENT\nRECURRENCE-ID;TZID=America/Denver:'\
+ '20120404T073000\nEND:VEVENT'
component = Component.from_ical(componentStr)
self.assertEqual(
str(component['RECURRENCE-ID'].dt.tzinfo.zone), "America/Denver")
componentStr = 'BEGIN:VEVENT\nRECURRENCE-ID:20120404T073000\n'\
+ 'END:VEVENT'
component = Component.from_ical(componentStr)
self.assertEqual(component['RECURRENCE-ID'].dt.tzinfo, None)
示例2: test_cal_Component_from_ical
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import from_ical [as 别名]
def test_cal_Component_from_ical(self):
# Check for proper handling of TZID parameter of datetime properties
Component = icalendar.cal.Component
for component_name, property_name in (
("VEVENT", "DTSTART"),
("VEVENT", "DTEND"),
("VEVENT", "RECURRENCE-ID"),
("VTODO", "DUE"),
):
component_str = "BEGIN:" + component_name + "\n"
component_str += property_name + ";TZID=America/Denver:"
component_str += "20120404T073000\nEND:" + component_name
component = Component.from_ical(component_str)
self.assertEqual(str(component[property_name].dt.tzinfo.zone), "America/Denver")
component_str = "BEGIN:" + component_name + "\n"
component_str += property_name + ":"
component_str += "20120404T073000\nEND:" + component_name
component = Component.from_ical(component_str)
self.assertEqual(component[property_name].dt.tzinfo, None)
示例3: test_cal_Component_to_ical_parameter_order
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import from_ical [as 别名]
def test_cal_Component_to_ical_parameter_order(self):
Component = icalendar.cal.Component
component_str = [b"BEGIN:VEVENT", b"X-FOOBAR;C=one;A=two;B=three:helloworld.", b"END:VEVENT"]
component = Component.from_ical(b"\r\n".join(component_str))
sorted_str = component.to_ical().splitlines()
assert sorted_str[0] == component_str[0]
assert sorted_str[1] == b"X-FOOBAR;A=two;B=three;C=one:helloworld."
assert sorted_str[2] == component_str[2]
preserved_str = component.to_ical(sorted=False).splitlines()
assert preserved_str == component_str
示例4: test_cal_Component_from_ical
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import from_ical [as 别名]
def test_cal_Component_from_ical(self):
# Check for proper handling of TZID parameter of datetime properties
Component = icalendar.cal.Component
for component_name, property_name in (
('VEVENT', 'DTSTART'),
('VEVENT', 'DTEND'),
('VEVENT', 'RECURRENCE-ID'),
('VTODO', 'DUE')
):
component_str = 'BEGIN:' + component_name + '\n'
component_str += property_name + ';TZID=America/Denver:'
component_str += '20120404T073000\nEND:' + component_name
component = Component.from_ical(component_str)
self.assertEqual(str(component[property_name].dt.tzinfo.zone),
"America/Denver")
component_str = 'BEGIN:' + component_name + '\n'
component_str += property_name + ':'
component_str += '20120404T073000\nEND:' + component_name
component = Component.from_ical(component_str)
self.assertEqual(component[property_name].dt.tzinfo,
None)
示例5: test_cal_Component_to_ical_property_order
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import from_ical [as 别名]
def test_cal_Component_to_ical_property_order(self):
Component = icalendar.cal.Component
component_str = [b'BEGIN:VEVENT',
b'DTSTART:19970714T170000Z',
b'DTEND:19970715T035959Z',
b'SUMMARY:Bastille Day Party',
b'END:VEVENT']
component = Component.from_ical(b'\r\n'.join(component_str))
sorted_str = component.to_ical().splitlines()
assert sorted_str != component_str
assert set(sorted_str) == set(component_str)
preserved_str = component.to_ical(sorted=False).splitlines()
assert preserved_str == component_str
示例6: convert_from_calendar
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import from_ical [as 别名]
def convert_from_calendar(dict_calendar):
data = {
'format': dict_calendar['format']
}
if dict_calendar["format"] == CALENDAR:
pattern = dict_calendar["pattern"]
calendar_event = Component.from_ical(
CalendarUtil.decode_calendar_pattern(pattern)
)
if isinstance(calendar_event, Event):
calendar_event_rule = calendar_event['RRULE']
data['frequence'] = calendar_event_rule['FREQ'][0]
if data['frequence'] == MONTHLY and not (
'INTERVAL' in calendar_event['RRULE']):
data['date'] = ' '.join(
str(date)
for date in calendar_event_rule['BYMONTHDAY'])
if data['frequence'] == WEEKLY and not (
'INTERVAL' in calendar_event['RRULE']):
data['day'] = ' '.join(
str(CALENDAR_DAY_MAPPING_DICT[day])
for day in calendar_event_rule['BYDAY'])
if 'BYHOUR' in calendar_event['RRULE']:
data['hour'] = ' '.join(
str(hour) for hour in calendar_event_rule['BYHOUR'])
if 'BYMINUTE' in calendar_event['RRULE']:
data['minute'] = ' '.join(
str(minute)
for minute in calendar_event_rule['BYMINUTE'])
if 'INTERVAL' in calendar_event['RRULE']:
data['interval'] = ' '.join(
str(interval)
for interval in calendar_event_rule['INTERVAL'])
return data