本文整理汇总了Python中pycalendar.icalendar.calendar.Calendar.parseComponent方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.parseComponent方法的具体用法?Python Calendar.parseComponent怎么用?Python Calendar.parseComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycalendar.icalendar.calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.parseComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TimezoneDatabase
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import parseComponent [as 别名]
#.........这里部分代码省略.........
@staticmethod
def getTimezoneDescriptor(tzid, dt):
# Cache it first
tz = TimezoneDatabase.getTimezone(tzid)
if tz is not None:
return tz.getTimezoneDescriptor(dt)
else:
return ""
@staticmethod
def isStandardTimezone(tzid):
return TimezoneDatabase.getTimezoneDatabase()._isStandardTimezone(tzid)
def cacheTimezone(self, tzid):
"""
Load the specified timezone identifier's timezone data from a file and parse it
into the L{Calendar} used to store timezones used by this object.
@param tzid: the timezone identifier to load
@type tzid: L{str}
"""
if self.dbpath is None:
return
tzpath = os.path.join(self.dbpath, "%s.ics" % (tzid,))
tzpath = os.path.normpath(tzpath)
if tzpath.startswith(self.dbpath) and os.path.isfile(tzpath):
try:
with open(tzpath) as f:
self.calendar.parseComponent(f)
except (IOError, InvalidData):
raise NoTimezoneInDatabase(self.dbpath, tzid)
else:
raise NoTimezoneInDatabase(self.dbpath, tzid)
def addTimezone(self, tz):
"""
Add the specified VTIMEZONE component to this object's L{Calendar} cache. This component
is assumed to be a non-standard timezone - i.e., not loaded from the timezone database.
@param tz: the VTIMEZONE component to add
@type tz: L{Component}
"""
copy = tz.duplicate(self.calendar)
self.calendar.addComponent(copy)
self.tzcache[copy.getID()] = copy
def _addStandardTimezone(self, tz):
"""
Same as L{addTimezone} except that the timezone is marked as a standard timezone. This
is only meant to be used for testing which happens int he absence of a real standard
timezone database.
@param tz: the VTIMEZONE component to add
@type tz: L{Component}
"""
if tz.getID() not in self.tzcache:
self.addTimezone(tz)
self.stdtzcache.add(tz.getID())
示例2: testParseComponent
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import parseComponent [as 别名]
def testParseComponent(self):
data1 = """BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//mulberrymail.com//Mulberry v4.0//EN
BEGIN:VEVENT
UID:C3184A66-1ED0-11D9-A5E0-000A958A3252
DTSTART;VALUE=DATE:20020101
DTEND;VALUE=DATE:20020102
DTSTAMP:20020101T000000Z
RRULE:FREQ=YEARLY;UNTIL=20031231;BYMONTH=1
SUMMARY:New Year's Day
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")
data2 = """BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//Example Inc.//Example Calendar//EN
BEGIN:VTIMEZONE
TZID:America/Montreal
LAST-MODIFIED:20040110T032845Z
BEGIN:DAYLIGHT
DTSTART:20000404T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
TZNAME:EDT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
BEGIN:STANDARD
DTSTART:20001026T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:EST
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
""".replace("\n", "\r\n")
result = """BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//mulberrymail.com//Mulberry v4.0//EN
BEGIN:VTIMEZONE
TZID:America/Montreal
LAST-MODIFIED:20040110T032845Z
BEGIN:DAYLIGHT
DTSTART:20000404T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
TZNAME:EDT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
BEGIN:STANDARD
DTSTART:20001026T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:EST
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:C3184A66-1ED0-11D9-A5E0-000A958A3252
DTSTART;VALUE=DATE:20020101
DTEND;VALUE=DATE:20020102
DTSTAMP:20020101T000000Z
RRULE:FREQ=YEARLY;UNTIL=20031231;BYMONTH=1
SUMMARY:New Year's Day
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")
cal = Calendar()
cal.parse(StringIO.StringIO(data1))
cal.parseComponent(StringIO.StringIO(data2))
self.assertEqual(str(cal), result)