示例#1
0
    def parse(self, record, rid):
        """Parse everything from a string"""
        # Split up into lines
        Encoding.check_unicode(record)
        split_lines = record.split("\n")
        self.check_line_length(split_lines, rid)
        self.maybe_remove_last_empty_line(split_lines)
        self.comment_raw = TxtParser.extract_record_comment(split_lines)
        for comment in self.comment_raw:
            Encoding.check_unicode(comment)
        self.set_comment(TxtParser.extract_comment(self.comment_raw))
        Encoding.check_unicode(self.get_comment())

        success, parsed_record = TxtParser.split_entries(
            split_lines, rid, self,
            len(self.comment_raw) + 1)
        # If there was an error during the split already - stop
        # processing here
        if not success:
            self._set_not_usable()
            return

        for i in parsed_record:
            self.append(TxtRecordEntry(i))
        return
示例#2
0
 def __setup(self, se):
     '''Store the raw input for possible later output.'''
     self.tag_raw = se[0]
     self.content_raw = se[1]
     self.comment_raw = se[2]
     # Parse the rest
     tag = self.tag_raw[0:-1]
     value = "".join(se[1])
     comment = TxtParser.extract_comment(se[2])
     RecordEntry.__init__(self, tag, value, comment)
示例#3
0
 def __init__(self, se):
     '''There must be three entries:
        1) initial line with tag
        2) possible empty list of continue lines (starting with space)
        3) possible empty list of comment and / or empty lines.
     '''
     assert len(se) == 3
     Encoding.check_unicode(se[0])
     self.tag_raw = se[0]
     Encoding.check_unicode_list(se[1])
     self.content_raw = se[1]
     Encoding.check_unicode_list(se[2])
     self.comment_raw = se[2]
     # Parse the rest
     tag = self.tag_raw[0:-1]
     value = "".join(se[1])
     comment = TxtParser.extract_comment(se[2])
     RecordEntry.__init__(self, tag, value, comment)
示例#4
0
 def __init__(self, se):
     '''There must be three entries:
        1) initial line with tag
        2) possible empty list of continue lines (starting with space)
        3) possible empty list of comment and / or empty lines.
     '''
     assert len(se) == 3
     Encoding.check_unicode(se[0])
     self.tag_raw = se[0]
     Encoding.check_unicode_list(se[1])
     self.content_raw = se[1]
     Encoding.check_unicode_list(se[2])
     self.comment_raw = se[2]
     # Parse the rest
     tag = self.tag_raw[0:-1]
     value = "".join(se[1])
     comment = TxtParser.extract_comment(se[2])
     RecordEntry.__init__(self, tag, value, comment)
示例#5
0
    def parse(self, s, rid):
        # Split up into lines
        sl = s.split("\n")
        self.check_line_length(sl, rid)
        self.maybe_remove_last_empty_line(sl)
        self.comment_raw = TxtParser.extract_record_comment(sl)
        self.set_comment(TxtParser.extract_comment(self.comment_raw))

        success, rp = TxtParser.split_entries(sl, rid, self, len(self.comment_raw) + 1)
        # If there was an error during the split already - stop
        # processing here
        if not success:
            self.set_unusable()
            return

        for i in rp:
            self.append(TxtRecordEntry(i))
        return
示例#6
0
    def parse(self, s, rid):
        # Split up into lines
        sl = s.split("\n")
        self.check_line_length(sl, rid)
        self.maybe_remove_last_empty_line(sl)
        self.comment_raw = TxtParser.extract_record_comment(sl)
        self.set_comment(TxtParser.extract_comment(self.comment_raw))

        success, rp = TxtParser.split_entries(sl, rid, self,
                                              len(self.comment_raw) + 1)
        # If there was an error during the split already - stop
        # processing here
        if not success:
            self._set_not_usable()
            return

        for i in rp:
            self.append(TxtRecordEntry(i))
        return