From 10af5cc250e5999f697e925d10d355035dbfa501 Mon Sep 17 00:00:00 2001 From: Salad Dais Date: Tue, 29 Oct 2024 07:15:24 +0000 Subject: [PATCH] Handle more JankStringyBytes ops --- hippolyzer/lib/base/datatypes.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hippolyzer/lib/base/datatypes.py b/hippolyzer/lib/base/datatypes.py index 2fca6fe..91635fc 100644 --- a/hippolyzer/lib/base/datatypes.py +++ b/hippolyzer/lib/base/datatypes.py @@ -322,12 +322,12 @@ class JankStringyBytes(bytes): def __add__(self, other): if isinstance(other, bytes): - return bytes(self) + other + return JankStringyBytes(bytes(self) + other) return str(self) + other def __radd__(self, other): if isinstance(other, bytes): - return other + bytes(self) + return JankStringyBytes(other + bytes(self)) return other + str(self) def lower(self): @@ -336,6 +336,20 @@ class JankStringyBytes(bytes): def upper(self): return str(self).upper() + def startswith(self, __prefix, __start=None, __end=None): + if __start or __end: + raise RuntimeError("Can't handle __start or __end") + if isinstance(__prefix, str): + return str(self).startswith(__prefix) + return self.startswith(__prefix) + + def endswith(self, __prefix, __start=None, __end=None): + if __start or __end: + raise RuntimeError("Can't handle __start or __end") + if isinstance(__prefix, str): + return str(self).endswith(__prefix) + return self.endswith(__prefix) + class RawBytes(bytes): __slots__ = ()