| 544 | |
| 545 | |
| 546 | class RandBin(_RandString[bytes]): |
| 547 | _DEFAULT_CHARS = b"".join(chb(c) for c in range(256)) |
| 548 | |
| 549 | def __init__(self, size=None, chars=_DEFAULT_CHARS): |
| 550 | # type: (Optional[Union[int, RandNum]], bytes) -> None |
| 551 | if size is None: |
| 552 | size = RandNumExpo(0.01) |
| 553 | self.size = size |
| 554 | self.chars = chars |
| 555 | |
| 556 | def _command_args(self): |
| 557 | # type: () -> str |
| 558 | if not isinstance(self.size, VolatileValue): |
| 559 | return "size=%r" % self.size |
| 560 | |
| 561 | if isinstance(self.size, RandNumExpo) and \ |
| 562 | self.size.lambd == 0.01 and self.size.base == 0: |
| 563 | # Default size for RandString, skip |
| 564 | return "" |
| 565 | return "size=%r" % self.size.command() |
| 566 | |
| 567 | def _fix(self): |
| 568 | # type: () -> bytes |
| 569 | s = b"" |
| 570 | for _ in range(int(self.size)): |
| 571 | s += struct.pack("!B", random.choice(self.chars)) |
| 572 | return s |
| 573 | |
| 574 | |
| 575 | class RandTermString(RandBin): |
no test coverage detected