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