def extractUnrecognized(parent_component, child):
    """
    Extract unrecognized, content lines, and parameters from a vevent, also
    store top level components from the whole calendar in cases that look like
    CalDAV.
    
    If the object has more than one icalUID, it's not a CalDAV icalendar file,
    so don't waste space on potentially hundreds of items by storing top-level
    unrecognized data for each item.
    
    Return either None, or a vobject, which is a fragment of an icalendar file,
    containing lines and components that weren't recognized.  If a line is
    recognized but a parameter isn't, a line with parameters byt no value will
    be output.
    
    This strategy may fall on its face for duplicated lines that are recognized 
    but with different, unrecognized parameters, but that seems like an unlikely
    edge case.
    
    Tasks currently aren't handled for fear of oddities when vevents
    are converted into vtodos.
    
    """
    # don't create a new component unless it's needed
    out = unrecognizedData(parent_component, child)

    # only handle top level lines and components if child is a vevent, and
    # parent_component's vevent children's uids all match
    if child.name.lower() == 'vevent':
        uid = child.getChildValue('uid').upper()
        for vevent in parent_component.contents.get('vevent', Empty):
            if vevent.getChildValue('uid').upper() != uid:
                break
        else:  # reminder: else-after-for executes if the for-loop wasn't broken
            for key, top_child in parent_component.contents.iteritems():
                if key.lower() not in top_level_understood:
                    out.getComponent().contents[key] = top_child
                else:
                    # not saving parameters of recognized top level lines
                    pass

    for line in child.lines():
        name = line.name.lower()
        if name not in attributesUnderstood:
            line.transformFromNative()
            out.getChild().contents.setdefault(name, []).append(line)
        else:
            paramPairs = []
            for key, paramvals in line.params.iteritems():
                if key.lower() not in parametersUnderstood:
                    paramPairs.append((key, paramvals))
            if paramPairs:
                newLine = ContentLine(line.name, [], '')
                newLine.params = dict(paramPairs)
                out.getChild().contents.setdefault(name, []).append(newLine)

    # we could recurse and process child's component children, which would get
    # things like custom lines in VALARMs, but for now, don't bother

    return out.newComponent
Exemple #2
0
def extractUnrecognized(parent_component, child):
    """
    Extract unrecognized, content lines, and parameters from a vevent, also
    store top level components from the whole calendar in cases that look like
    CalDAV.
    
    If the object has more than one icalUID, it's not a CalDAV icalendar file,
    so don't waste space on potentially hundreds of items by storing top-level
    unrecognized data for each item.
    
    Return either None, or a vobject, which is a fragment of an icalendar file,
    containing lines and components that weren't recognized.  If a line is
    recognized but a parameter isn't, a line with parameters byt no value will
    be output.
    
    This strategy may fall on its face for duplicated lines that are recognized 
    but with different, unrecognized parameters, but that seems like an unlikely
    edge case.
    
    Tasks currently aren't handled for fear of oddities when vevents
    are converted into vtodos.
    
    """
    # don't create a new component unless it's needed
    out = unrecognizedData(parent_component, child)
    
    # only handle top level lines and components if child is a vevent, and
    # parent_component's vevent children's uids all match
    if child.name.lower() == 'vevent':
        uid = child.getChildValue('uid').upper()
        for vevent in parent_component.contents.get('vevent', Empty):
            if vevent.getChildValue('uid').upper() != uid:
                break
        else: # reminder: else-after-for executes if the for-loop wasn't broken
            for key, top_child in parent_component.contents.iteritems():
                if key.lower() not in top_level_understood:
                    out.getComponent().contents[key] = top_child
                else:
                    # not saving parameters of recognized top level lines
                    pass
                
    for line in child.lines():
        name = line.name.lower()
        if name not in attributesUnderstood:
            line.transformFromNative()
            out.getChild().contents.setdefault(name, []).append(line)
        else:
            paramPairs = []
            for key, paramvals in line.params.iteritems():
                if key.lower() not in parametersUnderstood:
                    paramPairs.append((key, paramvals))
            if paramPairs:
                newLine = ContentLine(line.name, [], '')
                newLine.params = dict(paramPairs)
                out.getChild().contents.setdefault(name, []).append(newLine)

    # we could recurse and process child's component children, which would get
    # things like custom lines in VALARMs, but for now, don't bother
    
    return out.newComponent
Exemple #3
0
 def set_description(self, description):
     raw_event = self.vevent.instance.contents["vevent"][0]
     self.description = description
     encoded = encode_quopri(description)
     if DESCRIPTION_KEY not in raw_event.contents:
         raw_event.contents[DESCRIPTION_KEY] = [
             ContentLine(DESCRIPTION_KEY,
                         {"ENCODING": ["QUOTED-PRINTABLE"]}, encoded)
         ]
     else:
         content_line = raw_event.contents[DESCRIPTION_KEY][0]
         content_line.value = encoded
         content_line.params["ENCODING"] = ["QUOTED-PRINTABLE"]
Exemple #4
0
    def test_periodBehavior(self):
        line = ContentLine('test', [], '', isNative=True)
        line.behavior = PeriodBehavior
        line.value = [(datetime.datetime(2006, 2, 16, 10), twoHours)]

        self.assertEqual(line.transformFromNative().value,
                         '20060216T100000/PT2H')
        self.assertEqual(line.transformToNative().value, [(datetime.datetime(
            2006, 2, 16, 10, 0), datetime.timedelta(0, 7200))])

        line.value.append((datetime.datetime(2006, 5, 16, 10), twoHours))

        self.assertEqual(line.serialize().strip(),
                         'TEST:20060216T100000/PT2H,20060516T100000/PT2H')
Exemple #5
0
    def test_periodBehavior(self):
        line = ContentLine('test', [], '', isNative=True)
        line.behavior = PeriodBehavior
        line.value = [(datetime.datetime(2006, 2, 16, 10), twoHours)]

        self.assertEqual(
            line.transformFromNative().value,
            '20060216T100000/PT2H'
        )
        self.assertEqual(
            line.transformToNative().value,
            [(datetime.datetime(2006, 2, 16, 10, 0), datetime.timedelta(0, 7200))]
        )

        line.value.append((datetime.datetime(2006, 5, 16, 10), twoHours))

        self.assertEqual(
            line.serialize().strip(),
            'TEST:20060216T100000/PT2H,20060516T100000/PT2H'
        )