| 426 | |
| 427 | @dataclass |
| 428 | class String(ASTNode): |
| 429 | value: str |
| 430 | |
| 431 | def __post_init__(self): |
| 432 | super().__post_init__() |
| 433 | self._taint_class = Taints.SAFE |
| 434 | |
| 435 | def __add__(self, other): |
| 436 | if isinstance(other, String): |
| 437 | new_str = self.value + other.value |
| 438 | return String(value=new_str) |
| 439 | else: |
| 440 | raise exceptions.ASTNodeRewrite(f"Can't add String and `{type(other)}`") |
| 441 | |
| 442 | def __mul__(self, other): |
| 443 | if isinstance(other, int): |
| 444 | return String(value=self.value * other) |
| 445 | else: |
| 446 | raise exceptions.ASTNodeRewrite( |
| 447 | f"Can't multiply String and `{type(other)}`" |
| 448 | ) |
| 449 | |
| 450 | def __str__(self): |
| 451 | return str(self.value) |
| 452 | |
| 453 | def __bytes__(self): |
| 454 | return self.value.encode("utf-8") |
| 455 | |
| 456 | def __len__(self): |
| 457 | return len(str(self)) |
| 458 | |
| 459 | def __hash__(self): |
| 460 | return hash(self.value) |
| 461 | |
| 462 | def _visit_node(self, context: Context): |
| 463 | pass |
| 464 | |
| 465 | @property |
| 466 | def json(self): |
| 467 | d = super().json |
| 468 | d["value"] = self.value |
| 469 | return d |
| 470 | |
| 471 | def match(self, other, ctx) -> bool: |
| 472 | if type(other) not in (str, String): |
| 473 | return False |
| 474 | |
| 475 | return str(self) == str(other) |
| 476 | |
| 477 | |
| 478 | @dataclass |
no outgoing calls
no test coverage detected