• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python base.PropertyName类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中txdav.base.propertystore.base.PropertyName的典型用法代码示例。如果您正苦于以下问题:Python PropertyName类的具体用法?Python PropertyName怎么用?Python PropertyName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: _processDefaultCalendarProperty

def _processDefaultCalendarProperty(home, propname):
    """
    Move the specified property value to the matching CALENDAR_HOME_METADATA table column.
    """

    inbox = (yield home.calendarWithName("inbox"))
    if inbox is not None:
        prop = inbox.properties().get(PropertyName.fromElement(propname))
        if prop is not None:
            defaultCalendar = str(prop.children[0])
            parts = defaultCalendar.split("/")
            if len(parts) == 5:

                calendarName = parts[-1]
                calendarHomeUID = parts[-2]
                if calendarHomeUID == home.uid():

                    calendar = (yield home.calendarWithName(calendarName))
                    if calendar is not None:
                        try:
                            yield home.setDefaultCalendar(
                                calendar, tasks=(propname == customxml.ScheduleDefaultTasksURL)
                            )
                        except InvalidDefaultCalendar:
                            # Ignore these - the server will recover
                            pass

            del inbox.properties()[PropertyName.fromElement(propname)]
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:28,代码来源:calendar_upgrade_from_3_to_4.py


示例2: _defaultAlarmUpgrade_check

    def _defaultAlarmUpgrade_check(self, changed_users, unchanged_users, detailshome, detailscalendar, detailsshared, shared_name):

        # Check each type of collection
        home = yield self.homeUnderTest(name="user01")
        version = (yield home.dataVersion())
        self.assertEqual(version, 4)
        for vevent, timed, alarm, prop in detailshome:
            alarm_result = (yield home.getDefaultAlarm(vevent, timed))
            self.assertEquals(alarm_result, alarm)
            self.assertTrue(PropertyName.fromElement(prop) not in home.properties())

        calendar = yield self.calendarUnderTest(name="calendar_1", home="user01")
        for vevent, timed, alarm, prop in detailscalendar:
            alarm_result = (yield calendar.getDefaultAlarm(vevent, timed))
            self.assertEquals(alarm_result, alarm)
            self.assertTrue(PropertyName.fromElement(prop) not in calendar.properties())

        if "user02" in changed_users:
            home = (yield self.homeUnderTest(name="user02"))
            version = (yield home.dataVersion())
            self.assertEqual(version, 4)
            shared = yield self.calendarUnderTest(name=shared_name, home="user02")
            for vevent, timed, alarm, prop in detailsshared:
                alarm_result = (yield shared.getDefaultAlarm(vevent, timed))
                self.assertEquals(alarm_result, alarm)
                self.assertTrue(PropertyName.fromElement(prop) not in shared.properties())
        else:
            home = (yield self.homeUnderTest(name="user02"))
            version = (yield home.dataVersion())
            self.assertEqual(version, 3)
            shared = yield self.calendarUnderTest(name=shared_name, home="user02")
            for vevent, timed, alarm, prop in detailsshared:
                alarm_result = (yield shared.getDefaultAlarm(vevent, timed))
                self.assertEquals(alarm_result, None)
                self.assertTrue(PropertyName.fromElement(prop) in shared.properties())
开发者ID:eventable,项目名称:CalendarServer,代码行数:35,代码来源:test_upgrade_from_3_to_4.py


示例3: test_defaultCalendarUpgrade

    def test_defaultCalendarUpgrade(self):

        # Set dead property on inbox
        for user in ("user01", "user02",):
            inbox = (yield self.calendarUnderTest(name="inbox", home=user))
            inbox.properties()[PropertyName.fromElement(ScheduleDefaultCalendarURL)] = ScheduleDefaultCalendarURL(HRef.fromString("/calendars/__uids__/%s/calendar_1" % (user,)))

            # Force current default to null
            home = (yield self.homeUnderTest(name=user))
            chm = home._homeMetaDataSchema
            yield Update(
                {chm.DEFAULT_EVENTS: None},
                Where=chm.RESOURCE_ID == home._resourceID,
            ).on(self.transactionUnderTest())

        # Force data version to previous
        ch = home._homeSchema
        yield Update(
            {ch.DATAVERSION: 3},
            Where=ch.RESOURCE_ID == home._resourceID,
        ).on(self.transactionUnderTest())

        yield self.commit()

        # Trigger upgrade
        yield moveDefaultCalendarProperties(self._sqlCalendarStore)

        # Test results
        for user in ("user01", "user02",):
            home = (yield self.homeUnderTest(name=user))
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            self.assertTrue(home.isDefaultCalendar(calendar))
            inbox = (yield self.calendarUnderTest(name="inbox", home=user))
            self.assertTrue(PropertyName.fromElement(ScheduleDefaultCalendarURL) not in inbox.properties())
