Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
match cannot be determined.
Parameters:
1. node (Any) The node to type
Returns: (YAMLValueFormats) one of the enumerated values
Raises: N/A
"""
best_type: YAMLValueFormats = YAMLValueFormats.DEFAULT
if node is None:
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type
if node is None:
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type
Returns: (YAMLValueFormats) one of the enumerated values
Raises: N/A
"""
best_type: YAMLValueFormats = YAMLValueFormats.DEFAULT
if node is None:
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type
def from_str(name: str) -> "YAMLValueFormats":
"""
Convert a string value to a value of this enumeration, if valid.
Parameters:
1. name (str) The name to convert
Returns: (YAMLValueFormats) the converted enumeration value
Raises:
- `NameError` when name doesn't match any enumeration values.
"""
check: str = str(name).upper()
if check in YAMLValueFormats.get_names():
return YAMLValueFormats[check]
raise NameError(
"YAMLValueFormats has no such item: {}"
.format(name))
def from_node(node: Any) -> "YAMLValueFormats":
"""
Identify the best matching enumeration value from a sample data node.
Will return YAMLValueFormats.DEFAULT if the node is None or its best
match cannot be determined.
Parameters:
1. node (Any) The node to type
Returns: (YAMLValueFormats) one of the enumerated values
Raises: N/A
"""
best_type: YAMLValueFormats = YAMLValueFormats.DEFAULT
if node is None:
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type
"""
best_type: YAMLValueFormats = YAMLValueFormats.DEFAULT
if node is None:
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type
def get_names() -> List[str]:
"""
Return all entry names for this enumeration.
Parameters: N/A
Returns: (List[str]) Upper-case names from this enumeration
Raises: N/A
"""
return [entry.name.upper() for entry in YAMLValueFormats]
Raises: N/A
"""
best_type: YAMLValueFormats = YAMLValueFormats.DEFAULT
if node is None:
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type
node_type: type = type(node)
if node_type is FoldedScalarString:
best_type = YAMLValueFormats.FOLDED
elif node_type is LiteralScalarString:
best_type = YAMLValueFormats.LITERAL
elif node_type is DoubleQuotedScalarString:
best_type = YAMLValueFormats.DQUOTE
elif node_type is SingleQuotedScalarString:
best_type = YAMLValueFormats.SQUOTE
elif node_type is PlainScalarString:
best_type = YAMLValueFormats.BARE
elif node_type is ScalarBoolean:
best_type = YAMLValueFormats.BOOLEAN
elif node_type is ScalarFloat:
best_type = YAMLValueFormats.FLOAT
elif node_type is ScalarInt:
best_type = YAMLValueFormats.INT
return best_type