MCPcopy Index your code
hub / github.com/RustPython/RustPython / _format_align

Function _format_align

Lib/_pydecimal.py:6239–6264  ·  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

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

Callers 2

__format__Method · 0.85
_format_numberFunction · 0.85

Calls 1

lenFunction · 0.85

Tested by

no test coverage detected