|
1 | 1 | # Roundup Issue Tracker configuration support |
2 | 2 | # |
3 | | -# $Id: configuration.py,v 1.5 2004-07-25 14:36:50 a1s Exp $ |
| 3 | +# $Id: configuration.py,v 1.6 2004-07-25 15:09:07 a1s Exp $ |
4 | 4 | # |
5 | 5 | __docformat__ = "restructuredtext" |
6 | 6 |
|
@@ -330,6 +330,46 @@ def str2value(self, value): |
330 | 330 | except ValueError: |
331 | 331 | raise OptionValueError(self, value, "Integer number required") |
332 | 332 |
|
| 333 | +class NullableOption(Option): |
| 334 | + |
| 335 | + """Option that is set to None if it's string value is one of NULL strings |
| 336 | +
|
| 337 | + Default nullable strings list contains empty string only. |
| 338 | + There is constructor parameter allowing to specify different nullables. |
| 339 | +
|
| 340 | + Conversion to external representation returns the first of the NULL |
| 341 | + strings list when the value is None. |
| 342 | +
|
| 343 | + """ |
| 344 | + |
| 345 | + NULL_STRINGS = ("",) |
| 346 | + |
| 347 | + def __init__(self, config, section, setting, |
| 348 | + default=NODEFAULT, description=None, aliases=None, |
| 349 | + null_strings=NULL_STRINGS |
| 350 | + ): |
| 351 | + self.null_strings = list(null_strings) |
| 352 | + Option.__init__(self, config, section, setting, default, |
| 353 | + description, aliases) |
| 354 | + |
| 355 | + def str2value(self, value): |
| 356 | + if value in self.null_strings: |
| 357 | + return None |
| 358 | + else: |
| 359 | + return value |
| 360 | + |
| 361 | + def _value2str(self, value): |
| 362 | + if value is None: |
| 363 | + return self.null_strings[0] |
| 364 | + else: |
| 365 | + return value |
| 366 | + |
| 367 | +class NullableFilePathOption(NullableOption, FilePathOption): |
| 368 | + |
| 369 | + # .get() is from FilePathOption, |
| 370 | + get = FilePathOption.get |
| 371 | + # everything else - from NullableOption (inheritance order) |
| 372 | + |
333 | 373 | ### Main configuration layout. |
334 | 374 | # Config is described as a sequence of sections, |
335 | 375 | # where each section name is followed by a sequence |
@@ -431,10 +471,10 @@ def str2value(self, value): |
431 | 471 | (BooleanOption, "tls", "no", |
432 | 472 | "If your SMTP mail host provides or requires TLS\n" |
433 | 473 | "(Transport Layer Security) then set this option to 'yes'"), |
434 | | - (FilePathOption, "tls_keyfile", "", |
| 474 | + (NullableFilePathOption, "tls_keyfile", "", |
435 | 475 | "If TLS is used, you may set this option to the name\n" |
436 | 476 | "of a PEM formatted file that contains your private key"), |
437 | | - (FilePathOption, "tls_certfile", "", |
| 477 | + (NullableFilePathOption, "tls_certfile", "", |
438 | 478 | "If TLS is used, you may set this option to the name\n" |
439 | 479 | "of a PEM formatted certificate chain file"), |
440 | 480 | (BooleanOption, "keep_quoted_text", "yes", |
|
0 commit comments