Return a properly formatted dict built from Tcl list pairs. If cut_minus is True, the supposed '-' prefix will be removed from keys. If conv is specified, it is used to convert values. Tcl list is expected to contain an even number of elements.
(tk, v, cut_minus=True, conv=None)
| 126 | |
| 127 | |
| 128 | def _splitdict(tk, v, cut_minus=True, conv=None): |
| 129 | """Return a properly formatted dict built from Tcl list pairs. |
| 130 | |
| 131 | If cut_minus is True, the supposed '-' prefix will be removed from |
| 132 | keys. If conv is specified, it is used to convert values. |
| 133 | |
| 134 | Tcl list is expected to contain an even number of elements. |
| 135 | """ |
| 136 | t = tk.splitlist(v) |
| 137 | if len(t) % 2: |
| 138 | raise RuntimeError('Tcl list representing a dict is expected ' |
| 139 | 'to contain an even number of elements') |
| 140 | it = iter(t) |
| 141 | dict = {} |
| 142 | for key, value in zip(it, it): |
| 143 | key = str(key) |
| 144 | if cut_minus and key[0] == '-': |
| 145 | key = key[1:] |
| 146 | if conv: |
| 147 | value = conv(value) |
| 148 | dict[key] = value |
| 149 | return dict |
| 150 | |
| 151 | class _VersionInfoType(collections.namedtuple('_VersionInfoType', |
| 152 | ('major', 'minor', 'micro', 'releaselevel', 'serial'))): |
no test coverage detected
searching dependent graphs…