Example #1
0
def ini_format(stream, options, encoding):
    """format options using the INI format"""
    for optname, optdict, value in options:
        value = format_option_value(optdict, value)
        help = optdict.get('help')
        if help:
            help = normalize_text(help, line_len=79, indent='# ')
            print >> stream
            print >> stream, _encode(help, encoding)
        else:
            print >> stream
        if value is None:
            print >> stream, '#%s=' % optname
        else:
            value = _encode(value, encoding).strip()
            print >> stream, '%s=%s' % (optname, value)
Example #2
0
def ini_format_section(stream, section, options, encoding=None, doc=None):
    """format an options section using the INI format"""
    encoding = _get_encoding(encoding, stream)
    if doc:
        print(_encode(comment(doc), encoding), file=stream)
    print('[%s]' % section, file=stream)
    ini_format(stream, options, encoding)
Example #3
0
def ini_format_section(stream, section, options, encoding=None, doc=None):
    """format an options section using the INI format"""
    encoding = _get_encoding(encoding, stream)
    if doc:
        print >> stream, _encode(comment(doc), encoding)
    print >> stream, '[%s]' % section
    ini_format(stream, options, encoding)
Example #4
0
def ini_format(stream, options, encoding):
    """format options using the INI format"""
    for optname, optdict, value in options:
        value = format_option_value(optdict, value)
        help = optdict.get('help')
        if help:
            help = normalize_text(help, line_len=79, indent='# ')
            print(file=stream)
            print(_encode(help, encoding), file=stream)
        else:
            print(file=stream)
        if value is None:
            print('#%s=' % optname, file=stream)
        else:
            value = _encode(value, encoding).strip()
            print('%s=%s' % (optname, value), file=stream)
Example #5
0
def ini_format(stream, options, encoding):
    """format options using the INI format"""
    for optname, optdict, value in options:
        value = format_option_value(optdict, value)
        help = optdict.get("help")
        if help:
            help = normalize_text(help, line_len=79, indent="# ")
            print >> stream
            print >> stream, _encode(help, encoding)
        else:
            print >> stream
        if value is None:
            print >> stream, "#%s=" % optname
        else:
            value = _encode(value, encoding).strip()
            print >> stream, "%s=%s" % (optname, value)
Example #6
0
def ini_format_section(stream, section, options, encoding=None, doc=None):
    """format an options section using the INI format"""
    encoding = _get_encoding(encoding, stream)
    if doc:
        print >> stream, _encode(comment(doc), encoding)
    print >> stream, "[%s]" % section
    ini_format(stream, options, encoding)
Example #7
0
def rest_format_section(stream, section, options, encoding=None, doc=None):
    """format an options section using as ReST formatted output"""
    encoding = _get_encoding(encoding, stream)
    if section:
        print('%s\n%s' % (section, "'"*len(section)), file=stream)
    if doc:
        print(_encode(normalize_text(doc, line_len=79, indent=''), encoding), file=stream)
        print(file=stream)
    for optname, optdict, value in options:
        help = optdict.get('help')
        print(':%s:' % optname, file=stream)
        if help:
            help = normalize_text(help, line_len=79, indent='  ')
            print(_encode(help, encoding), file=stream)
        if value:
            value = _encode(format_option_value(optdict, value), encoding)
            print(file=stream)
            print('  Default: ``%s``' % value.replace("`` ", "```` ``"), file=stream)
Example #8
0
def rest_format_section(stream, section, options, encoding=None, doc=None):
    """format an options section using as ReST formatted output"""
    encoding = _get_encoding(encoding, stream)
    if section:
        print('%s\n%s' % (section, "'"*len(section)), file=stream)
    if doc:
        print(_encode(normalize_text(doc, line_len=79, indent=''), encoding), file=stream)
        print(file=stream)
    for optname, optdict, value in options:
        help = optdict.get('help')
        print(':%s:' % optname, file=stream)
        if help:
            help = normalize_text(help, line_len=79, indent='  ')
            print(_encode(help, encoding), file=stream)
        if value:
            value = _encode(format_option_value(optdict, value), encoding)
            print(file=stream)
            print('  Default: ``%s``' % value.replace("`` ", "```` ``"), file=stream)
Example #9
0
def rest_format_section(stream, section, options, encoding=None, doc=None):
    """format an options section using the INI format"""
    encoding = _get_encoding(encoding, stream)
    if section:
        print >> stream, "%s\n%s" % (section, "'" * len(section))
    if doc:
        print >> stream, _encode(normalize_text(doc, line_len=79, indent=""), encoding)
        print >> stream
    for optname, optdict, value in options:
        help = optdict.get("help")
        print >> stream, ":%s:" % optname
        if help:
            help = normalize_text(help, line_len=79, indent="  ")
            print >> stream, _encode(help, encoding)
        if value:
            value = _encode(format_option_value(optdict, value), encoding)
            print >> stream, ""
            print >> stream, "  Default: ``%s``" % value.replace("`` ", "```` ``")
Example #10
0
def ini_format(stream, options, encoding):
    """format options using the INI format"""
    for optname, optdict, value in options:
        value = format_option_value(optdict, value)
        help = optdict.get('help')
        if help:
            help = normalize_text(help, line_len=79, indent='# ')
            print(file=stream)
            print(_encode(help, encoding), file=stream)
        else:
            print(file=stream)
        if value is None:
            print('#%s=' % optname, file=stream)
        else:
            value = _encode(value, encoding).strip()
            if optdict.get('type') == 'string' and '\n' in value:
                prefix = '\n    '
                value = prefix + prefix.join(value.split('\n'))
            print('%s=%s' % (optname, value), file=stream)
Example #11
0
def ini_format(stream: Union[StringIO, TextIOWrapper], options: Any,
               encoding: str) -> None:
    """format options using the INI format"""
    for optname, optdict, value in options:
        value = format_option_value(optdict, value)
        help = optdict.get("help")
        if help:
            help = normalize_text(help, line_len=79, indent="# ")
            print(file=stream)
            print(_encode(help, encoding), file=stream)
        else:
            print(file=stream)
        if value is None:
            print("#%s=" % optname, file=stream)
        else:
            value = _encode(value, encoding).strip()
            if optdict.get("type") == "string" and "\n" in value:
                prefix = "\n    "
                value = prefix + prefix.join(value.split("\n"))
            print("%s=%s" % (optname, value), file=stream)
Example #12
0
def ini_format_section(
    stream: Union[StringIO, TextIOWrapper],
    section: str,
    options: Any,
    encoding: str = None,
    doc: Optional[Any] = None,
) -> None:
    """format an options section using the INI format"""
    encoding = _get_encoding(encoding, stream)
    if doc:
        print(_encode(comment(doc), encoding), file=stream)
    print("[%s]" % section, file=stream)
    ini_format(stream, options, encoding)