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


Python Component.fromString方法代码示例

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


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

示例1: test_objectresource_component

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_objectresource_component(self):
        """
        Test that a remote object resource L{component} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")

        resource = yield calendar.objectResourceWithName("1.ics")
        caldata = yield resource.component()
        self.assertEqual(str(caldata), self.caldata1)

        resource = yield calendar.objectResourceWithName("2.ics")
        caldata = yield resource.component()
        self.assertEqual(str(caldata), self.caldata2)

        yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:27,代码来源:test_store_api.py

示例2: test_oneEventCalendar

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [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

示例3: test_vcalendar_no_effect

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_vcalendar_no_effect(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        no_effect = CalendarData(
            CalendarComponent(
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)

        no_effect = CalendarData(
            CalendarComponent(
                AllComponents(),
                AllProperties(),
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)
开发者ID:nunb,项目名称:calendarserver,代码行数:35,代码来源:test_calendardata.py

示例4: migrate

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def migrate(self, txn, mapIDsCallback):
        """
        See L{ScheduleWork.migrate}
        """

        # Try to find a mapping
        new_home, new_resource = yield mapIDsCallback(self.resourceID)

        # If we previously had a resource ID and now don't, then don't create work
        if self.resourceID is not None and new_resource is None:
            returnValue(False)

        if self.icalendarTextOld:
            calendar_old = Component.fromString(self.icalendarTextOld)
            uid = calendar_old.resourceUID()
        else:
            calendar_new = Component.fromString(self.icalendarTextNew)
            uid = calendar_new.resourceUID()

        # Insert new work - in paused state
        yield ScheduleOrganizerWork.schedule(
            txn, uid, scheduleActionFromSQL[self.scheduleAction],
            new_home, new_resource, self.icalendarTextOld, self.icalendarTextNew,
            new_home.uid(), self.attendeeCount, self.smartMerge,
            pause=1
        )

        returnValue(True)
开发者ID:eventable,项目名称:CalendarServer,代码行数:30,代码来源:work.py

示例5: test_objectresource_objectwith

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_objectresource_objectwith(self):
        """
        Test that a remote home child L{objectResourceWithName} and L{objectResourceWithUID} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        resource01 = yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")

        resource = yield calendar.objectResourceWithName("2.ics")
        self.assertEqual(resource.name(), "2.ics")

        resource = yield calendar.objectResourceWithName("foo.ics")
        self.assertEqual(resource, None)

        resource = yield calendar.objectResourceWithUID("uid1")
        self.assertEqual(resource.name(), "1.ics")

        resource = yield calendar.objectResourceWithUID("foo")
        self.assertEqual(resource, None)

        resource = yield calendar.objectResourceWithID(resource01.id())
        self.assertEqual(resource.name(), "1.ics")

        resource = yield calendar.objectResourceWithID(12345)
        self.assertEqual(resource, None)

        yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:37,代码来源:test_store_api.py