开发者ID:anemitz,项目名称:calendarserver,代码行数:34,代码来源:test_upgrade_from_3_to_4.py


示例4: test_toString

    def test_toString(self):
        name = PropertyName("http://calendarserver.org/", "bleargh")

        self.assertEquals(
            name.toString(),
            "{http://calendarserver.org/}bleargh"
        )
开发者ID:eventable,项目名称:CalendarServer,代码行数:7,代码来源:test_base.py


示例5: test_migrateHomeFromFile

    def test_migrateHomeFromFile(self):
        """
        L{migrateHome} will migrate an L{IAddressbookHome} provider from one
        backend to another; in this specific case, from the file-based backend
        to the SQL-based backend.
        """
        fromHome = yield self.fileTransaction().addressbookHomeWithUID("home1")

        # Populate an arbitrary / unused dead properties so there's something
        # to verify against.

        key = PropertyName.fromElement(GETContentLanguage)
        fromHome.properties()[key] = GETContentLanguage("C")
        (yield fromHome.addressbookWithName("addressbook")).properties()[
            key] = (
            GETContentLanguage("pig-latin")
        )
        (yield fromHome.addressbookWithName("addressbook")).properties()[
            PropertyName.fromElement(ResourceType)] = (
            carddavxml.ResourceType.addressbook
        )
        toHome = yield self.transactionUnderTest().addressbookHomeWithUID(
            "new-home", create=True
        )
        yield migrateHome(fromHome, toHome, lambda x: x.component())
        toAddressbooks = yield toHome.addressbooks()
        self.assertEquals(set([c.name() for c in toAddressbooks]),
                          set([k for k in self.requirements['home1'].keys()
                               if self.requirements['home1'][k] is not None]))
        fromAddressbooks = yield fromHome.addressbooks()
        for c in fromAddressbooks:
            self.assertPropertiesSimilar(
                c, (yield toHome.addressbookWithName(c.name())),
            )
        self.assertPropertiesSimilar(fromHome, toHome,)
开发者ID:nunb,项目名称:calendarserver,代码行数:35,代码来源:test_sql.py


示例6: _calendarTranspUpgrade_check

    def _calendarTranspUpgrade_check(self, changed_users, unchanged_users):

        # Test results
        for user in changed_users:
            home = (yield self.homeUnderTest(name=user))
            version = (yield home.dataVersion())
            self.assertEqual(version, 4)
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            if user == "user01":
                self.assertTrue(calendar.isUsedForFreeBusy())
            else:
                self.assertFalse(calendar.isUsedForFreeBusy())
            self.assertTrue(PropertyName.fromElement(caldavxml.ScheduleCalendarTransp) not in calendar.properties())
            inbox = (yield self.calendarUnderTest(name="inbox", home=user))
            self.assertTrue(PropertyName.fromElement(CalendarFreeBusySet) not in inbox.properties())

        for user in unchanged_users:
            home = (yield self.homeUnderTest(name=user))
            version = (yield home.dataVersion())
            self.assertEqual(version, 3)
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            if user == "user01":
                self.assertFalse(calendar.isUsedForFreeBusy())
            else:
                self.assertFalse(calendar.isUsedForFreeBusy())
            self.assertTrue(PropertyName.fromElement(caldavxml.ScheduleCalendarTransp) in calendar.properties())
            inbox = (yield self.calendarUnderTest(name="inbox", home=user))
            self.assertTrue(PropertyName.fromElement(CalendarFreeBusySet) in inbox.properties())
开发者ID:redtailtech,项目名称:calendarserver,代码行数:28,代码来源:test_upgrade_from_3_to_4.py


示例7: initPropertyStore

 def initPropertyStore(self, props):
     # Setup peruser special properties
     props.setSpecialProperties(
         (PropertyName.fromElement(carddavxml.AddressBookDescription),),
         (PropertyName.fromElement(customxml.GETCTag),),
         (),
     )
