本文整理汇总了Python中twistedcaldav.ical.Component.newCalendar方法的典型用法代码示例。如果您正苦于以下问题:Python Component.newCalendar方法的具体用法?Python Component.newCalendar怎么用?Python Component.newCalendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twistedcaldav.ical.Component
的用法示例。
在下文中一共展示了Component.newCalendar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exportToFile
# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import newCalendar [as 别名]
def exportToFile(calendars, fileobj):
"""
Export some calendars to a file as their owner would see them.
@param calendars: an iterable of L{ICalendar} providers (or L{Deferred}s of
same).
@param fileobj: an object with a C{write} method that will accept some
iCalendar data.
@return: a L{Deferred} which fires when the export is complete. (Note that
the file will not be closed.)
@rtype: L{Deferred} that fires with C{None}
"""
comp = Component.newCalendar()
for calendar in calendars:
calendar = yield calendar
for obj in (yield calendar.calendarObjects()):
evt = yield obj.filteredComponent(calendar.ownerCalendarHome().uid(), True)
for sub in evt.subcomponents():
if sub.name() != 'VTIMEZONE':
# Omit all VTIMEZONE components here - we will include them later
# when we serialize the whole calendar.
comp.addComponent(sub)
fileobj.write(comp.getTextWithTimezones(True))
示例2: test_twoSimpleEvents
# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import newCalendar [as 别名]
def test_twoSimpleEvents(self):
"""
Exporting a calendar with two events in it will result in a VCALENDAR
component with both VEVENTs in it.
"""
yield populateCalendarsFrom(
{
"home1": {
"calendar1": {
"valentines-day.ics": (valentines, {}),
"new-years-day.ics": (newYears, {})
}
}
}, self.store
)
expected = Component.newCalendar()
a = Component.fromString(valentines)
b = Component.fromString(newYears)
for comp in a, b:
for sub in comp.subcomponents():
expected.addComponent(sub)
io = StringIO()
yield exportToFile(
[(yield self.txn().calendarHomeWithUID("home1"))
.calendarWithName("calendar1")], io
)
self.assertEquals(Component.fromString(io.getvalue()),
expected)
示例3: test_oneEventCalendar
# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import newCalendar [as 别名]
def test_oneEventCalendar(self):
"""
Exporting an calendar with one event in it will result in just that
event.
"""
yield populateCalendarsFrom(
{
"home1": {
"calendar1": {
"valentines-day.ics": (valentines, {})
}
}
}, self.store
)
expected = Component.newCalendar()
[theComponent] = Component.fromString(valentines).subcomponents()
expected.addComponent(theComponent)
io = StringIO()
yield exportToFile(
[(yield self.txn().calendarHomeWithUID("home1"))
.calendarWithName("calendar1")], io
)
self.assertEquals(Component.fromString(io.getvalue()),
expected)
示例4: test_emptyCalendar
# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import newCalendar [as 别名]
def test_emptyCalendar(self):
"""
Exporting an empty calendar results in an empty calendar.
"""
io = StringIO()
value = yield exportToFile([], io)
# it doesn't return anything, it writes to the file.
self.assertEquals(value, None)
# but it should write a valid component to the file.
self.assertEquals(Component.fromString(io.getvalue()),
Component.newCalendar())
示例5: exportToDirectory
# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import newCalendar [as 别名]
def exportToDirectory(calendars, dirname):
"""
Export some calendars to a file as their owner would see them.
@param calendars: an iterable of L{ICalendar} providers (or L{Deferred}s of
same).
@param dirname: the path to a directory to store calendar files in; each
calendar being exported will have it's own .ics file
@return: a L{Deferred} which fires when the export is complete. (Note that
the file will not be closed.)
@rtype: L{Deferred} that fires with C{None}
"""
for calendar in calendars:
homeUID = calendar.ownerCalendarHome().uid()
calendarProperties = calendar.properties()
comp = Component.newCalendar()
for element, propertyName in ((davxml.DisplayName, "NAME"), (customxml.CalendarColor, "COLOR")):
value = calendarProperties.get(PropertyName.fromElement(element), None)
if value:
comp.addProperty(Property(propertyName, str(value)))
source = "/calendars/__uids__/{}/{}/".format(homeUID, calendar.name())
comp.addProperty(Property("SOURCE", source))
for obj in (yield calendar.calendarObjects()):
evt = yield obj.filteredComponent(homeUID, True)
for sub in evt.subcomponents():
if sub.name() != "VTIMEZONE":
# Omit all VTIMEZONE components here - we will include them later
# when we serialize the whole calendar.
comp.addComponent(sub)
filename = os.path.join(dirname, "{}_{}.ics".format(homeUID, calendar.name()))
fileobj = open(filename, "wb")
fileobj.write(comp.getTextWithTimezones(True))
fileobj.close()