Skip to main content

A utf8 charset config file parser

Project description

https://travis-ci.org/MacHu-GWU/utf8config-project.svg?branch=master https://codecov.io/gh/MacHu-GWU/utf8config-project/branch/master/graph/badge.svg https://img.shields.io/pypi/v/utf8config.svg https://img.shields.io/pypi/l/utf8config.svg https://img.shields.io/pypi/pyversions/utf8config.svg https://img.shields.io/badge/Star_Me_on_GitHub!--None.svg?style=social

Welcome to utf8config Documentation

utf8 format config file IO tool.

Features:

  1. Comment Control. (You can choose ignore comment or not while dumping)

  2. Allow unicode character.

  3. Smart parser for number, string, boolean, None, list.

Example:

# content of config.ini
### DEFAULT is the default section
### DEFAULT是默认Section
[DEFAULT]
localhost = 192.168.0.1 # IP地址, 默认 192.168.0.1
port = 8080 # 端口号

### 下面的是尝试连接的最长时间
connection_timeout = 60 # 单位是秒, 默认60

# Test是用来测试各种数据类型是否能被成功解析的
# 用Configuration.load()看看会不会成功吧

[TEST]
# Single Value
# 以下是单值项
# 即非列表的值
int = 123 # 123
int_pos = +123 # 123
int_neg = -123 # -123
float = 3.14 # 3.14
float_pos = +3.14 # 3.14
float_neg = -3.14 # -3.14
str = Hello World! # str "Hello World!"
str_quote = 'Good Boy' # str "Good Boy"
str_double_quote = "Bad Boy" # str "Bad Boy"
str_quote_in_quote = '"Boy"' # str '"Boy"'
str_int = '123' # str "123"
str_float = '3.14' # str "3.14"
str_bool = 'True' # str "True"
str_path = C:\用户\管理员 # str "C:\用户\管理员"
str_utf8 = 中文 # str "中文"
bool_true = True # True
bool_yes = Yes # True
bool_false = False # False
bool_no = No # No
none_none = None # None
none_null = null # None
none = # None

# List Value
# 以下是各种列表
empty_list = , # Empty list []
int_list = 1, -2, 3 # [1, -2, 3]
int_none_list = , -2,3 # [None -2, 3]
float_list = 1.1, -2.2, 3.3 # [1.1, -2.2, 3.3]
float_none_list = , -2.2,3.3 # [None -2.2, 3.3]
str_list = a, b, c # ["a", "b", "c"]
str_single_quote_list = '1', '2', '3' # ["1", "2", "3"]
str_double_quote_list = "1", "2", "3" # ["1", "2", "3"]
str_path_list = C:\windows, C:\中文 # ["C:\windows", "C:\中文"]
str_special_list = a, '1', '3.14', "True", "no", ,"None" # ["a", "1", "3.14", "True", "no", "None"]
bool_list = True, False # [True, False]
bool_yes_no_list = Yes, No # [True, False]

Usage:

Read and Write:

from utf8config import Config, Section, Field

config = Config.load("config.ini")
for section_name, section in config.items():
    ...

section = Config["DEFAULT"]
for field_name, field in section.items():
    ...

localhost = section["localhost"]
port = section["port"]

localhost.key # "localhost"
localhost.value # "192.168.0.1"

with open("config.ini", "w") as f:
    text = config.dump("config.ini", ignore_comment=True)
    f.write(text)

Programmatically Construct Config:

config = Config()
DEFAULT = config["DEFAULT"]
DEFAULT.add_field(Field(key="localhost", value="192.168.0.1"))

TEST = Section("TEST")
TEST.add_field(Field(key="numbers", value=[1, 2, 3]))
config.add_section(TEST)

Install

utf8config is released on PyPI, so all you need is:

$ pip install utf8config

To upgrade to latest version:

$ pip install --upgrade utf8config

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utf8config-0.0.2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

utf8config-0.0.2-py2-none-any.whl (35.0 kB view details)

Uploaded Python 2

File details

Details for the file utf8config-0.0.2.tar.gz.

File metadata

  • Download URL: utf8config-0.0.2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for utf8config-0.0.2.tar.gz
Algorithm Hash digest
SHA256 aa2d7bc2710c49916b6c250695b77835826ebd29761b26ce3945fffe394be427
MD5 70bdf9a48516d644c53a0ea348ca18d7
BLAKE2b-256 1e99e724bb6ffb9df8c512c7c40f05393dbacb00294ab434bcfa8c6c85ab19d0

See more details on using hashes here.

File details

Details for the file utf8config-0.0.2-py2-none-any.whl.

File metadata

File hashes

Hashes for utf8config-0.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 c0b57c6a888ae18223ddc9489bb8681a9b4842745295ffb48a3167b5c53f2780
MD5 b859fe7930d05be6b24cdce3f2cd67bf
BLAKE2b-256 debe8d95b0f1e669b90fb0e15c5e9203cb66f858cb719e4a4df7711edae15520

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page