How to use the javaproperties.reading.KeyValue 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
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(
                unescape(line[:m.start(1)]),
                unescape(line[m.end():]),
                source,
            )
        else:
            yield KeyValue(unescape(line), '', source)
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
#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
github jwodder / javaproperties / javaproperties / reading.py View on Github external
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(
                unescape(line[:m.start(1)]),
                unescape(line[m.end():]),
                source,
            )
        else:
            yield KeyValue(unescape(line), '', source)
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
lastsrc = lastline.source
                    if isinstance(lastline, KeyValue):
                        lastsrc = CONTINUED_RGX.sub(r'\1', lastsrc)
                    if not lastsrc.endswith(('\r', '\n')):
                        lastsrc += '\n'
                    self._lines.end.value = lastline._replace(source=lastsrc)
            n = self._lines.append(None)
        else:
            # Update the first occurrence of the key and discard the rest.
            # This way, the order in which the keys are listed in the file and
            # dict will be preserved.
            n = nodes.pop(0)
            for n2 in nodes:
                n2.unlink()
        self._key2nodes[key] = [n]
        n.value = KeyValue(key, value, None)
github jwodder / javaproperties / javaproperties / reading.py View on Github external
return the value returned by ``object_pairs_hook``.

    .. versionchanged:: 0.5.0
        Invalid ``\\uXXXX`` escape sequences will now cause an
        `InvalidUEscapeError` to be raised

    :param fp: the file from which to read the ``.properties`` document
    :type fp: file-like object
    :param callable object_pairs_hook: class or function for combining the
        key-value pairs
    :rtype: `dict` of text strings or the return value of ``object_pairs_hook``
    :raises InvalidUEscapeError: if an invalid ``\\uXXXX`` escape sequence
        occurs in the input
    """
    return object_pairs_hook(
        (kv.key, kv.value) for kv in parse(fp) if isinstance(kv, KeyValue)
    )
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
def _comparable(self):
        return [
            (n.value.key, n.value.value)
                if isinstance(n.value, KeyValue)
                else (None, n.value.source)
            for n in self._lines.iternodes()
            ### TODO: Also include non-final repeated keys???
            if not isinstance(n.value, KeyValue)
                or n is self._key2nodes[n.value.key][-1]
        ]