Skip to content

Commit 8af0c4e

Browse files
author
Alexander Smishlajev
committed
added NullableOption, NullableFilePathOption;
MAIL_TLS_KEYFILE and MAIL_TLS_CERTFILE made nullable to be directly usable as smtplib.SMTP.starttls() arguments.
1 parent 092f01b commit 8af0c4e

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

roundup/configuration.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Roundup Issue Tracker configuration support
22
#
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 $
44
#
55
__docformat__ = "restructuredtext"
66

@@ -330,6 +330,46 @@ def str2value(self, value):
330330
except ValueError:
331331
raise OptionValueError(self, value, "Integer number required")
332332

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+
333373
### Main configuration layout.
334374
# Config is described as a sequence of sections,
335375
# where each section name is followed by a sequence
@@ -431,10 +471,10 @@ def str2value(self, value):
431471
(BooleanOption, "tls", "no",
432472
"If your SMTP mail host provides or requires TLS\n"
433473
"(Transport Layer Security) then set this option to 'yes'"),
434-
(FilePathOption, "tls_keyfile", "",
474+
(NullableFilePathOption, "tls_keyfile", "",
435475
"If TLS is used, you may set this option to the name\n"
436476
"of a PEM formatted file that contains your private key"),
437-
(FilePathOption, "tls_certfile", "",
477+
(NullableFilePathOption, "tls_certfile", "",
438478
"If TLS is used, you may set this option to the name\n"
439479
"of a PEM formatted certificate chain file"),
440480
(BooleanOption, "keep_quoted_text", "yes",

0 commit comments

Comments
 (0)