Attempt to load the file path. :type file_path: str :param file_path: The full path to the file to load without the '.json' extension. :return: The loaded data if it exists, otherwise None.
(self, file_path)
| 156 | return os.path.isfile(file_path + '.json') |
| 157 | |
| 158 | def load_file(self, file_path): |
| 159 | """Attempt to load the file path. |
| 160 | |
| 161 | :type file_path: str |
| 162 | :param file_path: The full path to the file to load without |
| 163 | the '.json' extension. |
| 164 | |
| 165 | :return: The loaded data if it exists, otherwise None. |
| 166 | |
| 167 | """ |
| 168 | full_path = file_path + '.json' |
| 169 | if not os.path.isfile(full_path): |
| 170 | return |
| 171 | |
| 172 | # By default the file will be opened with locale encoding on Python 3. |
| 173 | # We specify "utf8" here to ensure the correct behavior. |
| 174 | with open(full_path, 'rb') as fp: |
| 175 | payload = fp.read().decode('utf-8') |
| 176 | |
| 177 | logger.debug("Loading JSON file: %s", full_path) |
| 178 | return json.loads(payload, object_pairs_hook=OrderedDict) |
| 179 | |
| 180 | |
| 181 | def create_loader(search_path_string=None): |
no test coverage detected