-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Profile class for profile contextmanager
- Loading branch information
Showing
3 changed files
with
95 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Profile.""" | ||
|
||
from typing import Any, Dict, Optional | ||
|
||
from cfgenvy import yaml_type | ||
|
||
|
||
class Profile: | ||
"""Profile.""" | ||
|
||
YAML = "!profile" | ||
|
||
@classmethod | ||
def as_yaml_type(cls, tag: Optional[str] = None): | ||
"""As yaml type.""" | ||
yaml_type( | ||
cls, | ||
tag or cls.YAML, | ||
init=cls._yaml_init, | ||
repr=cls._yaml_repr, | ||
) | ||
|
||
@classmethod | ||
def _yaml_init(cls, loader, node): | ||
"""Yaml init.""" | ||
return cls(**loader.construct_mapping(node, deep=True)) | ||
|
||
@classmethod | ||
def _yaml_repr(cls, dumper, self, *, tag: str): | ||
"""Yaml repr.""" | ||
return dumper.represent_mapping(tag, self.as_yaml()) | ||
|
||
def __init__(self, on: int, end: Optional[int] = None): | ||
"""__init__.""" | ||
self.on = on | ||
self.end = end | ||
|
||
def as_yaml(self) -> Dict[str, Any]: | ||
"""As yaml.""" | ||
return {"end": self.end, "on": self.on} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters