Guido van Rossum | 228d807 | 2001-03-02 05:58:11 +0000 | [diff] [blame] | 1 | """A more or less complete user-defined wrapper around dictionary objects.""" |
| 2 | |
| 3 | import riscos |
| 4 | |
| 5 | class _Environ: |
| 6 | def __init__(self): |
| 7 | pass |
| 8 | def __repr__(self): |
| 9 | return repr(riscos.getenvdict()) |
| 10 | def __cmp__(self, dict): |
| 11 | if isinstance(dict, UserDict): |
| 12 | return cmp(riscos.getenvdict(), dict) |
| 13 | def __len__(self): |
| 14 | return len(riscos.getenvdict()) |
| 15 | def __getitem__(self, key): |
| 16 | ret = riscos.getenv(key) |
| 17 | if ret<>None: |
| 18 | return ret |
| 19 | else: |
| 20 | raise KeyError |
| 21 | def __setitem__(self, key, item): |
| 22 | riscos.setenv(key, item) |
| 23 | def __delitem__(self, key): |
| 24 | riscos.delenv(key) |
| 25 | def clear(self): |
| 26 | # too dangerous on RISC OS |
| 27 | pass |
| 28 | def copy(self): |
| 29 | return riscos.getenvdict() |
| 30 | def keys(self): return riscos.getenvdict().keys() |
| 31 | def items(self): return riscos.getenvdict().items() |
| 32 | def values(self): return riscos.getenvdict().values() |
| 33 | def has_key(self, key): |
| 34 | value = riscos.getenv(key) |
| 35 | return value<>None |
| 36 | def update(self, dict): |
| 37 | for k, v in dict.items(): |
| 38 | riscos.putenv(k, v) |
| 39 | def get(self, key, failobj=None): |
| 40 | value = riscos.getenv(key) |
| 41 | if value<>None: |
| 42 | return value |
| 43 | else: |
| 44 | return failobj |
| 45 | |
| 46 | environ = _Environ() |