Debian Codegraph @

third_party/python/taskcluster_taskgraph/taskgraph/util/readonlydict.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 # Imported from
6 # https://searchfox.org/mozilla-central/rev/ece43b04e7baa4680dac46a06d5ad42b27b124f4/python/mozbuild/mozbuild/util.py#102
7
8 import copy
9
10
11 class ReadOnlyDict(dict):
12 """A read-only dictionary."""
13
14 def __init__(self, *args, **kwargs):
15 dict.__init__(self, *args, **kwargs)
16
17 def __delitem__(self, key):
18 raise Exception("Object does not support deletion.")
19
20 def __setitem__(self, key, value):
21 raise Exception("Object does not support assignment.")
22
23 def update(self, *args, **kwargs):
24 raise Exception("Object does not support update.")
25
26 def __copy__(self, *args, **kwargs):
27 return ReadOnlyDict(**dict.copy(self, *args, **kwargs))
28
29 def __deepcopy__(self, memo):
30 result = {}
31 for k, v in self.items():
32 result[k] = copy.deepcopy(v, memo)
33
34 return ReadOnlyDict(**result)
35
36 def __reduce__(self, *args, **kwargs):
37 """
38 Support for `pickle`.
39 """
40
41 return (self.__class__, (dict(self),))