Returns the parsed INI config contents. Each section name is a top level key. :param config_filename: The name of the INI file to parse :param parse_subsections: If True, parse indented blocks as subsections that represent their own configuration dictionary. For example,
(config_filename, parse_subsections=True)
| 107 | |
| 108 | |
| 109 | def raw_config_parse(config_filename, parse_subsections=True): |
| 110 | """Returns the parsed INI config contents. |
| 111 | |
| 112 | Each section name is a top level key. |
| 113 | |
| 114 | :param config_filename: The name of the INI file to parse |
| 115 | |
| 116 | :param parse_subsections: If True, parse indented blocks as |
| 117 | subsections that represent their own configuration dictionary. |
| 118 | For example, if the config file had the contents:: |
| 119 | |
| 120 | s3 = |
| 121 | signature_version = s3v4 |
| 122 | addressing_style = path |
| 123 | |
| 124 | The resulting ``raw_config_parse`` would be:: |
| 125 | |
| 126 | {'s3': {'signature_version': 's3v4', 'addressing_style': 'path'}} |
| 127 | |
| 128 | If False, do not try to parse subsections and return the indented |
| 129 | block as its literal value:: |
| 130 | |
| 131 | {'s3': '\nsignature_version = s3v4\naddressing_style = path'} |
| 132 | |
| 133 | :returns: A dict with keys for each profile found in the config |
| 134 | file and the value of each key being a dict containing name |
| 135 | value pairs found in that profile. |
| 136 | |
| 137 | :raises: ConfigNotFound, ConfigParseError |
| 138 | """ |
| 139 | config = {} |
| 140 | path = config_filename |
| 141 | if path is not None: |
| 142 | path = os.path.expandvars(path) |
| 143 | path = os.path.expanduser(path) |
| 144 | if not os.path.isfile(path): |
| 145 | raise botocore.exceptions.ConfigNotFound(path=_unicode_path(path)) |
| 146 | cp = configparser.RawConfigParser() |
| 147 | try: |
| 148 | cp.read([path]) |
| 149 | except (configparser.Error, UnicodeDecodeError): |
| 150 | raise botocore.exceptions.ConfigParseError( |
| 151 | path=_unicode_path(path) |
| 152 | ) |
| 153 | else: |
| 154 | for section in cp.sections(): |
| 155 | config[section] = {} |
| 156 | for option in cp.options(section): |
| 157 | config_value = cp.get(section, option) |
| 158 | if parse_subsections and config_value.startswith('\n'): |
| 159 | # Then we need to parse the inner contents as |
| 160 | # hierarchical. We support a single level |
| 161 | # of nesting for now. |
| 162 | try: |
| 163 | config_value = _parse_nested(config_value) |
| 164 | except ValueError: |
| 165 | raise botocore.exceptions.ConfigParseError( |
| 166 | path=_unicode_path(path) |