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

Function _group_lengths

Lib/_pydecimal.py:6266–6287  ·  view source on GitHub ↗

Convert a localeconv-style grouping into a (possibly infinite) iterable of integers representing group lengths.

(grouping)

Source from the content-addressed store, hash-verified

6264 return result
6265
6266def _group_lengths(grouping):
6267 """Convert a localeconv-style grouping into a (possibly infinite)
6268 iterable of integers representing group lengths.
6269
6270 """
6271 # The result from localeconv()['grouping'], and the input to this
6272 # function, should be a list of integers in one of the
6273 # following three forms:
6274 #
6275 # (1) an empty list, or
6276 # (2) nonempty list of positive integers + [0]
6277 # (3) list of positive integers + [locale.CHAR_MAX], or
6278
6279 from itertools import chain, repeat
6280 if not grouping:
6281 return []
6282 elif grouping[-1] == 0 and len(grouping) >= 2:
6283 return chain(grouping[:-1], repeat(grouping[-2]))
6284 elif grouping[-1] == _locale.CHAR_MAX:
6285 return grouping[:-1]
6286 else:
6287 raise ValueError('unrecognised format for grouping')
6288
6289def _insert_thousands_sep(digits, spec, min_width=1):
6290 """Insert thousands separators into a digit string.

Callers 1

_insert_thousands_sepFunction · 0.85

Calls 2

lenFunction · 0.85
repeatFunction · 0.85

Tested by

no test coverage detected