当前位置: 首页>>代码示例>>Python>>正文


Python Component.newCalendar方法代码示例

本文整理汇总了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))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:28,代码来源:export.py

示例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)
开发者ID:azbarcea,项目名称:calendarserver,代码行数:32,代码来源:test_export.py

示例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)
开发者ID:azbarcea,项目名称:calendarserver,代码行数:28,代码来源:test_export.py

示例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())
开发者ID:azbarcea,项目名称:calendarserver,代码行数:13,代码来源:test_export.py

示例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()
开发者ID:eventable,项目名称:CalendarServer,代码行数:43,代码来源:export.py


注:本文中的twistedcaldav.ical.Component.newCalendar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。