开发者ID:redtailtech,项目名称:calendarserver,代码行数:7,代码来源:file.py


示例8: test_upgradeProperties

    def test_upgradeProperties(self):
        """
        L{UpgradeToDatabaseService.startService} will do the upgrade, then
        start its dependent service by adding it to its service hierarchy.
        """
        yield self.upgrader.stepWithResult(None)
        txn = self.sqlStore.newTransaction()
        self.addCleanup(txn.commit)

        # Want metadata preserved
        home = (yield txn.calendarHomeWithUID("home_defaults"))
        cal = (yield home.calendarWithName("calendar_1"))
        inbox = (yield home.calendarWithName("inbox"))

        # Supported components
        self.assertEqual(cal.getSupportedComponents(), "VEVENT")
        self.assertTrue(cal.properties().get(PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet)) is None)

        # Resource type removed
        self.assertTrue(cal.properties().get(PropertyName.fromElement(element.ResourceType)) is None)

        # Ctag removed
        self.assertTrue(cal.properties().get(PropertyName.fromElement(customxml.GETCTag)) is None)

        # Availability
        self.assertEquals(str(home.getAvailability()), str(self.av1))
        self.assertTrue(inbox.properties().get(PropertyName.fromElement(customxml.CalendarAvailability)) is None)

        # Default calendar
        self.assertTrue(home.isDefaultCalendar(cal))
        self.assertTrue(inbox.properties().get(PropertyName.fromElement(caldavxml.ScheduleDefaultCalendarURL)) is None)
开发者ID:eventable,项目名称:CalendarServer,代码行数:31,代码来源:test_migrate.py


示例9: setUp

    def setUp(self):
        """
        Set up two stores to migrate between.
        """
        # Add some files to the file store.

        self.filesPath = CachingFilePath(self.mktemp())
        self.filesPath.createDirectory()
        fileStore = self.fileStore = CommonDataStore(
            self.filesPath, {"push": StubNotifierFactory()}, TestStoreDirectoryService(), True, True
        )
        self.sqlStore = yield theStoreBuilder.buildStore(
            self, StubNotifierFactory()
        )
        self.upgrader = UpgradeToDatabaseStep(self.fileStore, self.sqlStore)

        requirements = CommonTests.requirements
        extras = deriveValue(self, "extraRequirements", lambda t: {})
        requirements = self.mergeRequirements(requirements, extras)

        yield populateCalendarsFrom(requirements, fileStore)
        md5s = CommonTests.md5s
        yield resetCalendarMD5s(md5s, fileStore)
        self.filesPath.child("calendars").child(
            "__uids__").child("ho").child("me").child("home1").child(
            ".some-extra-data").setContent("some extra data")

        requirements = ABCommonTests.requirements
        yield populateAddressBooksFrom(requirements, fileStore)
        md5s = ABCommonTests.md5s
        yield resetAddressBookMD5s(md5s, fileStore)
        self.filesPath.child("addressbooks").child(
            "__uids__").child("ho").child("me").child("home1").child(
            ".some-extra-data").setContent("some extra data")

        # Add some properties we want to check get migrated over
        txn = self.fileStore.newTransaction()
        home = yield txn.calendarHomeWithUID("home_defaults")

        cal = yield home.calendarWithName("calendar_1")
        props = cal.properties()
        props[PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet)] = caldavxml.SupportedCalendarComponentSet(
            caldavxml.CalendarComponent(name="VEVENT"),
            caldavxml.CalendarComponent(name="VTODO"),
        )
        props[PropertyName.fromElement(element.ResourceType)] = element.ResourceType(
            element.Collection(),
            caldavxml.Calendar(),
        )
        props[PropertyName.fromElement(customxml.GETCTag)] = customxml.GETCTag.fromString("foobar")

        inbox = yield home.calendarWithName("inbox")
        props = inbox.properties()
        props[PropertyName.fromElement(customxml.CalendarAvailability)] = customxml.CalendarAvailability.fromString(str(self.av1))
        props[PropertyName.fromElement(caldavxml.ScheduleDefaultCalendarURL)] = caldavxml.ScheduleDefaultCalendarURL(
            element.HRef.fromString("/calendars/__uids__/home_defaults/calendar_1"),
        )

        yield txn.commit()
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:59,代码来源:test_migrate.py