示例6: test_objectresource_resourceuidforname

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_objectresource_resourceuidforname(self):
        """
        Test that a remote home child L{resourceUIDForName} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")

        uid = yield calendar.resourceUIDForName("1.ics")
        self.assertEqual(uid, "uid1")

        uid = yield calendar.resourceUIDForName("2.ics")
        self.assertEqual(uid, "uid2")

        uid = yield calendar.resourceUIDForName("foo.ics")
        self.assertEqual(uid, None)

        yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:28,代码来源:test_store_api.py

示例7: test_twoSimpleEvents

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [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

示例8: test_full

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_full(self):
        """
        Running C{calendarserver_export} on the command line exports an ics
        file. (Almost-full integration test, starting from the main point, using
        as few test fakes as possible.)

        Note: currently the only test for directory interaction.
        """
        yield populateCalendarsFrom(
            {
                "user02": {
                    # TODO: more direct test for skipping inbox
                    "inbox": {
                        "inbox-item.ics": (valentines, {})
                    },
                    "calendar1": {
                        "peruser.ics": (dataForTwoUsers, {}), # EST
                    }
                }
            }, self.store
        )

        output = FilePath(self.mktemp())
        main(['calendarserver_export', '--output',
              output.path, '--user', 'user02'], reactor=self)

        yield self.waitToStop

        self.assertEquals(
            Component.fromString(resultForUser2),
            Component.fromString(output.getContent())
        )
开发者ID:eventable,项目名称:CalendarServer,代码行数:34,代码来源:test_export.py

示例9: doWork

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def doWork(self):

        try:
            home = (yield self.transaction.calendarHomeWithResourceID(self.homeResourceID))
            resource = (yield home.objectResourceWithID(self.resourceID))
            organizerAddress = yield calendarUserFromCalendarUserUID(home.uid(), self.transaction)
            organizer = organizerAddress.record.canonicalCalendarUserAddress()
            calendar_old = Component.fromString(self.icalendarTextOld) if self.icalendarTextOld else None
            calendar_new = Component.fromString(self.icalendarTextNew) if self.icalendarTextNew else None

            log.debug("ScheduleOrganizerWork - running for ID: {id}, UID: {uid}, organizer: {org}", id=self.workID, uid=self.icalendarUid, org=organizer)

            # We need to get the UID lock for implicit processing.
            yield NamedLock.acquire(self.transaction, "ImplicitUIDLock:%s" % (hashlib.md5(self.icalendarUid).hexdigest(),))

            from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
            scheduler = ImplicitScheduler()
            yield scheduler.queuedOrganizerProcessing(
                self.transaction,
                scheduleActionFromSQL[self.scheduleAction],
                home,
                resource,
                self.icalendarUid,
                calendar_old,
                calendar_new,
                self.smartMerge
            )

            self._dequeued()

        except Exception, e:
            log.debug("ScheduleOrganizerWork - exception ID: {id}, UID: '{uid}', {err}", id=self.workID, uid=self.icalendarUid, err=str(e))
            log.debug(traceback.format_exc())
            raise
开发者ID:nunb,项目名称:calendarserver,代码行数:36,代码来源:work.py

示例10: test_setcomponent

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_setcomponent(self):
        """
        Test that action=setcomponent works.
        """

        yield self.createShare("user01", "puser01")

        calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
        yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield self.commitTransaction(0)

        shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
        ical = yield shared_object.component()
        self.assertTrue(isinstance(ical, Component))
        self.assertEqual(normalize_iCalStr(str(ical)), normalize_iCalStr(self.caldata1))
        yield self.commitTransaction(1)

        shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
        changed = yield shared_object.setComponent(Component.fromString(self.caldata1_changed))
        self.assertFalse(changed)
        ical = yield shared_object.component()
        self.assertTrue(isinstance(ical, Component))
        self.assertEqual(normalize_iCalStr(str(ical)), normalize_iCalStr(self.caldata1_changed))
        yield self.commitTransaction(1)

        object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
        ical = yield object1.component()
        self.assertTrue(isinstance(ical, Component))
        self.assertEqual(normalize_iCalStr(str(ical)), normalize_iCalStr(self.caldata1_changed))
        yield self.commitTransaction(0)
开发者ID:eventable,项目名称:CalendarServer,代码行数:32,代码来源:test_conduit.py

示例11: test_listobjects

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_listobjects(self):
        """
        Test that action=listobjects works.
        """

        yield self.createShare("user01", "puser01")

        shared = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", name="shared-calendar")
        objects = yield shared.listObjectResources()
        self.assertEqual(set(objects), set())
        yield self.commitTransaction(1)

        calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
        yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar1.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        objects = yield calendar1.listObjectResources()
        self.assertEqual(set(objects), set(("1.ics", "2.ics",)))
        yield self.commitTransaction(0)

        shared = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", name="shared-calendar")
        objects = yield shared.listObjectResources()
        self.assertEqual(set(objects), set(("1.ics", "2.ics",)))
        yield self.commitTransaction(1)

        calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
        object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
        yield object1.remove()
        objects = yield calendar1.listObjectResources()
        self.assertEqual(set(objects), set(("2.ics",)))
        yield self.commitTransaction(0)

        shared = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", name="shared-calendar")
        objects = yield shared.listObjectResources()
        self.assertEqual(set(objects), set(("2.ics",)))
        yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:37,代码来源:test_conduit.py

示例12: test_full

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_full(self):
        """
        Running C{calendarserver_export} on the command line exports an ics
        file. (Almost-full integration test, starting from the main point, using
        as few test fakes as possible.)

        Note: currently the only test for directory interaction.
        """
        yield populateCalendarsFrom(
            {
                "user02": {
                    # TODO: more direct test for skipping inbox
                    "inbox": {
                        "inbox-item.ics": (valentines, {})
                    },
                    "calendar1": {
                        "peruser.ics": (dataForTwoUsers, {}), # EST
                    }
                }
            }, self.store
        )

        augmentsData = """
            <augments>
              <record>
                <uid>Default</uid>
                <enable>true</enable>
                <enable-calendar>true</enable-calendar>
                <enable-addressbook>true</enable-addressbook>
              </record>
            </augments>
        """
        augments = FilePath(self.mktemp())
        augments.setContent(augmentsData)

        accountsData = """
            <accounts realm="Test Realm">
                <user>
                    <uid>user-under-test</uid>
                    <guid>user02</guid>
                    <name>Not Interesting</name>
                    <password>very-secret</password>
                </user>
            </accounts>
        """
        accounts = FilePath(self.mktemp())
        accounts.setContent(accountsData)
        output = FilePath(self.mktemp())
        self.accountsFile = accounts.path
        self.augmentsFile = augments.path
        main(['calendarserver_export', '--output',
              output.path, '--user', 'user-under-test'], reactor=self)

        yield self.waitToStop

        self.assertEquals(
            Component.fromString(resultForUser2),
            Component.fromString(output.getContent())
        )
开发者ID:azbarcea,项目名称:calendarserver,代码行数:61,代码来源:test_export.py

示例13: assertEqualCalendarData

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
 def assertEqualCalendarData(self, cal1, cal2):
     if isinstance(cal1, str):
         cal1 = Component.fromString(cal1)
     if isinstance(cal2, str):
         cal2 = Component.fromString(cal2)
     ncal1 = normalize_iCalStr(cal1)
     ncal2 = normalize_iCalStr(cal2)
     self.assertEqual(ncal1, ncal2, msg=diff_iCalStrs(ncal1, ncal2))
开发者ID:eventable,项目名称:CalendarServer,代码行数:10,代码来源:util.py

示例14: test_validation_replaceMissingToDoProperties_Completed

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_validation_replaceMissingToDoProperties_Completed(self):
        """
        Test that VTODO completed status is fixed.
        """

        data1 = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VTODO
UID:12345-67890-attendee-reply
DTSTAMP:20080601T120000Z
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ORGANIZER;CN="User 01":mailto:[email protected]
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VTODO
END:VCALENDAR
"""

        calendar_collection = (yield self.calendarUnderTest(home="user01"))
        calendar = Component.fromString(data1)
        yield calendar_collection.createCalendarObjectWithName("test.ics", calendar)
        yield self.commit()

        data2 = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VTODO
