-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
From Kivy to Textual & fix docker builds
- Loading branch information
Krisjanis Veinbahs
committed
Mar 12, 2022
1 parent
76ab43b
commit 4ad991f
Showing
11 changed files
with
268 additions
and
298 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,36 @@ | ||
import math | ||
from dataclasses import dataclass | ||
from typing import Iterable | ||
from result import Result, Err, Ok | ||
|
||
|
||
@dataclass | ||
class FancyByte: | ||
value: int | ||
|
||
@staticmethod | ||
def fromBytes(b: bytes) -> Result['FancyByte', str]: | ||
if len(b) > 1: | ||
return Err("Only one byte allowed") | ||
try: | ||
return Ok(FancyByte(int.from_bytes(b, "little"))) | ||
except Exception as e: | ||
return Err(f"Can't build byte: {e}") | ||
|
||
@staticmethod | ||
def fromInt(n: int) -> Result['FancyByte', str]: | ||
if n < 0: | ||
return Err("Byte too small") | ||
elif n >= math.pow(2, 8): | ||
return Err("Byte too large") | ||
return Ok(FancyByte(n)) | ||
|
||
def to_binary_bits(self) -> Iterable[bool]: | ||
str_bits_8 = bin(self.value)[2:].zfill(8) | ||
return list(map(lambda x: x == "1", str_bits_8)) | ||
|
||
def to_hex_str(self) -> str: | ||
return str(hex(self.value)) | ||
|
||
def to_char(self) -> str: | ||
return chr(self.value) |
Oops, something went wrong.