1"""A more or less complete dictionary like interface for the RISC OS environment."""
2
3import riscos
4
5class _Environ:
6    def __init__(self, initial = None):
7        pass
8    def __repr__(self):
9        return repr(riscos.getenvdict())
10    def __cmp__(self, dict):
11        return cmp(riscos.getenvdict(), dict)
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):
21        riscos.putenv(key, item)
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 __contains__(self, key):
36        return riscos.getenv(key) is not None
37    def update(self, dict):
38        for k, v in dict.items():
39            riscos.putenv(k, v)
40    def get(self, key, failobj=None):
41        value = riscos.getenv(key)
42        if value<>None:
43            return value
44        else:
45            return failobj
46