Source code for python2verilog.api.modes
"""
Modes
"""
from __future__ import annotations
from enum import Enum
[docs]
class Modes(Enum):
"""
Filesystem Modes
"""
NO_WRITE = 0
WRITE = 1
OVERWRITE = 2
[docs]
@staticmethod
def write(mode: Modes) -> bool:
"""
Returns if user wants to write
"""
return mode in (Modes.WRITE, Modes.OVERWRITE)
[docs]
@staticmethod
def open_text_mode(mode: Modes) -> str:
"""
Returns proper mode argument for `open`
"""
assert Modes.write(mode)
return "w" if mode == Modes.OVERWRITE else "x"