Coverage for pygeodesy/streprs.py: 95%
267 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-06-07 08:37 -0400
« prev ^ index » next coverage.py v7.2.2, created at 2023-06-07 08:37 -0400
2# -*- coding: utf-8 -*-
4u'''Floating point and other formatting utilities.
5'''
7from pygeodesy.basics import _0_0, isint, islistuple, isscalar, isstr, _zip
8# from pygeodesy.constants import _0_0
9from pygeodesy.errors import _AttributeError, _IsnotError, itemsorted, _or, \
10 _TypeError, _ValueError, _xkwds_get, _xkwds_pop
11from pygeodesy.interns import NN, _0_, _0to9_, MISSING, _BAR_, _COMMASPACE_, \
12 _DOT_, _dunder_nameof, _E_, _ELLIPSIS_, _EQUAL_, \
13 _H_, _LR_PAIRS, _N_, _name_, _not_, _not_scalar_, \
14 _PERCENT_, _SPACE_, _STAR_, _UNDER_
15from pygeodesy.interns import _convergence_, _distant_, _e_, _eps_, _exceeds_, \
16 _EQUALSPACED_, _f_, _F_, _g_, _limit_, _no_, \
17 _tolerance_ # PYCHOK used!
18from pygeodesy.lazily import _ALL_LAZY, _ALL_MODS as _MODS
20from math import fabs, log10 as _log10
22__all__ = _ALL_LAZY.streprs
23__version__ = '23.06.03'
25_EN_PREC = 6 # max MGRS/OSGR precision, 1 micrometer
26_EN_WIDE = 5 # number of MGRS/OSGR units, log10(_100km)
27_OKd_ = '._-' # acceptable name characters
28_PAREN_g = '(%g)' # PYCHOK used!
29_threshold_ = 'threshold' # PYCHOK used!
32class _Fmt(str): # in .streprs
33 '''(INTERNAL) Callable formatting.
34 '''
35 name = NN
37 def __call__(self, *name_value_, **name_value):
38 '''Format a C{name=value} pair or C{name, value} pair
39 or just a single C{value}.
40 '''
41 for n, v in name_value.items():
42 break
43 else:
44 if len(name_value_) > 1:
45 n, v = name_value_[:2]
46 elif name_value_:
47 n, v = NN, name_value_[0]
48 else:
49 n, v = NN, MISSING
50 t = str.__mod__(self, v)
51 return NN(n, t) if n else t
53# def __mod__(self, arg, **unused):
54# '''Regular C{%} operator.
55# '''
56# return str.__mod__(self, arg)
59class Fstr(str):
60 '''(INTERNAL) C{float} format.
61 '''
62 name = NN
64 def __call__(self, flt, prec=None, ints=False):
65 '''Format the B{C{flt}} like function L{fstr}.
66 '''
67 # see also function C{fstr} if isscalar case below
68 t = str.__mod__(_pct(self), flt) if prec is None else next(
69 _streprs(prec, (flt,), self, ints, True, None))
70 return t
72 def __mod__(self, arg, **unused):
73 '''Regular C{%} operator.
75 @arg arg: A C{scalar} value to be formatted (either
76 the C{scalar}, or a 1-tuple C{(scalar,)},
77 or 2-tuple C{(prec, scalar)}.
79 @raise TypeError: Non-scalar B{C{arg}} value.
81 @raise ValueError: Invalid B{C{arg}}.
82 '''
83 def _error(arg):
84 n = _DOT_(Fstr.__name__, self.name or self)
85 return _SPACE_(n, _PERCENT_, repr(arg))
87 prec = 6 # default std %f and %F
88 if islistuple(arg):
89 n = len(arg)
90 if n == 1:
91 arg = arg[0]
92 elif n == 2:
93 prec, arg = arg
94 else:
95 raise _ValueError(_error(arg))
97 if not isscalar(arg):
98 raise _TypeError(_error(arg))
99 return self(arg, prec=prec)
102class _Sub(str):
103 '''(INTERNAL) Class list formatter.
104 '''
105 # see .ellipsoidalNvector.LatLon.deltaTo
106 def __call__(self, *Classes):
107 t = _or(*(C.__name__ for C in Classes))
108 return str.__mod__(self, t or MISSING)
111class Fmt(object):
112 '''Formatting options.
113 '''
114 ANGLE = _Fmt('<%s>')
115 COLON = _Fmt(':%s')
116# COLONSPACE = _Fmt(': %s') # == _COLONSPACE_(n, v)
117# COMMASPACE = _Fmt(', %s') # == _COMMASPACE_(n, v)
118 convergence = _Fmt(_convergence_(_PAREN_g))
119 CURLY = _Fmt('{%s}') # BRACES
120 distant = _Fmt(_distant_('(%.3g)'))
121 DOT = _Fmt('.%s') # == NN(_DOT_, n)
122 e = Fstr(_e_)
123 E = Fstr(_E_)
124 EQUAL = _Fmt(_EQUAL_(NN, '%s'))
125 EQUALSPACED = _Fmt(_EQUALSPACED_(NN, '%s'))
126 exceeds_eps = _Fmt(_exceeds_(_eps_, _PAREN_g))
127 exceeds_limit = _Fmt(_exceeds_(_limit_, _PAREN_g))
128 f = Fstr(_f_)
129 F = Fstr(_F_)
130 g = Fstr(_g_)
131 G = Fstr('G')
132 h = Fstr('%+.*f') # height, .streprs.hstr
133 limit = _Fmt(' %s limit') # .units
134 LOPEN = _Fmt('(%s]') # left-open range (L, R]
135 PAREN = _Fmt('(%s)')
136 PAREN_g = _Fmt(_PAREN_g)
137 PARENSPACED = _Fmt(' (%s)')
138 QUOTE2 = _Fmt('"%s"')
139 ROPEN = _Fmt('[%s)') # right-open range [L, R)
140# SPACE = _Fmt(' %s') # == _SPACE_(n, v)
141 SQUARE = _Fmt('[%s]') # BRACKETS
142 sub_class = _Sub('%s (sub-)class')
143 TAG = ANGLE
144 TAGEND = _Fmt('</%s>')
145 tolerance = _Fmt(_tolerance_(_PAREN_g))
146 zone = _Fmt('%02d') # .epsg, .mgrs, .utmupsBase
148 def __init__(self):
149 for n, a in self.__class__.__dict__.items():
150 if isinstance(a, (Fstr, _Fmt)):
151 setattr(a, _name_, n)
153 def __call__(self, obj, prec=9):
154 '''Return C{str(B{obj})} or C{repr(B{obj})}.
155 '''
156 return str(obj) if isint(obj) else next(
157 _streprs(prec, (obj,), Fmt.g, False, False, repr))
159 def no_convergence(self, _d, *tol, **thresh):
160 t = Fmt.convergence(fabs(_d))
161 if tol:
162 t = _COMMASPACE_(t, Fmt.tolerance(tol[0]))
163 if thresh and _xkwds_get(thresh, thresh=False):
164 t = t.replace(_tolerance_, _threshold_)
165 return _no_(t)
167Fmt = Fmt() # PYCHOK singleton
168Fmt.__name__ = Fmt.__class__.__name__
170_DOTSTAR_ = Fmt.DOT(_STAR_)
171# formats %G and %g drop all trailing zeros and the
172# decimal point, making the float appear as an int
173_Gg = (Fmt.G, Fmt.g)
174_FfEeGg = (Fmt.F, Fmt.f, Fmt.E, Fmt.e) + _Gg # float formats
175_Fspec_ = NN('[%[<flags>][<width>]', _DOTSTAR_, ']', _BAR_.join(_FfEeGg)) # in testStreprs
178def anstr(name, OKd=_OKd_, sub=_UNDER_):
179 '''Make a valid name of alphanumeric and OKd characters.
181 @arg name: The original name (C{str}).
182 @kwarg OKd: Other acceptable characters (C{str}).
183 @kwarg sub: Substitute for invalid charactes (C{str}).
185 @return: The modified name (C{str}).
187 @note: Leading and trailing whitespace characters are removed,
188 intermediate whitespace characters are coalesced and
189 substituted.
190 '''
191 s = n = str(name).strip()
192 for c in n:
193 if not (c.isalnum() or c in OKd or c in sub):
194 s = s.replace(c, _SPACE_)
195 return sub.join(s.strip().split())
198def attrs(inst, *names, **Nones_True__pairs_kwds): # prec=6, fmt=Fmt.F, ints=False, Nones=True, sep=_EQUAL_
199 '''Get instance attributes as I{name=value} strings, with C{float}s
200 formatted by function L{fstr}.
202 @arg inst: The instance (any C{type}).
203 @arg names: The attribute names, all other positional (C{str}).
204 @kwarg Nones_True__pairs_kwds: Keyword argument for function L{pairs}, except
205 C{B{Nones}=True} to in-/exclude missing or C{None}-valued attributes.
207 @return: A C{tuple(B{sep}.join(t) for t in zip(B{names}, reprs(values, ...)))}
208 of C{str}s.
209 '''
210 def _items(inst, names, Nones):
211 for n in names:
212 v = getattr(inst, n, None)
213 if Nones or v is not None:
214 yield n, v
216 def _Nones_kwds(Nones=True, **kwds):
217 return Nones, kwds
219 Nones, kwds = _Nones_kwds(**Nones_True__pairs_kwds)
220 return pairs(_items(inst, names, Nones), **kwds)
223def enstr2(easting, northing, prec, *extras, **wide_dot):
224 '''Return an MGRS/OSGR easting, northing string representations.
226 @arg easting: Easting from false easting (C{meter}).
227 @arg northing: Northing from from false northing (C{meter}).
228 @arg prec: Precision, the number of I{decimal} digits (C{int}) or if
229 negative, the number of I{units to drop}, like MGRS U{PRECISION
230 <https://GeographicLib.SourceForge.io/C++/doc/GeoConvert.1.html#PRECISION>}.
231 @arg extras: Optional leading items (C{str}s).
232 @kwarg wide_dot: Optional keword argument C{B{wide}=%d} for the number of I{unit digits}
233 (C{int}) and C{B{dot}=False} (C{bool}) to insert a decimal point.
235 @return: B{C{extras}} + 2-tuple C{(str(B{easting}), str(B{northing}))} or
236 + 2-tuple C{("", "")} for C{B{prec} <= -B{wide}}.
238 @raise ValueError: Invalid B{C{easting}}, B{C{northing}} or B{C{prec}}.
240 @note: The B{C{easting}} and B{C{northing}} values are I{truncated, not rounded}.
241 '''
242 t = extras
243 try: # like .dms.compassPoint
244 p = min(int(prec), _EN_PREC)
245 w = p + _xkwds_get(wide_dot, wide=_EN_WIDE)
246 if w > 0:
247 f = 10**p # truncate
248 d = (-p) if p > 0 and _xkwds_get(wide_dot, dot=False) else 0
249 t += (_0wdot(w, int(easting * f), d),
250 _0wdot(w, int(northing * f), d))
251 else: # prec <= -_EN_WIDE
252 t += (NN, NN)
253 except (TypeError, ValueError) as x:
254 raise _ValueError(easting=easting, northing=northing, prec=prec, cause=x)
255 return t
257if enstr2.__doc__: # PYCHOK expected
258 enstr2.__doc__ %= (_EN_WIDE,)
261def _enstr2m3(estr, nstr, wide=_EN_WIDE): # in .mgrs, .osgr
262 '''(INTERNAL) Convert east- and northing C{str}s to meter and resolution.
263 '''
264 def _s2m2(s, m): # e or n str to float meter
265 if _DOT_ in s:
266 m = 1 # meter
267 else:
268 s += _0_ * wide
269 s = _DOT_(s[:wide], s[wide:wide+_EN_PREC])
270 return float(s), m
272 e, m = _s2m2(estr, 0)
273 n, m = _s2m2(nstr, m)
274 if not m:
275 p = max(len(estr), len(nstr)) # 2 = Km, 5 = m, 7 = cm
276 m = 10**max(-_EN_PREC, wide - p) # resolution, meter
277 return e, n, m
280def fstr(floats, prec=6, fmt=Fmt.F, ints=False, sep=_COMMASPACE_, strepr=None):
281 '''Convert one or more floats to string, optionally stripped of trailing zero decimals.
283 @arg floats: Single or a list, sequence, tuple, etc. (C{scalar}s).
284 @kwarg prec: The C{float} precision, number of decimal digits (0..9).
285 Trailing zero decimals are stripped if B{C{prec}} is
286 positive, but kept for negative B{C{prec}} values. In
287 addition, trailing decimal zeros are stripped for U{alternate,
288 form '#'<https://docs.Python.org/3/library/stdtypes.html
289 #printf-style-string-formatting>}.
290 @kwarg fmt: Optional, C{float} format (C{str}).
291 @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}).
292 @kwarg sep: Separator joining the B{C{floats}} (C{str}).
293 @kwarg strepr: Optional callable to format non-C{floats} (typically
294 C{repr}, C{str}) or C{None} to raise a TypeError.
296 @return: The C{sep.join(strs(floats, ...)} joined (C{str}) or single
297 C{strs((floats,), ...)} (C{str}) if B{C{floats}} is C{scalar}.
298 '''
299 if isscalar(floats): # see Fstr.__call__ above
300 return next(_streprs(prec, (floats,), fmt, ints, True, strepr))
301 else:
302 return sep.join(_streprs(prec, floats, fmt, ints, True, strepr))
305def _fstrENH2(inst, prec, m): # in .css, .lcc, .utmupsBase
306 # (INTERNAL) For C{Css.} and C{Lcc.} C{toRepr} and C{toStr} and C{UtmUpsBase._toStr}.
307 t = inst.easting, inst.northing
308 t = tuple(_streprs(prec, t, Fmt.F, False, True, None))
309 T = _E_, _N_
310 if m is not None and fabs(inst.height): # fabs(self.height) > EPS
311 t += hstr(inst.height, prec=-2, m=m),
312 T += _H_,
313 return t, T
316def _fstrLL0(inst, prec, toRepr): # in .azimuthal, .css
317 # (INTERNAL) For C{_AlbersBase.}, C{_AzimuthalBase.} and C{CassiniSoldner.}
318 t = tuple(_streprs(prec, inst.latlon0, Fmt.F, False, True, None))
319 if toRepr:
320 n = inst.name
321 if n:
322 t += Fmt.EQUAL(_name_, repr(n)),
323 t = Fmt.PAREN(inst.classname, _COMMASPACE_.join(t))
324 return t
327def fstrzs(efstr, ap1z=False):
328 '''Strip trailing zero decimals from a C{float} string.
330 @arg efstr: Float with or without exponent (C{str}).
331 @kwarg ap1z: Append the decimal point and one zero decimal
332 if the B{C{efstr}} is all digits (C{bool}).
334 @return: Float (C{str}).
335 '''
336 s = efstr.find(_DOT_)
337 if s >= 0:
338 e = efstr.rfind(Fmt.e)
339 if e < 0:
340 e = efstr.rfind(Fmt.E)
341 if e < 0:
342 e = len(efstr)
343 s += 2 # keep 1st _DOT_ + _0_
344 if s < e and efstr[e-1] == _0_:
345 efstr = NN(efstr[:s], efstr[s:e].rstrip(_0_), efstr[e:])
347 elif ap1z:
348 # %.G and %.g formats may drop the decimal
349 # point and all trailing zeros, ...
350 if efstr.isdigit():
351 efstr += _DOT_ + _0_ # ... append or ...
352 else: # ... insert one dot and zero
353 e = efstr.rfind(Fmt.e)
354 if e < 0:
355 e = efstr.rfind(Fmt.E)
356 if e > 0:
357 efstr = NN(efstr[:e], _DOT_, _0_, efstr[e:])
359 return efstr
362def hstr(height, prec=2, fmt=Fmt.h, ints=False, m=NN):
363 '''Return a string for the height value.
365 @arg height: Height value (C{float}).
366 @kwarg prec: The C{float} precision, number of decimal digits (0..9).
367 Trailing zero decimals are stripped if B{C{prec}} is
368 positive, but kept for negative B{C{prec}} values.
369 @kwarg fmt: Optional, C{float} format (C{str}).
370 @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}).
371 @kwarg m: Optional unit of the height (C{str}).
372 '''
373 h = next(_streprs(prec, (height,), fmt, ints, True, None))
374 return NN(h, str(m)) if m else h
377def instr(inst, *args, **kwds):
378 '''Return the string representation of an instantiation.
380 @arg inst: The instance (any C{type}).
381 @arg args: Optional positional arguments.
382 @kwarg kwds: Optional keyword arguments.
384 @return: Representation (C{str}).
385 '''
386 return unstr(_MODS.named.classname(inst), *args, **kwds)
389def lrstrip(txt, lrpairs=_LR_PAIRS):
390 '''Left- I{and} right-strip parentheses, brackets, etc. from a string.
392 @arg txt: String to be stripped (C{str}).
393 @kwarg lrpairs: Parentheses, etc. to remove (C{dict} of one or several
394 C{(Left, Right)} pairs).
396 @return: Stripped B{C{txt}} (C{str}).
397 '''
398 _e, _s, _n = str.endswith, str.startswith, len
399 while _n(txt) > 2:
400 for L, R in lrpairs.items():
401 if _e(txt, R) and _s(txt, L):
402 txt = txt[_n(L):-_n(R)]
403 break # restart
404 else:
405 return txt
408def pairs(items, prec=6, fmt=Fmt.F, ints=False, sep=_EQUAL_):
409 '''Convert items to I{name=value} strings, with C{float}s handled like L{fstr}.
411 @arg items: Name-value pairs (C{dict} or 2-{tuple}s of any C{type}s).
412 @kwarg prec: The C{float} precision, number of decimal digits (0..9).
413 Trailing zero decimals are stripped if B{C{prec}} is
414 positive, but kept for negative B{C{prec}} values.
415 @kwarg fmt: Optional, C{float} format (C{str}).
416 @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}).
417 @kwarg sep: Separator joining I{names} and I{values} (C{str}).
419 @return: A C{tuple(B{sep}.join(t) for t in B{items}))} of C{str}s.
420 '''
421 try:
422 if isinstance(items, dict):
423 items = itemsorted(items)
424 elif not islistuple(items):
425 items = tuple(items)
426 # can't unzip empty items tuple, list, etc.
427 n, v = _zip(*items) if items else ((), ()) # strict=True
428 except (TypeError, ValueError):
429 raise _IsnotError(dict.__name__, '2-tuples', items=items)
430 v = _streprs(prec, v, fmt, ints, False, repr)
431 return tuple(sep.join(t) for t in _zip(map(str, n), v)) # strict=True
434def _pct(fmt):
435 '''(INTERNAL) Prefix C{%} if needed.
436 '''
437 return fmt if _PERCENT_ in fmt else NN(_PERCENT_, fmt)
440def reprs(objs, prec=6, fmt=Fmt.F, ints=False):
441 '''Convert objects to C{repr} strings, with C{float}s handled like L{fstr}.
443 @arg objs: List, sequence, tuple, etc. (any C{type}s).
444 @kwarg prec: The C{float} precision, number of decimal digits (0..9).
445 Trailing zero decimals are stripped if B{C{prec}} is
446 positive, but kept for negative B{C{prec}} values.
447 @kwarg fmt: Optional, C{float} format (C{str}).
448 @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}).
450 @return: A C{tuple(map(fstr|repr, objs))} of C{str}s.
451 '''
452 return tuple(_streprs(prec, objs, fmt, ints, False, repr)) if objs else ()
455def _resolution10(resolution, Error=ValueError): # in .mgrs, .osgr
456 '''(INTERNAL) Validate C{resolution} in C{meter}.
457 '''
458 try:
459 r = int(_log10(resolution))
460 if _EN_WIDE < r or r < -_EN_PREC:
461 raise ValueError
462 except (ValueError, TypeError):
463 raise Error(resolution=resolution)
464 return _MODS.units.Meter(resolution=10**r)
467def _streprs(prec, objs, fmt, ints, force, strepr):
468 '''(INTERNAL) Helper for C{fstr}, C{pairs}, C{reprs} and C{strs}
469 '''
470 # <https://docs.Python.org/3/library/stdtypes.html#printf-style-string-formatting>
471 if fmt in _FfEeGg:
472 fGg = fmt in _Gg
473 fmt = NN(_PERCENT_, _DOT_, abs(prec), fmt)
475 elif fmt.startswith(_PERCENT_):
476 fGg = False
477 try: # to make sure fmt is valid
478 f = fmt.replace(_DOTSTAR_, Fmt.DOT(abs(prec)))
479 _ = f % (_0_0,)
480 except (TypeError, ValueError):
481 raise _ValueError(fmt=fmt, txt=_not_(repr(_DOTSTAR_)))
482 fmt = f
484 else:
485 raise _ValueError(fmt=fmt, txt=_not_(repr(_Fspec_)))
487 for i, o in enumerate(objs):
488 if force or isinstance(o, float):
489 t = fmt % (float(o),)
490 if ints and t.rstrip(_0to9_ if isint(o, both=True) else
491 _0_).endswith(_DOT_):
492 t = t.split(_DOT_)[0]
493 elif prec > 1:
494 t = fstrzs(t, ap1z=fGg)
495 elif strepr:
496 t = strepr(o)
497 else:
498 t = Fmt.PARENSPACED(Fmt.SQUARE(objs=i), o)
499 raise TypeError(_SPACE_(t, _not_scalar_))
500 yield t
503def strs(objs, prec=6, fmt=Fmt.F, ints=False):
504 '''Convert objects to C{str} strings, with C{float}s handled like L{fstr}.
506 @arg objs: List, sequence, tuple, etc. (any C{type}s).
507 @kwarg prec: The C{float} precision, number of decimal digits (0..9).
508 Trailing zero decimals are stripped if B{C{prec}} is
509 positive, but kept for negative B{C{prec}} values.
510 @kwarg fmt: Optional, C{float} format (C{str}).
511 @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}).
513 @return: A C{tuple(map(fstr|str, objs))} of C{str}s.
514 '''
515 return tuple(_streprs(prec, objs, fmt, ints, False, str)) if objs else ()
518def unstr(where, *args, **kwds):
519 '''Return the string representation of an invokation.
521 @arg where: Class, function, method (C{type}) or name (C{str}).
522 @arg args: Optional positional arguments.
523 @kwarg kwds: Optional keyword arguments, except
524 C{B{_ELLIPSIS}=False}.
526 @return: Representation (C{str}).
527 '''
528 t = reprs(args, fmt=Fmt.g) if args else ()
529 if kwds and _xkwds_pop(kwds, _ELLIPSIS=False):
530 t += _ELLIPSIS_,
531 if kwds:
532 t += pairs(itemsorted(kwds), fmt=Fmt.g)
533 n = where if isstr(where) else _dunder_nameof(where)
534 return Fmt.PAREN(n, _COMMASPACE_.join(t))
537def _0wd(*w_i): # in .osgr, .wgrs
538 '''(INTERNAL) Int formatter'.
539 '''
540 return '%0*d' % w_i
543def _0wdot(w, f, dot=0):
544 '''(INTERNAL) Int and Float formatter'.
545 '''
546 s = _0wd(w, int(f))
547 if dot:
548 s = _DOT_(s[:dot], s[dot:])
549 return s
552def _0wpF(*w_p_f): # in .dms, .osgr
553 '''(INTERNAL) Float deg, min, sec formatter'.
554 '''
555 return '%0*.*f' % w_p_f # XXX was F
558def _xattrs(insto, other, *attrs):
559 '''(INTERNAL) Copy attribute values from B{C{other}} to B{C{insto}}.
561 @arg insto: Object to copy attribute values to (any C{type}).
562 @arg other: Object to copy attribute values from (any C{type}).
563 @arg attrs: One or more attribute names (C{str}s).
565 @return: Object B{C{insto}}, updated.
567 @raise AttributeError: An B{C{attrs}} doesn't exist
568 or is not settable.
569 '''
570 def _getattr(o, a):
571 if hasattr(o, a):
572 return getattr(o, a)
573 try:
574 n = o._DOT_(a)
575 except AttributeError:
576 n = Fmt.DOT(a)
577 raise _AttributeError(o, name=n)
579 for a in attrs:
580 s = _getattr(other, a)
581 g = _getattr(insto, a)
582 if (g is None and s is not None) or g != s:
583 setattr(insto, a, s) # not settable?
584 return insto
587def _xzipairs(names, values, sep=_COMMASPACE_, fmt=NN, pair_fmt=Fmt.COLON):
588 '''(INTERNAL) Zip C{names} and C{values} into a C{str}, joined and bracketed.
589 '''
590 try:
591 t = sep.join(pair_fmt(*t) for t in _zip(names, values)) # strict=True
592 except Exception as x:
593 raise _ValueError(names=names, values=values, cause=x)
594 return (fmt % (t,)) if fmt else t
596# **) MIT License
597#
598# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved.
599#
600# Permission is hereby granted, free of charge, to any person obtaining a
601# copy of this software and associated documentation files (the "Software"),
602# to deal in the Software without restriction, including without limitation
603# the rights to use, copy, modify, merge, publish, distribute, sublicense,
604# and/or sell copies of the Software, and to permit persons to whom the
605# Software is furnished to do so, subject to the following conditions:
606#
607# The above copyright notice and this permission notice shall be included
608# in all copies or substantial portions of the Software.
609#
610# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
611# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
612# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
613# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
614# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
615# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
616# OTHER DEALINGS IN THE SOFTWARE.