How to use the javaproperties.reading.Comment function in javaproperties

To help you get started, we’ve selected a few javaproperties examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwodder / javaproperties / javaproperties / reading.py View on Github external
liter = iter(ascii_splitlines(src))
    else:
        def lineiter():
            while True:
                line = src.readline()
                if isinstance(line, binary_type):
                    line = line.decode('iso-8859-1')
                if line == '':
                    return
                for ln in ascii_splitlines(line):
                    yield ln
        liter = lineiter()
    for source in liter:
        line = source
        if COMMENT_RGX.match(line):
            yield Comment(source)
            continue
        elif BLANK_RGX.match(line):
            yield Whitespace(source)
            continue
        line = line.lstrip(' \t\f').rstrip('\r\n')
        while CONTINUED_RGX.search(line):
            line = line[:-1]
            nextline = next(liter, '')
            source += nextline
            line += nextline.lstrip(' \t\f').rstrip('\r\n')
        if line == '':  # series of otherwise-blank lines with continuations
            yield Whitespace(source)
            continue
        m = SEPARATOR_RGX.search(line)
        if m:
            yield KeyValue(
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
def timestamp(self, value):
        if value is not None and value is not False:
            if not isinstance(value, six.string_types):
                value = java_timestamp(value)
            comments = [
                Comment(c) for c in ascii_splitlines(to_comment(value) + '\n')
            ]
        else:
            comments = []
        for n in self._lines.iternodes():
            if isinstance(n.value, Comment) and n.value.is_timestamp():
                if comments:
                    n.value = comments[0]
                    for c in comments[1:]:
                        n = n.insert_after(c)
                else:
                    n.unlink()
                return
            elif isinstance(n.value, KeyValue):
                for c in comments:
                    n.insert_before(c)
                return
        else:
            for c in comments:
                self._lines.append(c)
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
'Fri Feb 13 18:31:30 EST 2009'
        >>> print(pf.dumps(), end='')
        #This is a comment.
        #Fri Feb 13 18:31:30 EST 2009
        key = value
        zebra: apple
        >>> del pf.timestamp
        >>> pf.timestamp is None
        True
        >>> print(pf.dumps(), end='')
        #This is a comment.
        key = value
        zebra: apple
        """
        for elem in self._lines:
            if isinstance(elem, Comment) and elem.is_timestamp():
                return elem.value
            elif isinstance(elem, KeyValue):
                return None
        return None