import pprint
import re
import shlex
-import string
import sys
import textwrap
self.unlock: list[str] = []
-class FormatCounterFormatter(string.Formatter):
- """
- This counts how many instances of each formatter
- "replacement string" appear in the format string.
-
- e.g. after evaluating "string {a}, {b}, {c}, {a}"
- the counts dict would now look like
- {'a': 2, 'b': 1, 'c': 1}
- """
- def __init__(self) -> None:
- self.counts = collections.Counter[str]()
-
- def get_value(
- self, key: str, args: object, kwargs: object # type: ignore[override]
- ) -> Literal['']:
- self.counts[key] += 1
- return ''
-
class Language(metaclass=abc.ABCMeta):
start_line = ""
fields = ['dsl_name']
fields.extend(additional_fields)
line: str = getattr(self, attr)
- fcf = FormatCounterFormatter()
+ fcf = libclinic.FormatCounterFormatter()
fcf.format(line)
def local_fail(should_be_there_but_isnt: bool) -> None:
if should_be_there_but_isnt:
wrapped_c_string_literal,
)
from .utils import (
- create_regex,
+ FormatCounterFormatter,
compute_checksum,
+ create_regex,
write_file,
)
"wrapped_c_string_literal",
# Utility functions
- "create_regex",
+ "FormatCounterFormatter",
"compute_checksum",
+ "create_regex",
"write_file",
]
+import collections
import hashlib
-import re
import os
+import re
+import string
+from typing import Literal
def write_file(filename: str, new_contents: str) -> None:
group_re = r"\w+" if word else ".+"
before = re.escape(before)
after = re.escape(after)
- pattern = fr"{before}({group_re}){after}"
+ pattern = rf"{before}({group_re}){after}"
if whole_line:
- pattern = fr"^{pattern}$"
+ pattern = rf"^{pattern}$"
return re.compile(pattern)
+
+
+class FormatCounterFormatter(string.Formatter):
+ """
+ This counts how many instances of each formatter
+ "replacement string" appear in the format string.
+
+ e.g. after evaluating "string {a}, {b}, {c}, {a}"
+ the counts dict would now look like
+ {'a': 2, 'b': 1, 'c': 1}
+ """
+
+ def __init__(self) -> None:
+ self.counts = collections.Counter[str]()
+
+ def get_value(
+ self, key: str, args: object, kwargs: object # type: ignore[override]
+ ) -> Literal[""]:
+ self.counts[key] += 1
+ return ""