1# Copyright (C) 2017 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15'''Utility functions for crypto doc updating tools.'''
16
17import json
18
19
20def load_json(filename):
21    '''Returns an object containing the JSON data from the provided file.'''
22    f = open(filename)
23    # JSON doesn't allow comments, but we have some header docs in our file,
24    # so strip comments out before parsing
25    stripped_contents = ''
26    for line in f:
27        if not line.strip().startswith('#'):
28            stripped_contents += line
29    data = json.loads(stripped_contents)
30    f.close()
31    return data
32
33
34def find_by_name(seq, name):
35    """Returns the first element in seq with the given name."""
36    for item in seq:
37        if item['name'] == name:
38            return item
39    return None
40