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


Python Component.fromStream方法代码示例

本文整理汇总了Python中twistedcaldav.ical.Component.fromStream方法的典型用法代码示例。如果您正苦于以下问题:Python Component.fromStream方法的具体用法?Python Component.fromStream怎么用?Python Component.fromStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twistedcaldav.ical.Component的用法示例。


在下文中一共展示了Component.fromStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mkcalendar_cb

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
        def mkcalendar_cb(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("MKCALENDAR failed: %s" % (response.code,))

            def put_cb(response):
                response = IResponse(response)

                if response.code != responsecode.FORBIDDEN:
                    self.fail("Incorrect response to dot file PUT: %s" % (response.code,))

            stream = self.dataPath.child(
                "Holidays").child(
                "C318AA54-1ED0-11D9-A5E0-000A958A3252.ics"
            ).open()
            try: calendar = str(Component.fromStream(stream))
            finally: stream.close()

            event_uri = "/".join([calendar_uri, ".event.ics"])

            request = SimpleRequest(self.site, "PUT", event_uri)
            request.headers.setHeader("content-type", MimeType("text", "calendar"))
            request.stream = MemoryStream(calendar)
            return self.send(request, put_cb)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:test_collectioncontents.py

示例2: _db_recreate

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
    def _db_recreate(self, do_commit=True):
        """
        Re-create the database tables from existing calendar data.
        """

        #
        # Populate the DB with data from already existing resources.
        # This allows for index recovery if the DB file gets
        # deleted.
        #
        fp = self.resource.fp
        for name in fp.listdir():
            if name.startswith("."):
                continue

            try:
                stream = fp.child(name).open()
            except (IOError, OSError), e:
                log.err("Unable to open resource %s: %s" % (name, e))
                continue

            # FIXME: This is blocking I/O
            try:
                calendar = Component.fromStream(stream)
                calendar.validCalendarData()
                calendar.validCalendarForCalDAV(methodAllowed=True)
            except ValueError:
                log.err("Non-calendar resource: %s" % (name,))
            else:
                #log.msg("Indexing resource: %s" % (name,))
                self.addResource(name, calendar, True, reCreate=True)
            finally:
                stream.close()
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:35,代码来源:index_file.py

示例3: test_fail_dot_file_put_in_calendar

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
    def test_fail_dot_file_put_in_calendar(self):
        """
        Make (regular) collection in calendar
        """
        calendar_uri = "/calendars/users/wsanchez/dot_file_in_calendar/"
        principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
        request = SimpleStoreRequest(self, "MKCALENDAR", calendar_uri, authPrincipal=principal)
        response = yield self.send(request)
        response = IResponse(response)
        if response.code != responsecode.CREATED:
            self.fail("MKCALENDAR failed: %s" % (response.code,))

        stream = self.dataPath.child(
            "Holidays").child(
            "C318AA54-1ED0-11D9-A5E0-000A958A3252.ics"
        ).open()
        try:
            calendar = str(Component.fromStream(stream))
        finally:
            stream.close()

        event_uri = "/".join([calendar_uri, ".event.ics"])

        request = SimpleStoreRequest(self, "PUT", event_uri, authPrincipal=principal)
        request.headers.setHeader("content-type", MimeType("text", "calendar"))
        request.stream = MemoryStream(calendar)
        response = yield self.send(request)
        response = IResponse(response)
        if response.code != responsecode.FORBIDDEN:
            self.fail("Incorrect response to dot file PUT: %s" % (response.code,))
开发者ID:nunb,项目名称:calendarserver,代码行数:32,代码来源:test_collectioncontents.py

示例4: test_duplicate_uids

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
    def test_duplicate_uids(self):
        """
        Mutiple resources with the same UID.
        """
        stream = self.dataPath.child(
            "Holidays").child(
            "C318AA54-1ED0-11D9-A5E0-000A958A3252.ics").open()
        try: calendar = str(Component.fromStream(stream))
        finally: stream.close()

        return self._test_file_in_calendar(
            "mutiple resources with the same UID",
            (MemoryStream(calendar), responsecode.CREATED),
            (MemoryStream(calendar), responsecode.FORBIDDEN),
        )
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:17,代码来源:test_collectioncontents.py

示例5: test_single_events

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
    def test_single_events(self):
        """
        Single events in calendar collection
        """
        work = []

        stream = self.openHolidays()
        calendar = Component.fromStream(stream)

        for subcomponent in calendar.subcomponents():
            if subcomponent.name() == "VEVENT":
                subcalendar = Component("VCALENDAR")
                subcalendar.addComponent(subcomponent)
                for property in calendar.properties(): subcalendar.addProperty(property)
                work.append((MemoryStream(str(subcalendar)), responsecode.CREATED))

        return self._test_file_in_calendar("single event in calendar", *work)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:19,代码来源:test_collectioncontents.py

示例6: doTest

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
    def doTest(self, filename, dtstart, dtend, testEqual=True):
        
        if testEqual:
            testMethod = self.assertEqual
        else:
            testMethod = self.assertNotEqual

        calendar = Component.fromStream(file(os.path.join(self.data_dir, filename)))
        if calendar.name() != "VCALENDAR": self.fail("Calendar is not a VCALENDAR")

        instances = calendar.expandTimeRanges(datetime.date(2100, 1, 1))
        for key in instances:
            instance = instances[key]
            start = instance.start
            end = instance.end
            testMethod(start, dtstart)
            testMethod(end, dtend)
            break;
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:20,代码来源:test_timezones.py

示例7: splitICalendarFile

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
def splitICalendarFile(inputFileName, outputDirectory):
    """
    Reads iCalendar data from a file and outputs a separate file for
    each iCalendar component into a directory.  This is useful for
    converting a monolithic iCalendar object into a set of objects
    that comply with CalDAV's requirements on resources.
    """
    inputFile = open(inputFileName)
    try:
        calendar = iComponent.fromStream(inputFile)
    finally:
        inputFile.close()

    assert calendar.name() == "VCALENDAR"

    topLevelProperties = tuple(calendar.properties())

    for subcomponent in calendar.subcomponents():
        subcalendar = iComponent("VCALENDAR")

        #
        # Add top-level properties from monolithic calendar to
        # top-level properties of subcalendar.
        #
        for property in topLevelProperties:
            subcalendar.addProperty(property)

        subcalendar.addComponent(subcomponent)

        uid = subcalendar.resourceUID()
        subFileName = os.path.join(outputDirectory, uid + ".ics")

        print("Writing %s" % (subFileName,))

        subcalendar_file = file(subFileName, "w")
        try:
            subcalendar_file.write(str(subcalendar))
        finally:
            subcalendar_file.close()
开发者ID:eventable,项目名称:CalendarServer,代码行数:41,代码来源:icalsplit.py

示例8: Component

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromStream [as 别名]
# limitations under the License.
##

#
# Splits up the monolithic .Mac holidays calendar into a separate calendar
# for each subcomponent therein.
# These split-up calendars are useable as CalDAV resources.
#

import os

from twistedcaldav.ical import Component

monolithic_filename = os.path.join(os.path.dirname(__file__), "Holidays.ics")

calendar = Component.fromStream(file(monolithic_filename))

assert calendar.name() == "VCALENDAR"

for subcomponent in calendar.subcomponents():
    subcalendar = Component("VCALENDAR")

    #
    # Add top-level properties from monolithic calendar to top-level properties
    # of subcomponent calendar.
    #
    for property in calendar.properties():
        subcalendar.addProperty(property)

    subcalendar.addComponent(subcomponent)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:32,代码来源:split_holidays.py


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