本文整理汇总了Python中twistedcaldav.ical.Component类的典型用法代码示例。如果您正苦于以下问题:Python Component类的具体用法?Python Component怎么用?Python Component使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_objectresource_component
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)
示例2: migrate
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)
示例3: test_objectresource_objectwith
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)
示例4: test_oneEventCalendar
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)
示例5: test_vcalendar_no_effect
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)
示例6: doWork
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
示例7: doWork
def doWork(self):
"""
Do the export, stopping the reactor when done.
"""
try:
if self.options.inputDirectoryName:
dirname = self.options.inputDirectoryName
if not os.path.exists(dirname):
sys.stderr.write(
"Directory does not exist: {}\n".format(dirname)
)
sys.exit(1)
for filename in os.listdir(dirname):
fullpath = os.path.join(dirname, filename)
print("Importing {}".format(fullpath))
fileobj = open(fullpath, 'r')
component = Component.allFromStream(fileobj)
fileobj.close()
yield importCollectionComponent(self.store, component)
else:
try:
input = self.options.openInput()
except IOError, e:
sys.stderr.write(
"Unable to open input file for reading: %s\n" % (e)
)
sys.exit(1)
component = Component.allFromStream(input)
input.close()
yield importCollectionComponent(self.store, component)
except:
log.failure("doWork()")
示例8: test_objectresource_resourceuidforname
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)
示例9: test_listobjects
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)
示例10: init_perinstance_component
def init_perinstance_component():
peruser = Component(PerUserDataFilter.PERINSTANCE_COMPONENT)
rid = component.getRecurrenceIDUTC()
if rid:
peruser.addProperty(Property("RECURRENCE-ID", rid))
perinstance_components[rid] = peruser
return peruser
示例11: test_full
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())
)
示例12: test_setcomponent
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)
示例13: test_twoSimpleEvents
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)
示例14: test_full
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())
)
示例15: assertEqualCalendarData
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))