示例10: _calendarTimezoneUpgrade_setup

    def _calendarTimezoneUpgrade_setup(self):

        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        tz1 = Component(None, pycalendar=readVTZ("Etc/GMT+1"))
        tz2 = Component(None, pycalendar=readVTZ("Etc/GMT+2"))
        tz3 = Component(None, pycalendar=readVTZ("Etc/GMT+3"))

        # Share user01 calendar with user03
        calendar = (yield self.calendarUnderTest(name="calendar_1", home="user01"))
        home3 = yield self.homeUnderTest(name="user03")
        shared_name = yield calendar.shareWith(home3, _BIND_MODE_WRITE)

        user_details = (
            ("user01", "calendar_1", tz1),
            ("user02", "calendar_1", tz2),
            ("user03", "calendar_1", None),
            ("user03", shared_name, tz3),
        )

        # Set dead properties on calendars
        for user, calname, tz in user_details:
            calendar = (yield self.calendarUnderTest(name=calname, home=user))
            if tz:
                calendar.properties()[PropertyName.fromElement(caldavxml.CalendarTimeZone)] = caldavxml.CalendarTimeZone.fromString(str(tz))

            # Force data version to previous
            home = (yield self.homeUnderTest(name=user))
            ch = home._homeSchema
            yield Update(
                {ch.DATAVERSION: 4},
                Where=ch.RESOURCE_ID == home._resourceID,
            ).on(self.transactionUnderTest())

        yield self.commit()

        for user, calname, tz in user_details:
            calendar = (yield self.calendarUnderTest(name=calname, home=user))
            self.assertEqual(calendar.getTimezone(), None)
            self.assertEqual(PropertyName.fromElement(caldavxml.CalendarTimeZone) in calendar.properties(), tz is not None)
        yield self.commit()

        # Create "fake" entry for non-existent share
        txn = self.transactionUnderTest()
        calendar = (yield self.calendarUnderTest(name="calendar_1", home="user01"))
        rp = schema.RESOURCE_PROPERTY
        yield Insert(
            {
                rp.RESOURCE_ID: calendar._resourceID,
                rp.NAME: PropertyName.fromElement(caldavxml.CalendarTimeZone).toString(),
                rp.VALUE: caldavxml.CalendarTimeZone.fromString(str(tz3)).toxml(),
                rp.VIEWER_UID: "user04",
            }
        ).on(txn)
        yield self.commit()

        returnValue(user_details)
开发者ID:eventable,项目名称:CalendarServer,代码行数:58,代码来源:test_upgrade_from_4_to_5.py


示例11: _set_scheduleEtags

 def _set_scheduleEtags(self, value):
     if value:
         etags = [davxml.GETETag.fromString(etag) for etag in value]
         self.properties()[PropertyName.fromElement(customxml.TwistedScheduleMatchETags)] = customxml.TwistedScheduleMatchETags(*etags)
     else:
         try:
             del self.properties()[PropertyName.fromElement(customxml.TwistedScheduleMatchETags)]
         except KeyError:
             pass
开发者ID:anemitz,项目名称:calendarserver,代码行数:9,代码来源:file.py


示例12: moveCalendarAvailabilityProperties

def moveCalendarAvailabilityProperties(home):
    """
    Need to move all the CS:calendar-availability properties in the
    RESOURCE_PROPERTY table to the new CALENDAR_BIND table columns, extracting
    the new value from the XML property.
    """
    inbox = (yield home.calendarWithName("inbox"))
    if inbox is not None:
        prop = inbox.properties().get(PropertyName.fromElement(customxml.CalendarAvailability))
        if prop is not None:
            yield home.setAvailability(prop.calendar())
            del inbox.properties()[PropertyName.fromElement(customxml.CalendarAvailability)]
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:12,代码来源:calendar_upgrade_from_4_to_5.py


示例13: setDisplayName

    def setDisplayName(self, name):
        if name is None:
            del self.properties()[PropertyName.fromElement(DisplayName)]
        else:
            if not isinstance(name, unicode):
                raise ValueError("Display name must be unicode: %r" % (name,))

            self.properties()[
                PropertyName.fromElement(DisplayName)
            ] = DisplayName.fromString(name)

        return None
开发者ID:eventable,项目名称:CalendarServer,代码行数:12,代码来源:common.py


