Пример #1
0
 def test_MultiDateBehavior(self):
     parseRDate = MultiDateBehavior.transformToNative
     self.assertEqual(
         str(parseRDate(textLineToContentLine("RDATE;VALUE=DATE:19970304,19970504,19970704,19970904"))),
         "<RDATE{'VALUE': ['DATE']}[datetime.date(1997, 3, 4), datetime.date(1997, 5, 4), datetime.date(1997, 7, 4), datetime.date(1997, 9, 4)]>"
     )
     self.assertEqual(
         str(parseRDate(textLineToContentLine("RDATE;VALUE=PERIOD:19960403T020000Z/19960403T040000Z,19960404T010000Z/PT3H"))),
         "<RDATE{'VALUE': ['PERIOD']}[(datetime.datetime(1996, 4, 3, 2, 0, tzinfo=tzutc()), datetime.datetime(1996, 4, 3, 4, 0, tzinfo=tzutc())), (datetime.datetime(1996, 4, 4, 1, 0, tzinfo=tzutc()), datetime.timedelta(0, 10800))]>"
     )
Пример #2
0
 def test_MultiDateBehavior(self):
     """
     Test MultiDateBehavior
     """
     parseRDate = MultiDateBehavior.transformToNative
     self.assertEqual(
         str(parseRDate(textLineToContentLine("RDATE;VALUE=DATE:19970304,19970504,19970704,19970904"))),
         "<RDATE{'VALUE': ['DATE']}[datetime.date(1997, 3, 4), datetime.date(1997, 5, 4), datetime.date(1997, 7, 4), datetime.date(1997, 9, 4)]>"
     )
     self.assertEqual(
         str(parseRDate(textLineToContentLine("RDATE;VALUE=PERIOD:19960403T020000Z/19960403T040000Z,19960404T010000Z/PT3H"))),
         "<RDATE{'VALUE': ['PERIOD']}[(datetime.datetime(1996, 4, 3, 2, 0, tzinfo=tzutc()), datetime.datetime(1996, 4, 3, 4, 0, tzinfo=tzutc())), (datetime.datetime(1996, 4, 4, 1, 0, tzinfo=tzutc()), datetime.timedelta(0, 10800))]>"
     )
Пример #3
0
 def test_parseDTStart(self):
     """
     Should take a content line and return a datetime object.
     """
     self.assertEqual(
         parseDtstart(textLineToContentLine("DTSTART:20060509T000000")),
         datetime.datetime(2006, 5, 9, 0, 0))
Пример #4
0
 def test_parseDTStart(self):
     """
     Should take a content line and return a datetime object.
     """
     self.assertEqual(
         parseDtstart(textLineToContentLine("DTSTART:20060509T000000")),
         datetime.datetime(2006, 5, 9, 0, 0)
     )
Пример #5
0
def readAlarmRecord(view, alarmRecord, vobjs):
    vobj = getVobj(alarmRecord, vobjs)
    if alarmRecord.trigger not in translator.emptyValues:
        valarm = vobj.add('valarm')
        try:
            val = translator.fromICalendarDateTime(view, alarmRecord.trigger)[0]
            valarm.add('trigger').value = val
        except:
            valarm.trigger = textLineToContentLine("TRIGGER:" + 
                                                   alarmRecord.trigger)
        if alarmRecord.description not in translator.emptyValues:
            valarm.add('description').value = alarmRecord.description
        if alarmRecord.repeat not in translator.emptyValues:
            valarm.add('repeat').value = str(alarmRecord.repeat)
        if alarmRecord.duration not in translator.emptyValues:
            valarm.add('repeat').value = str(alarmRecord.duration)
            valarm.repeat.isNative = False
