| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This Source Code Form is subject to the terms of the Mozilla Public | 3 # This Source Code Form is subject to the terms of the Mozilla Public |
| 4 # License, v. 2.0. If a copy of the MPL was not distributed with this | 4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import io | 8 import io |
| 9 import ConfigParser | 9 import ConfigParser |
| 10 from StringIO import StringIO | 10 from StringIO import StringIO |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 def _make_parser(self, filename): | 59 def _make_parser(self, filename): |
| 60 parser = ConfigParser.SafeConfigParser() | 60 parser = ConfigParser.SafeConfigParser() |
| 61 parser.optionxform = lambda option: option | 61 parser.optionxform = lambda option: option |
| 62 | 62 |
| 63 with io.open(filename, encoding='utf-8') as file: | 63 with io.open(filename, encoding='utf-8') as file: |
| 64 parser.readfp(file, filename) | 64 parser.readfp(file, filename) |
| 65 | 65 |
| 66 return parser | 66 return parser |
| 67 | 67 |
| 68 def _get_parser_chain(self, parser, filename): | 68 def _get_parser_chain(self, parser, filename): |
| 69 parsers = [] | 69 parsers = [(parser, filename)] |
| 70 | 70 |
| 71 while True: | 71 try: |
| 72 parsers.insert(0, (parser, filename)) | 72 inherit = parser.get('default', 'inherit') |
| 73 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
| 74 return parsers |
| 73 | 75 |
| 74 try: | 76 dirname = os.path.dirname(filename) |
| 75 inherit = parser.get('default', 'inherit') | 77 for parent in inherit.split(): |
| 76 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): | 78 parent_filename = os.path.join(dirname, *parent.split('/')) |
| 77 return parsers | 79 parent_parser = self._make_parser(parent_filename) |
| 80 parsers[:0] = self._get_parser_chain(parent_parser, parent_filename) |
| 78 | 81 |
| 79 filename = os.path.join(os.path.dirname(filename), *inherit.split('/')) | 82 return parsers |
| 80 parser = self._make_parser(filename) | |
| 81 | 83 |
| 82 def _apply_diff(self, section, option, value): | 84 def _apply_diff(self, section, option, value): |
| 83 is_addition = option.endswith('+') | 85 is_addition = option.endswith('+') |
| 84 is_diff = is_addition or option.endswith('-') | 86 is_diff = is_addition or option.endswith('-') |
| 85 | 87 |
| 86 if is_diff: | 88 if is_diff: |
| 87 option = option[:-1].rstrip() | 89 option = option[:-1].rstrip() |
| 88 try: | 90 try: |
| 89 orig_value = self.get(section, option) | 91 orig_value = self.get(section, option) |
| 90 except ConfigParser.NoOptionError: | 92 except ConfigParser.NoOptionError: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 raise NotImplementedError | 163 raise NotImplementedError |
| 162 | 164 |
| 163 def add_section(self, section): | 165 def add_section(self, section): |
| 164 raise NotImplementedError | 166 raise NotImplementedError |
| 165 | 167 |
| 166 def remove_option(self, section, option): | 168 def remove_option(self, section, option): |
| 167 raise NotImplementedError | 169 raise NotImplementedError |
| 168 | 170 |
| 169 def remove_section(self, section): | 171 def remove_section(self, section): |
| 170 raise NotImplementedError | 172 raise NotImplementedError |
| OLD | NEW |