|
18 | 18 | import os |
19 | 19 | import shutil |
20 | 20 |
|
| 21 | + |
21 | 22 | # use our own ASCII only uppercase function to avoid locale issues |
22 | 23 | # not going to be fast but not important |
23 | 24 | def uppercase_ASCII_string(str): |
24 | 25 | newstr = "" |
25 | | - for i in range(0,len(str)): |
26 | | - if str[i] in string.lowercase: |
27 | | - newstr += chr(ord(str[i])-32) |
28 | | - else: |
29 | | - newstr += str[i] |
| 26 | + for i in range(0, len(str)): |
| 27 | + if str[i] in string.lowercase: |
| 28 | + newstr += chr(ord(str[i]) - 32) |
| 29 | + else: |
| 30 | + newstr += str[i] |
30 | 31 |
|
31 | 32 | return newstr |
32 | 33 |
|
| 34 | + |
33 | 35 | class SimpleConfigFile: |
34 | | - def __str__ (self): |
| 36 | + def __str__(self): |
35 | 37 | s = "" |
36 | | - keys = self.info.keys () |
37 | | - keys.sort () |
| 38 | + keys = list(self.info.keys()) |
| 39 | + keys.sort() |
38 | 40 | for key in keys: |
39 | 41 | # FIXME - use proper escaping |
40 | | - if type (self.info[key]) == type(""): |
| 42 | + if type(self.info[key]) == type(""): |
41 | 43 | s = s + key + "=\"" + self.info[key] + "\"\n" |
42 | 44 | return s |
43 | 45 |
|
44 | | - def __init__ (self): |
| 46 | + def __init__(self): |
45 | 47 | self.info = {} |
46 | 48 |
|
47 | 49 | def write(self, file): |
@@ -69,17 +71,17 @@ def read(self, file): |
69 | 71 | value = value.replace("'", '') |
70 | 72 | self.info[key] = value |
71 | 73 |
|
72 | | - def set (self, *args): |
| 74 | + def set(self, *args): |
73 | 75 | for (key, data) in args: |
74 | 76 | self.info[uppercase_ASCII_string(key)] = data |
75 | 77 |
|
76 | | - def unset (self, *keys): |
| 78 | + def unset(self, *keys): |
77 | 79 | for key in keys: |
78 | 80 | key = uppercase_ASCII_string(key) |
79 | | - if self.info.has_key (key): |
80 | | - del self.info[key] |
| 81 | + if key in self.info: |
| 82 | + del self.info[key] |
81 | 83 |
|
82 | | - def get (self, key): |
| 84 | + def get(self, key): |
83 | 85 | key = uppercase_ASCII_string(key) |
84 | 86 | return self.info.get(key, "") |
85 | 87 |
|
@@ -132,4 +134,3 @@ def write(self, dir=None): |
132 | 134 | path = os.path.join(dir, os.path.basename(self.path)) |
133 | 135 |
|
134 | 136 | SimpleConfigFile.write(self, path) |
135 | | - |
|
0 commit comments