Пример #6
0
def readAlarmRecord(view, alarmRecord, vobjs):
    vobj = getVobj(alarmRecord, vobjs)
    if alarmRecord.trigger not in translator.emptyValues:
        valarm = vobj.add('valarm')
        try:
            val = translator.fromICalendarDateTime(view,
                                                   alarmRecord.trigger)[0]
            valarm.add('trigger').value = val
        except:
            valarm.trigger = textLineToContentLine("TRIGGER:" +
                                                   alarmRecord.trigger)
        if alarmRecord.description not in translator.emptyValues:
            valarm.add('description').value = alarmRecord.description
        if alarmRecord.repeat not in translator.emptyValues:
            valarm.add('repeat').value = str(alarmRecord.repeat)
        if alarmRecord.duration not in translator.emptyValues:
            valarm.add('repeat').value = str(alarmRecord.duration)
            valarm.repeat.isNative = False
Пример #7
0
def fromICalendarDateTime(text, multivalued=False):
    prefix = 'dtstart' # arbitrary
    if not text.startswith(';') and not text.startswith(':'):
        # no parameters
        prefix += ':'
    line = textLineToContentLine(prefix + text)
    if multivalued:
        line.behavior = MultiDateBehavior
    else:
        line.behavior = DateOrDateTimeBehavior
    line.transformToNative()
    anyTime = getattr(line, 'x_osaf_anytime_param', "").upper() == 'TRUE'
    allDay = False
    start = line.value
    if not multivalued:
        start = [start]
    if type(start[0]) == datetime.date:
        allDay = not anyTime
        start = [force_datetime(dt) for dt in start]
    else:
        tzid = line.params.get('X-VOBJ-ORIGINAL-TZID')
        if tzid is None:
            # RDATEs and EXDATEs won't have an X-VOBJ-ORIGINAL-TZID
            tzid = getattr(line, 'tzid_param', None)
        if start[0].tzinfo == du_utc:
            tzinfo = TimeZone.utc
        elif tzid is None:
            tzinfo = TimeZone.floating
        else:
            # this parameter was broken, fixed in vobject 0.6.6, handle either
            # a string or take the first element of a list
            if not isinstance(tzid, basestring):
                tzid = tzid[0]
            tzinfo = TimeZone[tzid]
        start = [dt.replace(tzinfo=tzinfo) for dt in start]
    if not multivalued:
        start = start[0]
    return (start, allDay, anyTime)
Пример #8
0
def readEventRecord(view, eventRecord, vobjs):
    vevent = getVobj(eventRecord, vobjs)
    master = None

    uuid, recurrenceID = translator.splitUUID(view, eventRecord.uuid)
    if recurrenceID is not None:
        master = vobjs[uuid]
        m_start = master.dtstart
        anyTime = False
        if getattr(m_start, 'value_param', '') == 'DATE':
            recurrenceID = recurrenceID.date()
            anyTime = (getattr(m_start, 'x_osaf_anytime_param', '') == 'TRUE')
        elif recurrenceID.tzinfo == view.tzinfo.floating:
            recurrenceID = recurrenceID.replace(tzinfo=None)
        elif recurrenceID.tzinfo == view.tzinfo.UTC:
            # convert UTC recurrence-id (which is legal, but unusual in
            # iCalendar) to the master's dtstart timezone
            tzid = getattr(m_start, 'tzid_param', None)
            if tzid is not None:
                tzinfo = view.tzinfo.getInstance(tzid)
                recurrenceID = recurrenceID.astimezone(tzinfo)
        vevent.add('recurrence-id').value = recurrenceID

    if eventRecord.dtstart in translator.emptyValues:
        if recurrenceID is not None:
            dtstart = vevent.add('dtstart')
            dtstart.value = recurrenceID
            if anyTime:
                dtstart.x_osaf_anytime_param = "TRUE"
    else:
        vevent.dtstart = textLineToContentLine("DTSTART" + eventRecord.dtstart)
        pruneDateTimeParam(vevent.dtstart)
        registerTZID(view, vevent.dtstart)

    for name in ['duration', 'status', 'location']:
        eimValue = getattr(eventRecord, name)
        if eimValue not in translator.emptyValues:
            line = vevent.add(name)
            line.value = eimValue
            line.isNative = False

    if hasattr(vevent, 'duration'):
        vevent.duration.value = vevent.duration.value.upper()
    elif recurrenceID:
        vevent.add('duration').value = master.duration.value
        vevent.duration.isNative = False

    timestamp = datetime.utcnow()
    vevent.add('dtstamp').value = timestamp.replace(tzinfo=view.tzinfo.UTC)
    # rruleset
    for rule_name in ('rrule', 'exrule'):
        rules = []
        record_value = getattr(eventRecord, rule_name)
        if record_value not in translator.emptyValues:
            for rule_value in record_value.split(':'):
                rule_value = freq_first(rule_value)
                # EIM concatenates multiple rules with :
                rules.append(
                    textLineToContentLine(rule_name + ":" + rule_value))
        vevent.contents[rule_name] = rules

    for date_name in ('rdate', 'exdate'):
        record_value = getattr(eventRecord, date_name)
        if record_value not in translator.emptyValues:
            # multiple dates should always be on one line
            setattr(vevent, date_name,
                    textLineToContentLine(date_name + record_value))
            pruneDateTimeParam(getattr(vevent, date_name))
