Code Review
/
csit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Bump VPP stable version: socksvr
[csit.git]
/
resources
/
libraries
/
python
/
OptionString.py
diff --git
a/resources/libraries/python/OptionString.py
b/resources/libraries/python/OptionString.py
index
d6cb40f
..
7163d05
100644
(file)
--- a/
resources/libraries/python/OptionString.py
+++ b/
resources/libraries/python/OptionString.py
@@
-36,19
+36,21
@@
class OptionString(object):
the best fitting one, without much logic near the call site.
"""
the best fitting one, without much logic near the call site.
"""
- def __init__(self, p
refix="", *args
):
+ def __init__(self, p
arts=tuple(), prefix=""
):
"""Create instance with listed strings as parts to use.
Prefix will be converted to string and stripped.
The typical (nonempty) prefix values are "-" and "--".
"""Create instance with listed strings as parts to use.
Prefix will be converted to string and stripped.
The typical (nonempty) prefix values are "-" and "--".
+ TODO: Support users calling with parts being a string?
+
+ :param parts: List of of stringifiable objects to become parts.
:param prefix: Subtring to prepend to every parameter (not value).
:param prefix: Subtring to prepend to every parameter (not value).
- :
param args: List of positional arguments to become parts.
+ :
type parts: Iterable of object
:type prefix: object
:type prefix: object
- :type args: list of object
"""
"""
+ self.parts = [str(part) for part in parts]
self.prefix = str(prefix).strip() # Not worth to call change_prefix.
self.prefix = str(prefix).strip() # Not worth to call change_prefix.
- self.parts = list(args)
def __repr__(self):
"""Return string executable as Python constructor call.
def __repr__(self):
"""Return string executable as Python constructor call.
@@
-56,12
+58,11
@@
class OptionString(object):
:returns: Executable constructor call as string.
:rtype: str
"""
:returns: Executable constructor call as string.
:rtype: str
"""
- return "".join([
- "OptionString(prefix=", repr(self.prefix), ",",
- repr(self.parts)[1:-1], ")"])
+ return "OptionString(parts={parts!r},prefix={prefix!r})".format(
+ parts=self.parts, prefix=self.prefix)
# TODO: Would we ever need a copy() method?
# TODO: Would we ever need a copy() method?
- # Currently, supersting "master" is mutable but unique,
+ # Currently, superst
r
ing "master" is mutable but unique,
# substring "slave" can be used to extend, but does not need to be mutated.
def change_prefix(self, prefix):
# substring "slave" can be used to extend, but does not need to be mutated.
def change_prefix(self, prefix):
@@
-93,8
+94,9
@@
class OptionString(object):
return self
def _check_and_add(self, part, prefixed):
return self
def _check_and_add(self, part, prefixed):
- """Convert to string, strip,
add conditionally
prefixed if non-empty.
+ """Convert to string, strip,
conditionally add
prefixed if non-empty.
+ Value of None is converted to empty string.
Emptiness is tested before adding prefix.
:param part: Unchecked part to add to list of parts.
Emptiness is tested before adding prefix.
:param part: Unchecked part to add to list of parts.
@@
-104,7
+106,7
@@
class OptionString(object):
:returns: The converted part without prefix, empty means not added.
:rtype: str
"""
:returns: The converted part without prefix, empty means not added.
:rtype: str
"""
- part = str(part).strip()
+ part =
"" if part is None else
str(part).strip()
if part:
prefixed_part = self.prefix + part if prefixed else part
self.parts.append(prefixed_part)
if part:
prefixed_part = self.prefix + part if prefixed else part
self.parts.append(prefixed_part)