Computes statistics for the given characters to determine encoding possibilities. Args: chars (list): List of characters to analyze. Returns: Statistics: A named tuple with encoding possibility flags and counts.
(self, chars: List[str])
| 408 | raise ValueError(f"No encoding found for string: {input_string}, encodings: {encodings}") |
| 409 | |
| 410 | def _compute_statistics(self, chars: List[str]) -> Statistics: |
| 411 | """ |
| 412 | Computes statistics for the given characters to determine encoding possibilities. |
| 413 | |
| 414 | Args: |
| 415 | chars (list): List of characters to analyze. |
| 416 | |
| 417 | Returns: |
| 418 | Statistics: A named tuple with encoding possibility flags and counts. |
| 419 | """ |
| 420 | can_lower_upper_digit_special_encoded = True |
| 421 | can_lower_special_encoded = True |
| 422 | digit_count = 0 |
| 423 | upper_count = 0 |
| 424 | for c in chars: |
| 425 | if can_lower_upper_digit_special_encoded: |
| 426 | if not (c.islower() or c.isupper() or c.isdigit() or c in {self.special_char1, self.special_char2}): |
| 427 | can_lower_upper_digit_special_encoded = False |
| 428 | if can_lower_special_encoded: |
| 429 | if not (c.islower() or c in {".", "_", "$", "|"}): |
| 430 | can_lower_special_encoded = False |
| 431 | if c.isdigit(): |
| 432 | digit_count += 1 |
| 433 | if c.isupper(): |
| 434 | upper_count += 1 |
| 435 | |
| 436 | return Statistics( |
| 437 | can_lower_upper_digit_special_encoded, |
| 438 | can_lower_special_encoded, |
| 439 | digit_count, |
| 440 | upper_count, |
| 441 | ) |
| 442 | |
| 443 | def _encode_lower_special(self, input_string: str) -> bytes: |
| 444 | """ |