Пример #9
0
def readEventRecord(view, eventRecord, vobjs):
    vevent = getVobj(eventRecord, vobjs)
    master = None
    
    uuid, recurrenceID = translator.splitUUID(view, eventRecord.uuid)
    if recurrenceID is not None:
        master = vobjs[uuid]
        m_start = master.dtstart
        anyTime = False
        if getattr(m_start, 'value_param', '') == 'DATE':
            recurrenceID = recurrenceID.date()
            anyTime = (getattr(m_start, 'x_osaf_anytime_param', '') == 'TRUE')
        elif recurrenceID.tzinfo == view.tzinfo.floating:
            recurrenceID = recurrenceID.replace(tzinfo=None)
        elif recurrenceID.tzinfo == view.tzinfo.UTC:
            # convert UTC recurrence-id (which is legal, but unusual in
            # iCalendar) to the master's dtstart timezone
            tzid = getattr(m_start, 'tzid_param', None)
            if tzid is not None:
                tzinfo = view.tzinfo.getInstance(tzid)
                recurrenceID = recurrenceID.astimezone(tzinfo)
        vevent.add('recurrence-id').value = recurrenceID
        
    if eventRecord.dtstart in translator.emptyValues:
        if recurrenceID is not None:
            dtstart = vevent.add('dtstart')
            dtstart.value = recurrenceID
            if anyTime:
                dtstart.x_osaf_anytime_param = "TRUE"
    else:
        vevent.dtstart = textLineToContentLine("DTSTART" +
                                               eventRecord.dtstart)
        pruneDateTimeParam(vevent.dtstart)
        registerTZID(view, vevent.dtstart)

    for name in ['duration', 'status', 'location']:
        eimValue = getattr(eventRecord, name)
        if eimValue not in translator.emptyValues:
            line = vevent.add(name)
            line.value = eimValue
            line.isNative = False

    if hasattr(vevent, 'duration'):
        vevent.duration.value = vevent.duration.value.upper()
    elif recurrenceID:
        vevent.add('duration').value = master.duration.value
        vevent.duration.isNative = False
        
    timestamp = datetime.utcnow()
    vevent.add('dtstamp').value = timestamp.replace(tzinfo=view.tzinfo.UTC)
    # rruleset
    for rule_name in ('rrule', 'exrule'):
        rules = []
        record_value = getattr(eventRecord, rule_name)
        if record_value not in translator.emptyValues:
            for rule_value in record_value.split(':'):
                rule_value = freq_first(rule_value)
                # EIM concatenates multiple rules with :
                rules.append(textLineToContentLine(rule_name + ":" + rule_value))
        vevent.contents[rule_name] = rules

    for date_name in ('rdate', 'exdate'):
        record_value = getattr(eventRecord, date_name)
        if record_value not in translator.emptyValues:
            # multiple dates should always be on one line
            setattr(vevent, date_name, 
                    textLineToContentLine(date_name + record_value))
            pruneDateTimeParam(getattr(vevent, date_name))