equal
deleted
inserted
replaced
12 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and |
14 # See the License for the specific language governing permissions and |
15 # limitations under the License. |
15 # limitations under the License. |
16 |
16 |
17 """Logic related to handling dictionaries |
17 """Logic related to handling dictionaries. |
18 """ |
18 """ |
19 |
19 |
20 __authors__ = [ |
20 __authors__ = [ |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
22 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
29 Args: |
29 Args: |
30 target: The dictionary that is to be filtered |
30 target: The dictionary that is to be filtered |
31 keys: The list with keys to filter the dictionary on |
31 keys: The list with keys to filter the dictionary on |
32 |
32 |
33 Returns: |
33 Returns: |
34 A dictionary that only contains the (key,value) from target that have their key in keys |
34 A dictionary that only contains the (key,value) from target that |
|
35 have their key in keys. |
35 """ |
36 """ |
36 result = {} |
37 result = {} |
37 |
38 |
38 for key, value in target.iteritems(): |
39 for key, value in target.iteritems(): |
39 if key in keys: |
40 if key in keys: |
48 Args: |
49 Args: |
49 target: The dictionary that is to be updated, may be None |
50 target: The dictionary that is to be updated, may be None |
50 updates: A dictionary containing new values for the original dict |
51 updates: A dictionary containing new values for the original dict |
51 |
52 |
52 Returns: |
53 Returns: |
53 the target dict, with any missing values from updates merged in, in-place |
54 the target dict, with any missing values from updates merged in, in-place. |
54 """ |
55 """ |
55 |
56 |
56 if not target: |
57 if not target: |
57 target = {} |
58 target = {} |
58 |
59 |
87 result[key] = value |
88 result[key] = value |
88 |
89 |
89 return result |
90 return result |
90 |
91 |
91 def rename(target, keys): |
92 def rename(target, keys): |
92 """Returns a dict containing only the key/value pairs from keys |
93 """Returns a dict containing only the key/value pairs from keys. |
93 |
94 |
94 The keys from target will be looked up in keys, and the corresponding |
95 The keys from target will be looked up in keys, and the corresponding |
95 value from keys will be used instead. If a key is not found, it is skipped. |
96 value from keys will be used instead. If a key is not found, it is skipped. |
96 |
97 |
97 Args: |
98 Args: |