UID:12345-67890-attendee-reply
DTSTAMP:20080601T120000Z
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
SUMMARY:Changed
COMPLETED:20080601T140000Z
ORGANIZER;CN="User 01":mailto:[email protected]
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VTODO
END:VCALENDAR
"""

        calendar_resource = (yield self.calendarObjectUnderTest(name="test.ics", home="user01",))
        calendar = Component.fromString(data2)
        txn = self.transactionUnderTest()
        txn._authz_uid = "user01"
        yield calendar_resource.setComponent(calendar)
        yield self.commit()

        calendar_resource = (yield self.calendarObjectUnderTest(name="test.ics", home="user01",))
        calendar1 = (yield calendar_resource.component())
        calendar1 = str(calendar1).replace("\r\n ", "")
        self.assertTrue("ORGANIZER" in calendar1)
        self.assertTrue("ATTENDEE" in calendar1)
        self.assertTrue("SUMMARY:Changed" in calendar1)
        self.assertTrue("PARTSTAT=COMPLETED" in calendar1)
        yield self.commit()
开发者ID:anemitz,项目名称:calendarserver,代码行数:59,代码来源:test_implicit.py

示例15: test_testImplicitSchedulingPUT_FixScheduleState

# 需要导入模块: from twistedcaldav.ical import Component [as 别名]
# 或者: from twistedcaldav.ical.Component import fromString [as 别名]
    def test_testImplicitSchedulingPUT_FixScheduleState(self):
        """
        Test that testImplicitSchedulingPUT will fix an old cached schedule object state by
        re-evaluating the calendar data.
        """

        calendarOld = Component.fromString("""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTAMP:20080601T120000Z
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ORGANIZER;CN="User 01":mailto:[email protected]
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""")

        calendarNew = Component.fromString("""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTAMP:20080601T120000Z
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ORGANIZER;CN="User 01":mailto:[email protected]
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""")

        calendar_collection = (yield self.calendarUnderTest(home="user01"))
        calresource = (yield calendar_collection.createCalendarObjectWithName(
            "1.ics", calendarOld
        ))
        calresource.isScheduleObject = False

        scheduler = ImplicitScheduler()
        try:
            doAction, isScheduleObject = (yield scheduler.testImplicitSchedulingPUT(calendar_collection, calresource, calendarNew, False))
        except Exception as e:
            print e
            self.fail("Exception must not be raised")
        self.assertTrue(doAction)
        self.assertTrue(isScheduleObject)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:52,代码来源:test_implicit.py


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