How to use the javaproperties.writing.join_key_value 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 / __main__.py View on Github external
def select(ctx, default_value, defaults, escaped, separator, file, key,
           encoding, outfile):
    """ Extract key-value pairs from a Java .properties file """
    ok = True
    with click.open_file(outfile, 'w', encoding=encoding) as fpout:
        print(to_comment(java_timestamp()), file=fpout)
        for k,v in getselect(file, key, defaults, default_value, encoding,
                             escaped):
            if v is None:
                click.echo(u'javaproperties: {0}: key not found'.format(k),
                           err=True)
                ok = False
            else:
                print(join_key_value(k, v, separator=separator), file=fpout)
    ctx.exit(0 if ok else 1)
github jwodder / javaproperties / javaproperties / __main__.py View on Github external
prevsrc = src
                continue
            else:
                if prevsrc is not None:
                    if preserve_timestamp:
                        print(prevsrc, end='', file=fpout)
                    else:
                        if not re.match(TIMESTAMP_RGX, prevsrc, flags=re.U):
                            print(prevsrc, end='', file=fpout)
                        print(to_comment(java_timestamp()), file=fpout)
                elif not preserve_timestamp:
                    print(to_comment(java_timestamp()), file=fpout)
                in_header = False
        if k in newprops:
            if newprops[k] is not None:
                print(join_key_value(k, newprops[k], separator=separator),
                      file=fpout)
                newprops[k] = None
        else:
            # In case the last line of the file ends with a trailing line
            # continuation:
            src = re.sub(r'(?
github jwodder / javaproperties / javaproperties / __main__.py View on Github external
elif not preserve_timestamp:
                    print(to_comment(java_timestamp()), file=fpout)
                in_header = False
        if k in newprops:
            if newprops[k] is not None:
                print(join_key_value(k, newprops[k], separator=separator),
                      file=fpout)
                newprops[k] = None
        else:
            # In case the last line of the file ends with a trailing line
            # continuation:
            src = re.sub(r'(?
github jwodder / javaproperties / javaproperties / propfile.py View on Github external
Serializing a `PropertiesFile` instance with the :func:`dump()`
            function instead will cause all formatting information to be
            ignored, as :func:`dump()` will treat the instance like a normal
            mapping.

        :param fp: A file-like object to write the mapping to.  It must have
            been opened as a text file with a Latin-1-compatible encoding.
        :param separator: The string to use for separating new or modified keys
            & values.  Only ``" "``, ``"="``, and ``":"`` (possibly with added
            whitespace) should ever be used as the separator.
        :type separator: text string
        :return: `None`
        """
        for line in self._lines:
            if line.source is None:
                print(join_key_value(line.key, line.value, separator), file=fp)
            else:
                fp.write(line.source)