Mercurial > p > roundup > code
comparison roundup/configuration.py @ 2624:f40d5f0f1086
added NullableOption, NullableFilePathOption;
MAIL_TLS_KEYFILE and MAIL_TLS_CERTFILE made nullable
to be directly usable as smtplib.SMTP.starttls() arguments.
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Sun, 25 Jul 2004 15:09:07 +0000 |
| parents | 4e1030d49cea |
| children | 8e4c7a3217d6 |
comparison
equal
deleted
inserted
replaced
| 2623:4e1030d49cea | 2624:f40d5f0f1086 |
|---|---|
| 1 # Roundup Issue Tracker configuration support | 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 __docformat__ = "restructuredtext" | 5 __docformat__ = "restructuredtext" |
| 6 | 6 |
| 7 import imp | 7 import imp |
| 8 import os | 8 import os |
| 327 def str2value(self, value): | 327 def str2value(self, value): |
| 328 try: | 328 try: |
| 329 return int(value) | 329 return int(value) |
| 330 except ValueError: | 330 except ValueError: |
| 331 raise OptionValueError(self, value, "Integer number required") | 331 raise OptionValueError(self, value, "Integer number required") |
| 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) | |
| 332 | 372 |
| 333 ### Main configuration layout. | 373 ### Main configuration layout. |
| 334 # Config is described as a sequence of sections, | 374 # Config is described as a sequence of sections, |
| 335 # where each section name is followed by a sequence | 375 # where each section name is followed by a sequence |
| 336 # of Option definitions. Each Option definition | 376 # of Option definitions. Each Option definition |
| 429 (Option, "password", NODEFAULT, "SMTP login password\n" | 469 (Option, "password", NODEFAULT, "SMTP login password\n" |
| 430 "Set this if your mail host requires authenticated access."), | 470 "Set this if your mail host requires authenticated access."), |
| 431 (BooleanOption, "tls", "no", | 471 (BooleanOption, "tls", "no", |
| 432 "If your SMTP mail host provides or requires TLS\n" | 472 "If your SMTP mail host provides or requires TLS\n" |
| 433 "(Transport Layer Security) then set this option to 'yes'"), | 473 "(Transport Layer Security) then set this option to 'yes'"), |
| 434 (FilePathOption, "tls_keyfile", "", | 474 (NullableFilePathOption, "tls_keyfile", "", |
| 435 "If TLS is used, you may set this option to the name\n" | 475 "If TLS is used, you may set this option to the name\n" |
| 436 "of a PEM formatted file that contains your private key"), | 476 "of a PEM formatted file that contains your private key"), |
| 437 (FilePathOption, "tls_certfile", "", | 477 (NullableFilePathOption, "tls_certfile", "", |
| 438 "If TLS is used, you may set this option to the name\n" | 478 "If TLS is used, you may set this option to the name\n" |
| 439 "of a PEM formatted certificate chain file"), | 479 "of a PEM formatted certificate chain file"), |
| 440 (BooleanOption, "keep_quoted_text", "yes", | 480 (BooleanOption, "keep_quoted_text", "yes", |
| 441 "Keep email citations when accepting messages.\n" | 481 "Keep email citations when accepting messages.\n" |
| 442 "Setting this to \"no\" strips out \"quoted\" text" | 482 "Setting this to \"no\" strips out \"quoted\" text" |
