-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
pathseperators.py
59 lines (43 loc) · 1.45 KB
/
pathseperators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Implements the PathSeperators enumeration.
Copyright 2019 William W. Kimball, Jr. MBA MSIS
"""
from enum import Enum, auto
class PathSeperators(Enum):
"""Supported representation formats for YAML values."""
AUTO = auto()
DOT = auto()
FSLASH = auto()
@staticmethod
def get_names():
"""Returns all entry names for this enumeration.
Positional Parameters: N/A
Returns: (list) Upper-case names from this enumeration
Raises: N/A
"""
return [entry.name.upper() for entry in PathSeperators]
@staticmethod
def from_str(name):
"""Converts a string value to a value of this enumeration, if valid.
Positional Parameters:
1. name (str) The name to convert
Returns: (PathSeperators) the converted enumeration value
Raises:
NameError when name doesn't match any enumeration values.
"""
if isinstance(name, PathSeperators):
return name
check = str(name).upper()
if check == '.':
check = "DOT"
elif check == '/':
check = "FSLASH"
if check in PathSeperators.get_names():
return PathSeperators[check]
else:
raise NameError("PathSeperators has no such item, " + check)
@staticmethod
def to_seperator(name):
seperator = '.'
if name == PathSeperators.FSLASH:
seperator = '/'
return seperator