Example #1
0
 def __init__(self):
     super().__init__('CountFormat', None)
     for level in range(3):
         name = '{0}{1}'.format(DescendantCountFormat.countFieldName,
                                level + 1)
         field = fieldformat.DescendantCountField(name, level + 1)
         self.fieldDict[name] = field
Example #2
0
    def parseField(self, text):
        """Parse text field, return field type or plain text if not a field.

        Arguments:
            text -- the raw format text (could be a field)
        """
        fieldMatch = _fieldPartRe.match(text)
        if fieldMatch:
            modifier = fieldMatch.group(1)
            fieldName = fieldMatch.group(2)
            try:
                if not modifier:
                    return self.fieldDict[fieldName]
                elif modifier == '*' * len(modifier):
                    return fieldformat.AncestorLevelField(fieldName,
                                                          len(modifier))
                elif modifier == '?':
                    return fieldformat.AnyAncestorField(fieldName)
                elif modifier == '&':
                    return fieldformat.ChildListField(fieldName)
                elif modifier == '#':
                    match = _levelFieldRe.match(fieldName)
                    if match and match.group(1) != '0':
                        level = int(match.group(1))
                        return fieldformat.DescendantCountField(fieldName,
                                                                level)
                elif modifier == '!':
                    return (self.parentFormats.fileInfoFormat.
                            fieldDict[fieldName])
            except KeyError:
                pass
        return text