Mercurial > p > roundup > code
comparison roundup/configuration.py @ 6557:8687c096a945
Handle configparser.InterpolationSyntaxError
Under Python 3, an option value with a single % (e.g. this % is a
test) throws
configparser.InterpolationSyntaxError: '%' must be followed by
'%' or '(', found: '%s))'
Added code to capture this, raise a different exception. roundup-admin
handles the error and exits cleanly. Other code shows the traceback.
The new error message reports the file, section and option causing the
problem to allow easier repair.
Also updated roundup translations and added tests.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 13 Dec 2021 12:48:57 -0500 |
| parents | a036712c96f4 |
| children | c77bd76b57da |
comparison
equal
deleted
inserted
replaced
| 6556:d92e0d059c3a | 6557:8687c096a945 |
|---|---|
| 29 else: | 29 else: |
| 30 import ConfigParser as configparser # Python 2 | 30 import ConfigParser as configparser # Python 2 |
| 31 | 31 |
| 32 from roundup.exceptions import RoundupException | 32 from roundup.exceptions import RoundupException |
| 33 | 33 |
| 34 # XXX i don't think this module needs string translation, does it? | |
| 35 | |
| 36 ### Exceptions | 34 ### Exceptions |
| 37 | 35 |
| 38 | 36 |
| 39 class ConfigurationError(RoundupException): | 37 class ConfigurationError(RoundupException): |
| 40 pass | 38 pass |
| 39 | |
| 40 class ParsingOptionError(ConfigurationError): | |
| 41 def __str__(self): | |
| 42 _args = self.args | |
| 43 return self.args[0] | |
| 41 | 44 |
| 42 | 45 |
| 43 class NoConfigError(ConfigurationError): | 46 class NoConfigError(ConfigurationError): |
| 44 | 47 |
| 45 """Raised when configuration loading fails | 48 """Raised when configuration loading fails |
| 259 } | 262 } |
| 260 return _rv | 263 return _rv |
| 261 | 264 |
| 262 def load_ini(self, config): | 265 def load_ini(self, config): |
| 263 """Load value from ConfigParser object""" | 266 """Load value from ConfigParser object""" |
| 264 if config.has_option(self.section, self.setting): | 267 try: |
| 265 self.set(config.get(self.section, self.setting)) | 268 if config.has_option(self.section, self.setting): |
| 269 self.set(config.get(self.section, self.setting)) | |
| 270 except configparser.InterpolationSyntaxError as e: | |
| 271 raise ParsingOptionError( | |
| 272 _("Error in %(filepath)s with section [%(section)s] at option %(option)s: %(message)s")%{ | |
| 273 "filepath": self.config.filepath, | |
| 274 "section": e.section, | |
| 275 "option": e.option, | |
| 276 "message": e.message}) | |
| 277 | |
| 266 | 278 |
| 267 | 279 |
| 268 class BooleanOption(Option): | 280 class BooleanOption(Option): |
| 269 | 281 |
| 270 """Boolean option: yes or no""" | 282 """Boolean option: yes or no""" |
