From 6ff9d2b56eeb1793c13f00fcd6a1fb0f06d3040c Mon Sep 17 00:00:00 2001 From: Ethan-0l <67695818+ethan-0l@users.noreply.github.com> Date: Mon, 3 Feb 2025 04:27:24 +0100 Subject: [PATCH 1/4] add basic methode for framework handling --- pyjsx/jsx.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyjsx/jsx.py b/pyjsx/jsx.py index 87422f8..8740388 100644 --- a/pyjsx/jsx.py +++ b/pyjsx/jsx.py @@ -43,6 +43,12 @@ def __str__(self): case _: return self.convert_component(self.tag) + def __len__(self): + return len(str(self)) + + def __bytes__(self): + return str(self).encode('utf-8') + def convert_prop(self, key: str, value: Any) -> str: if isinstance(value, bool): return key if value else "" From 5edd4699103953371096ae57f8f907ff4b03f622 Mon Sep 17 00:00:00 2001 From: Ethan-0l <67695818+ethan-0l@users.noreply.github.com> Date: Mon, 3 Feb 2025 05:42:50 +0100 Subject: [PATCH 2/4] fix bytes concat --- pyjsx/jsx.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pyjsx/jsx.py b/pyjsx/jsx.py index 8740388..477efb2 100644 --- a/pyjsx/jsx.py +++ b/pyjsx/jsx.py @@ -47,7 +47,19 @@ def __len__(self): return len(str(self)) def __bytes__(self): - return str(self).encode('utf-8') + match self.tag: + case str(): + return self.convert_builtin(self.tag).encode('utf-8') + case _: + return self.convert_component(self.tag).encode('utf-8') + + def __add__(self, other): + return str(self) + str(other) + + def __radd__(self, other): + if isinstance(other, bytes): + return other + bytes(self) + return NotImplemented def convert_prop(self, key: str, value: Any) -> str: if isinstance(value, bool): From 6163104ce587e4738b62c89b9e2700ed415f26af Mon Sep 17 00:00:00 2001 From: Ethan-0l <67695818+ethan-0l@users.noreply.github.com> Date: Mon, 3 Feb 2025 05:50:39 +0100 Subject: [PATCH 3/4] fix encode calls --- pyjsx/jsx.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyjsx/jsx.py b/pyjsx/jsx.py index 477efb2..04daaed 100644 --- a/pyjsx/jsx.py +++ b/pyjsx/jsx.py @@ -61,6 +61,9 @@ def __radd__(self, other): return other + bytes(self) return NotImplemented + def encode(self, encoding='utf-8', errors='strict'): + return str(self).encode(encoding, errors) + def convert_prop(self, key: str, value: Any) -> str: if isinstance(value, bool): return key if value else "" From cbed616edb80b81f9a78124d30d0077a8201e610 Mon Sep 17 00:00:00 2001 From: Ethan-0l <67695818+ethan-0l@users.noreply.github.com> Date: Mon, 3 Feb 2025 18:08:08 +0100 Subject: [PATCH 4/4] remove stupid methods implementation --- pyjsx/jsx.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pyjsx/jsx.py b/pyjsx/jsx.py index 04daaed..4dd84d5 100644 --- a/pyjsx/jsx.py +++ b/pyjsx/jsx.py @@ -53,14 +53,6 @@ def __bytes__(self): case _: return self.convert_component(self.tag).encode('utf-8') - def __add__(self, other): - return str(self) + str(other) - - def __radd__(self, other): - if isinstance(other, bytes): - return other + bytes(self) - return NotImplemented - def encode(self, encoding='utf-8', errors='strict'): return str(self).encode(encoding, errors)