You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
633 B
31 lines
633 B
import shlex |
|
|
|
|
|
class ConfigSyntaxError(BaseException): |
|
pass |
|
|
|
|
|
def loadl(lines): |
|
output = {} |
|
|
|
for line in [ i.strip() for i in lines ]: |
|
words = shlex.split(line, comments=True) |
|
|
|
if len(words) == 0: |
|
pass |
|
elif len(words) == 2: |
|
if words[0] in output: |
|
raise ConfigSyntaxError('keys cannot be redefined') |
|
output[words[0]] = words[1] |
|
else: |
|
raise ConfigSyntaxError('lines must consist of exactly two tokens') |
|
|
|
return output |
|
|
|
|
|
def loads(string): |
|
return loadl(string.split('\n')) |
|
|
|
|
|
def load(f): |
|
return loadl(f.readlines())
|
|
|