示例14: initPropertyStore

 def initPropertyStore(self, props):
     # Setup peruser special properties
     props.setSpecialProperties(
         (
             PropertyName.fromElement(caldavxml.CalendarDescription),
             PropertyName.fromElement(caldavxml.CalendarTimeZone),
         ),
         (
             PropertyName.fromElement(customxml.GETCTag),
             PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet),
         ),
     )
开发者ID:anemitz,项目名称:calendarserver,代码行数:12,代码来源:file.py


示例15: test_ImportComponentNoScheduling

    def test_ImportComponentNoScheduling(self):

        component = Component.allFromString(DATA_NO_SCHEDULING)
        yield importCollectionComponent(self.store, component)

        txn = self.store.newTransaction()
        home = yield txn.calendarHomeWithUID("user01")
        collection = yield home.childWithName("calendar")

        # Verify properties have been set
        collectionProperties = collection.properties()
        for element, value in (
            (davxml.DisplayName, "Sample Import Calendar"),
            (customxml.CalendarColor, "#0E61B9FF"),
        ):
            self.assertEquals(
                value,
                collectionProperties[PropertyName.fromElement(element)]
            )

        # Verify child objects
        objects = yield collection.listObjectResources()
        self.assertEquals(len(objects), 2)

        yield txn.commit()

        # Reimport different component into same collection

        component = Component.allFromString(DATA_NO_SCHEDULING_REIMPORT)

        yield importCollectionComponent(self.store, component)

        txn = self.store.newTransaction()
        home = yield txn.calendarHomeWithUID("user01")
        collection = yield home.childWithName("calendar")

        # Verify properties have been changed
        collectionProperties = collection.properties()
        for element, value in (
            (davxml.DisplayName, "Sample Import Calendar Reimported"),
            (customxml.CalendarColor, "#FFFFFFFF"),
        ):
            self.assertEquals(
                value,
                collectionProperties[PropertyName.fromElement(element)]
            )

        # Verify child objects (should be 3 now)
        objects = yield collection.listObjectResources()
        self.assertEquals(len(objects), 3)

        yield txn.commit()
开发者ID:eventable,项目名称:CalendarServer,代码行数:52,代码来源:test_importer.py


示例16: test_copy

    def test_copy(self):

        tempDir = FilePath(self.mktemp())
        tempDir.makedirs()
        tempFile1 = tempDir.child("test1")
        tempFile1.touch()
        tempFile2 = tempDir.child("test2")
        tempFile2.touch()

        # Existing store
        store1_user1 = PropertyStore("user01", lambda : tempFile1)
        store1_user2 = PropertyStore("user01", lambda : tempFile1)
        store1_user2._setPerUserUID("user02")

        # New store
        store2_user1 = PropertyStore("user01", lambda : tempFile2)
        store2_user2 = PropertyStore("user01", lambda : tempFile2)
        store2_user2._setPerUserUID("user02")

        # Populate current store with data
        class DummyProperty1(WebDAVTextElement):
            namespace = "http://calendarserver.org/ns/"
            name = "dummy1"
        class DummyProperty2(WebDAVTextElement):
            namespace = "http://calendarserver.org/ns/"
            name = "dummy2"
        class DummyProperty3(WebDAVTextElement):
            namespace = "http://calendarserver.org/ns/"
            name = "dummy3"

        props_user1 = (
            DummyProperty1.fromString("value1-user1"),
            DummyProperty2.fromString("value2-user1"),
        )
        props_user2 = (
            DummyProperty1.fromString("value1-user2"),
            DummyProperty3.fromString("value3-user2"),
        )

        for prop in props_user1:
            store1_user1[PropertyName.fromElement(prop)] = prop
        for prop in props_user2:
            store1_user2[PropertyName.fromElement(prop)] = prop
        store1_user1.flush()
        store1_user2.flush()

        # Do copy and check results
        store2_user1.copyAllProperties(store1_user1)
        store2_user1.flush()

        self.assertEqual(store1_user1.attrs.items(), store2_user1.attrs.items())
        self.assertEqual(store1_user2.attrs.items(), store2_user2.attrs.items())
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:52,代码来源:test_xattr.py


