MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _group_lengths

Function _group_lengths

tools/python-3.11.9-amd64/Lib/_pydecimal.py:6295–6316  ·  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

6293 return result
6294
6295def _group_lengths(grouping):
6296 """Convert a localeconv-style grouping into a (possibly infinite)
6297 iterable of integers representing group lengths.
6298
6299 """
6300 # The result from localeconv()['grouping'], and the input to this
6301 # function, should be a list of integers in one of the
6302 # following three forms:
6303 #
6304 # (1) an empty list, or
6305 # (2) nonempty list of positive integers + [0]
6306 # (3) list of positive integers + [locale.CHAR_MAX], or
6307
6308 from itertools import chain, repeat
6309 if not grouping:
6310 return []
6311 elif grouping[-1] == 0 and len(grouping) >= 2:
6312 return chain(grouping[:-1], repeat(grouping[-2]))
6313 elif grouping[-1] == _locale.CHAR_MAX:
6314 return grouping[:-1]
6315 else:
6316 raise ValueError('unrecognised format for grouping')
6317
6318def _insert_thousands_sep(digits, spec, min_width=1):
6319 """Insert thousands separators into a digit string.

Callers 1

_insert_thousands_sepFunction · 0.85

Calls 2

chainClass · 0.85
repeatFunction · 0.85

Tested by

no test coverage detected