MCPcopy
hub / github.com/celery/celery / _saferepr

Function _saferepr

celery/utils/saferepr.py:158–183  ·  view source on GitHub ↗
(o, maxlen=None, maxlevels=3, seen=None)

Source from the content-addressed store, hash-verified

156
157
158def _saferepr(o, maxlen=None, maxlevels=3, seen=None):
159 # type: (Any, int, int, Set) -> str
160 stack = deque([iter([o])])
161 for token, it in reprstream(stack, seen=seen, maxlevels=maxlevels):
162 if maxlen is not None and maxlen <= 0:
163 yield ', ...'
164 # move rest back to stack, so that we can include
165 # dangling parens.
166 stack.append(it)
167 break
168 if isinstance(token, _literal):
169 val = token.value
170 elif isinstance(token, _key):
171 val = saferepr(token.value, maxlen, maxlevels)
172 elif isinstance(token, _quoted):
173 val = _format_chars(token.value, maxlen)
174 else:
175 val = _safetext(truncate(token, maxlen))
176 yield val
177 if maxlen is not None:
178 maxlen -= len(val)
179 for rest1 in stack:
180 # maxlen exceeded, process any dangling parens.
181 for rest2 in rest1:
182 if isinstance(rest2, _literal) and not rest2.truncate:
183 yield rest2.value
184
185
186def _reprseq(val, lit_start, lit_end, builtin_type, chainer):

Callers 1

safereprFunction · 0.85

Calls 5

reprstreamFunction · 0.85
safereprFunction · 0.85
_format_charsFunction · 0.85
_safetextFunction · 0.85
truncateFunction · 0.85

Tested by

no test coverage detected