def parse_item_specifier_type(
specifier, spec_types: Container=None, separator=':'):
"""
Returns a tuple that splits the string int a specifier, and its specifier
type.
Retruns a tuple of (specifier, specifier_type). If no specifier type could
be found in the set, returns None in place of the specifier_type.
:param specifier: The specifier string, such as "ip:10.0.0.1".
:param spec_types: A container whose elements are strings that will be
recognized as specifier types.
:param separator: Optional specifier. Defaults to ':'.
:return: tuple
"""
if separator in specifier:
tokens = specifier.split(separator, 1)
if tokens[0] in spec_types:
specifier_type = tokens[0]
specifier = tokens[1].strip()
else:
specifier_type = None
else:
specifier_type = None
return specifier, specifier_type
评论列表
文章目录