示例17: _removeOtherPropertiesUpgrade_check

    def _removeOtherPropertiesUpgrade_check(self, full=True):

        # Test results
        for user in ("user01", "user02",):
            if full:
                calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
                self.assertTrue(PropertyName.fromElement(element.ResourceID) not in calendar.properties())
                version = yield self.transactionUnderTest().calendarserverValue("CALENDAR-DATAVERSION")
                self.assertEqual(int(version), 5)
            else:
                calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
                self.assertTrue(PropertyName.fromElement(element.ResourceID) in calendar.properties())
                version = yield self.transactionUnderTest().calendarserverValue("CALENDAR-DATAVERSION")
                self.assertEqual(int(version), 4)
开发者ID:eventable,项目名称:CalendarServer,代码行数:14,代码来源:test_upgrade_from_4_to_5.py


示例18: _removeOtherPropertiesUpgrade_setup

    def _removeOtherPropertiesUpgrade_setup(self):

        # Set dead property on calendar
        for user in ("user01", "user02",):
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            calendar.properties()[PropertyName.fromElement(element.ResourceID)] = element.ResourceID(element.HRef("urn:uuid:%s" % (user,)))
        yield self.commit()

        for user in ("user01", "user02",):
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            self.assertTrue(PropertyName.fromElement(element.ResourceID) in calendar.properties())

        yield self.transactionUnderTest().updateCalendarserverValue("CALENDAR-DATAVERSION", "4")

        yield self.commit()
开发者ID:eventable,项目名称:CalendarServer,代码行数:15,代码来源:test_upgrade_from_4_to_5.py


示例19: _resourceTypeUpgrade_setup

    def _resourceTypeUpgrade_setup(self):

        # Set dead property on calendar
        for user in ("user01", "user02",):
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            calendar.properties()[PropertyName.fromElement(element.ResourceType)] = element.ResourceType(element.Collection())
        yield self.commit()

        for user in ("user01", "user02",):
            calendar = (yield self.calendarUnderTest(name="calendar_1", home=user))
            self.assertTrue(PropertyName.fromElement(element.ResourceType) in calendar.properties())

        yield self.transactionUnderTest().updateCalendarserverValue("CALENDAR-DATAVERSION", "3")

        yield self.commit()
开发者ID:eventable,项目名称:CalendarServer,代码行数:15,代码来源:test_upgrade_from_3_to_4.py


示例20: setData

    def setData(self, uid, notificationtype, notificationdata, inserting=False):

        rname = uid + ".xml"
        self._parentCollection.retrieveOldIndex().addOrUpdateRecord(
            NotificationRecord(uid, rname, notificationtype)
        )

        self._notificationdata = notificationdata
        notificationtext = json.dumps(self._notificationdata)
        md5 = hashlib.md5(notificationtext).hexdigest()

        def do():
            backup = None
            if self._path.exists():
                backup = hidden(self._path.temporarySibling())
                self._path.moveTo(backup)
            fh = self._path.open("w")
            try:
                # FIXME: concurrency problem; if this write is interrupted
                # halfway through, the underlying file will be corrupt.
                fh.write(notificationtext)
            finally:
                fh.close()
            def undo():
                if backup:
                    backup.moveTo(self._path)
                else:
                    self._path.remove()
            return undo
        self._transaction.addOperation(do, "set notification data %r" % (self.name(),))

        # Mark all properties as dirty, so they will be re-added to the
        # temporary file when the main file is deleted. NOTE: if there were a
        # temporary file and a rename() as there should be, this should really
        # happen after the write but before the rename.
        self.properties().update(self.properties())

        props = self.properties()
        props[PropertyName(*GETContentType.qname())] = GETContentType.fromString(generateContentType(MimeType("text", "xml", params={"charset": "utf-8"})))
        props[PropertyName.fromElement(NotificationType)] = NotificationType(json.dumps(notificationtype))
        props[PropertyName.fromElement(TwistedGETContentMD5)] = TwistedGETContentMD5.fromString(md5)

        # FIXME: the property store's flush() method may already have been
        # added to the transaction, but we need to add it again to make sure it
        # happens _after_ the new file has been written.  we may end up doing
        # the work multiple times, and external callers to property-
        # manipulation methods won't work.
        self._transaction.addOperation(self.properties().flush, "post-update property flush")
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:48,代码来源:file.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.dropboxIDFromCalendarObject函数代码示例发布时间:2022-05-27
下一篇:
Python project.Project类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap