MCPcopy Create free account
hub / github.com/celery/celery / simple_format

Function simple_format

celery/utils/text.py:120–138  ·  view source on GitHub ↗

Format string, expanding abbreviations in keys'.

(
        s: str, keys: dict[str, str | Callable],
        pattern: Pattern[str] = RE_FORMAT, expand: str = r'\1')

Source from the content-addressed store, hash-verified

118
119
120def simple_format(
121 s: str, keys: dict[str, str | Callable],
122 pattern: Pattern[str] = RE_FORMAT, expand: str = r'\1') -> str:
123 """Format string, expanding abbreviations in keys'."""
124 if s:
125 keys.setdefault('%', '%')
126
127 def resolve(match: Match) -> str | Any:
128 key = match.expand(expand)
129 try:
130 resolver = keys[key]
131 except KeyError:
132 raise ValueError(UNKNOWN_SIMPLE_FORMAT_KEY.format(key, s))
133 if callable(resolver):
134 return resolver()
135 return resolver
136
137 return pattern.sub(resolve, s)
138 return s
139
140
141def remove_repeating_from_task(task_name: str, s: str) -> str:

Callers 3

host_formatFunction · 0.85

Calls 1

setdefaultMethod · 0.45

Tested by 2