本文整理汇总了Python中icalendar.cal.Component.property_items方法的典型用法代码示例。如果您正苦于以下问题:Python Component.property_items方法的具体用法?Python Component.property_items怎么用?Python Component.property_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类icalendar.cal.Component
的用法示例。
在下文中一共展示了Component.property_items方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cal_Component
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import property_items [as 别名]
#.........这里部分代码省略.........
e = Component(summary='A brief history of time')
e.name = 'VEVENT'
e.add('dtend', '20000102T000000', encode=0)
e.add('dtstart', '20000101T000000', encode=0)
self.assertEqual(
e.to_ical(),
b'BEGIN:VEVENT\r\nDTEND:20000102T000000\r\n'
+ b'DTSTART:20000101T000000\r\nSUMMARY:A brief history of time\r'
+ b'\nEND:VEVENT\r\n'
)
c.add_component(e)
self.assertEqual(
c.subcomponents,
[Event({'DTEND': '20000102T000000', 'DTSTART': '20000101T000000',
'SUMMARY': 'A brief history of time'})]
)
# We can walk over nested componentes with the walk method.
self.assertEqual([i.name for i in c.walk()], ['VCALENDAR', 'VEVENT'])
# We can also just walk over specific component types, by filtering
# them on their name.
self.assertEqual([i.name for i in c.walk('VEVENT')], ['VEVENT'])
self.assertEqual(
[i['dtstart'] for i in c.walk('VEVENT')],
['20000101T000000']
)
# We can enumerate property items recursively with the property_items
# method.
self.assertEqual(
c.property_items(),
[('BEGIN', b'VCALENDAR'), ('ATTENDEE', prop.vCalAddress('Max M')),
('BEGIN', b'VEVENT'), ('DTEND', '20000102T000000'),
('DTSTART', '20000101T000000'),
('SUMMARY', 'A brief history of time'), ('END', b'VEVENT'),
('END', b'VCALENDAR')]
)
# We can also enumerate property items just under the component.
self.assertEqual(
c.property_items(recursive=False),
[('BEGIN', b'VCALENDAR'),
('ATTENDEE', prop.vCalAddress('Max M')),
('END', b'VCALENDAR')]
)
sc = c.subcomponents[0]
self.assertEqual(
sc.property_items(recursive=False),
[('BEGIN', b'VEVENT'), ('DTEND', '20000102T000000'),
('DTSTART', '20000101T000000'),
('SUMMARY', 'A brief history of time'), ('END', b'VEVENT')]
)
# Text fields which span multiple mulitple lines require proper
# indenting
c = Calendar()
c['description'] = u'Paragraph one\n\nParagraph two'
self.assertEqual(
c.to_ical(),
b'BEGIN:VCALENDAR\r\nDESCRIPTION:Paragraph one\\n\\nParagraph two'
+ b'\r\nEND:VCALENDAR\r\n'
)
示例2: test_cal_Component
# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import property_items [as 别名]
#.........这里部分代码省略.........
self.assertEqual(c.to_ical(), b"BEGIN:VCALENDAR\r\nATTENDEE:Max M\r\nEND:VCALENDAR\r\n")
# Components can be nested, so You can add a subcompont. Eg a calendar
# holds events.
e = Component(summary="A brief history of time")
e.name = "VEVENT"
e.add("dtend", "20000102T000000", encode=0)
e.add("dtstart", "20000101T000000", encode=0)
self.assertEqual(
e.to_ical(),
b"BEGIN:VEVENT\r\nDTEND:20000102T000000\r\n"
+ b"DTSTART:20000101T000000\r\nSUMMARY:A brief history of time\r"
+ b"\nEND:VEVENT\r\n",
)
c.add_component(e)
self.assertEqual(
c.subcomponents,
[Event({"DTEND": "20000102T000000", "DTSTART": "20000101T000000", "SUMMARY": "A brief history of time"})],
)
# We can walk over nested componentes with the walk method.
self.assertEqual([i.name for i in c.walk()], ["VCALENDAR", "VEVENT"])
# We can also just walk over specific component types, by filtering
# them on their name.
self.assertEqual([i.name for i in c.walk("VEVENT")], ["VEVENT"])
self.assertEqual([i["dtstart"] for i in c.walk("VEVENT")], ["20000101T000000"])
# We can enumerate property items recursively with the property_items
# method.
self.assertEqual(
c.property_items(),
[
("BEGIN", b"VCALENDAR"),
("ATTENDEE", prop.vCalAddress("Max M")),
("BEGIN", b"VEVENT"),
("DTEND", "20000102T000000"),
("DTSTART", "20000101T000000"),
("SUMMARY", "A brief history of time"),
("END", b"VEVENT"),
("END", b"VCALENDAR"),
],
)
# We can also enumerate property items just under the component.
self.assertEqual(
c.property_items(recursive=False),
[("BEGIN", b"VCALENDAR"), ("ATTENDEE", prop.vCalAddress("Max M")), ("END", b"VCALENDAR")],
)
sc = c.subcomponents[0]
self.assertEqual(
sc.property_items(recursive=False),
[
("BEGIN", b"VEVENT"),
("DTEND", "20000102T000000"),
("DTSTART", "20000101T000000"),
("SUMMARY", "A brief history of time"),
("END", b"VEVENT"),
],
)
# Text fields which span multiple mulitple lines require proper
# indenting