Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def to_string(self):
     s = TxtParser.add_newlines(self.comment_raw)
     for l in self:
         # There is the need to check for the type: only the
         # TxtRecordEntry provides a (for this method) usable
         # output.
         if isinstance(l, TxtRecordEntry):
             s += l.to_string()
         else:
             # If this is another RecordEntry, at least get some
             # infos from this.
             s += TxtRecordEntry.format_entry(l)
     return s
Exemplo n.º 6
0
 def to_string(self):
     s = TxtParser.add_newlines(self.comment_raw)
     for l in self:
         # There is the need to check for the type: only the
         # TxtRecordEntry provides a (for this method) usable
         # output.
         if isinstance(l, TxtRecordEntry):
             s += l.to_string()
         else:
             # If this is another RecordEntry, at least get some
             # infos from this.
             s += TxtRecordEntry.format_entry(l)
     return s
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def to_string(self):
     """Return the entry as a string"""
     add_content = TxtParser.add_newlines(self.content_raw)
     add_comment = TxtParser.add_newlines(self.comment_raw)
     return self.tag_raw + add_content + add_comment
Exemplo n.º 10
0
 def to_string(self):
     """Return the entry as a string"""
     add_content = TxtParser.add_newlines(self.content_raw)
     add_comment = TxtParser.add_newlines(self.comment_raw)
     return self.tag_raw + add_content + add_comment
Exemplo n.º 11
0
 def to_string(self):
     add_content = TxtParser.add_newlines(self.content_raw)
     add_comment = TxtParser.add_newlines(self.comment_raw)
     r = self.tag_raw + add_content + add_comment
     return r