MCPcopy Index your code
hub / github.com/python/cpython / _format_align

Function _format_align

Lib/_pydecimal.py:6242–6267  ·  view source on GitHub ↗

Given an unpadded, non-aligned numeric string 'body' and sign string 'sign', add padding and alignment conforming to the given format specifier dictionary 'spec' (as produced by parse_format_specifier).

(sign, body, spec)

Source from the content-addressed store, hash-verified

6240 return format_dict
6241
6242def _format_align(sign, body, spec):
6243 """Given an unpadded, non-aligned numeric string 'body' and sign
6244 string 'sign', add padding and alignment conforming to the given
6245 format specifier dictionary 'spec' (as produced by
6246 parse_format_specifier).
6247
6248 """
6249 # how much extra space do we have to play with?
6250 minimumwidth = spec['minimumwidth']
6251 fill = spec['fill']
6252 padding = fill*(minimumwidth - len(sign) - len(body))
6253
6254 align = spec['align']
6255 if align == '<':
6256 result = sign + body + padding
6257 elif align == '>':
6258 result = padding + sign + body
6259 elif align == '=':
6260 result = sign + padding + body
6261 elif align == '^':
6262 half = len(padding)//2
6263 result = padding[:half] + sign + body + padding[half:]
6264 else:
6265 raise ValueError('Unrecognised alignment field')
6266
6267 return result
6268
6269def _group_lengths(grouping):
6270 """Convert a localeconv-style grouping into a (possibly infinite)

Callers 2

__format__Method · 0.85
_format_numberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…