import compat from ini import LineContainer, EmptyLine def tidy(cfg): """Clean up blank lines. This functions makes the configuration look clean and handwritten - consecutive empty lines and empty lines at the start of the file are removed, and one is guaranteed to be at the end of the file. """ if isinstance(cfg, compat.RawConfigParser): cfg = cfg.data cont = cfg._data.contents i = 1 while i < len(cont): if isinstance(cont[i], LineContainer): tidy_section(cont[i]) i += 1 elif (isinstance(cont[i-1], EmptyLine) and isinstance(cont[i], EmptyLine)): del cont[i] else: i += 1 # Remove empty first line if cont and isinstance(cont[0], EmptyLine): del cont[0] # Ensure a last line if cont and not isinstance(cont[-1], EmptyLine): cont.append(EmptyLine()) def tidy_section(lc): cont = lc.contents i = 1 while i < len(cont): if (isinstance(cont[i-1], EmptyLine) and isinstance(cont[i], EmptyLine)): del cont[i] else: i += 1 # Remove empty first line if len(cont) > 1 and isinstance(cont[1], EmptyLine): del cont[1]
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.__init__.pyo.40009 | File | 945 B | 0644 |
|
.compat.pyo.40009 | File | 12.54 KB | 0644 |
|
.config.pyo.40009 | File | 9.37 KB | 0644 |
|
.ini.pyo.40009 | File | 19.94 KB | 0644 |
|
.utils.pyo.40009 | File | 1.39 KB | 0644 |
|
__init__.py | File | 1.08 KB | 0644 |
|
__init__.pyc | File | 945 B | 0644 |
|
__init__.pyo | File | 945 B | 0644 |
|
compat.py | File | 11.82 KB | 0644 |
|
compat.pyc | File | 12.54 KB | 0644 |
|
compat.pyo | File | 12.54 KB | 0644 |
|
config.py | File | 8.11 KB | 0644 |
|
config.pyc | File | 9.37 KB | 0644 |
|
config.pyo | File | 9.37 KB | 0644 |
|
ini.py | File | 20.17 KB | 0644 |
|
ini.pyc | File | 19.94 KB | 0644 |
|
ini.pyo | File | 19.94 KB | 0644 |
|
utils.py | File | 1.24 KB | 0644 |
|
utils.pyc | File | 1.39 KB | 0644 |
|
utils.pyo | File | 1.39 KB | 0644 |
|