Coverage for pygeodesy/basics.py: 90%

218 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-08-07 07:28 -0400

1 

2# -*- coding: utf-8 -*- 

3 

4u'''Some, basic definitions, functions and dependencies. 

5 

6Use env variable C{PYGEODESY_XPACKAGES} to avoid import of dependencies 

7C{geographiclib}, C{numpy} and/or C{scipy}. Set C{PYGEODESY_XPACKAGES} 

8to a comma-separated list of package names to be excluded from import. 

9''' 

10# make sure int/int division yields float quotient 

11from __future__ import division 

12division = 1 / 2 # .albers, .azimuthal, .constants, etc., .utily 

13if not division: 

14 raise ImportError('%s 1/2 == %s' % ('division', division)) 

15del division 

16 

17from pygeodesy.errors import _AssertionError, _AttributeError, _ImportError, \ 

18 _TypeError, _TypesError, _ValueError, _xkwds_get 

19from pygeodesy.interns import MISSING, NN, _by_, _DOT_, _ELLIPSIS4_, _enquote, \ 

20 _EQUAL_, _in_, _invalid_, _N_A_, _SPACE_, \ 

21 _splituple, _UNDER_, _version_ # _utf_8_ 

22from pygeodesy.lazily import _ALL_LAZY, _ALL_MODS as _MODS, _FOR_DOCS, \ 

23 _getenv, _sys, _sys_version_info2 

24 

25from copy import copy as _copy, deepcopy as _deepcopy 

26from math import copysign as _copysign 

27import inspect as _inspect 

28 

29__all__ = _ALL_LAZY.basics 

30__version__ = '23.06.23' 

31 

32_0_0 = 0.0 # in .constants 

33_below_ = 'below' 

34_cannot_ = 'cannot' 

35_list_tuple_types = (list, tuple) 

36_list_tuple_set_types = (list, tuple, set) 

37_odd_ = 'odd' 

38_required_ = 'required' 

39_PYGEODESY_XPACKAGES_ = 'PYGEODESY_XPACKAGES' 

40_XPACKAGES = _splituple(_getenv(_PYGEODESY_XPACKAGES_, NN)) 

41 

42try: # Luciano Ramalho, "Fluent Python", page 395, O'Reilly, 2016 

43 from numbers import Integral as _Ints, Real as _Scalars 

44except ImportError: 

45 try: 

46 _Ints = int, long # int objects (C{tuple}) 

47 except NameError: # Python 3+ 

48 _Ints = int, # int objects (C{tuple}) 

49 _Scalars = _Ints + (float,) 

50 

51try: 

52 try: # use C{from collections.abc import ...} in Python 3.9+ 

53 from collections.abc import Sequence as _Sequence # in .points 

54 except ImportError: # no .abc in Python 3.8- and 2.7- 

55 from collections import Sequence as _Sequence # in .points 

56 if isinstance([], _Sequence) and isinstance((), _Sequence): 

57 # and isinstance(range(1), _Sequence): 

58 _Seqs = _Sequence 

59 else: 

60 raise ImportError # _AssertionError 

61except ImportError: 

62 _Sequence = tuple # immutable for .points._Basequence 

63 _Seqs = list, _Sequence # , range for function len2 below 

64 

65try: 

66 _Bytes = unicode, bytearray # PYCHOK expected 

67 _Strs = basestring, str # XXX , bytes 

68 

69 def _NOP(x): 

70 '''NOP, pass thru.''' 

71 return x 

72 

73 str2ub = ub2str = _NOP # avoids UnicodeDecodeError 

74 

75 def _Xstr(exc): # PYCHOK no cover 

76 '''I{Invoke only with caught ImportError} B{C{exc}}. 

77 

78 C{... "cannot import name _distributor_init" ...} 

79 

80 only for C{numpy}, C{scipy} import errors occurring 

81 on arm64 Apple Silicon running macOS' Python 2.7.16? 

82 ''' 

83 t = str(exc) 

84 if '_distributor_init' in t: 

85 from sys import exc_info 

86 from traceback import extract_tb 

87 tb = exc_info()[2] # 3-tuple (type, value, traceback) 

88 t4 = extract_tb(tb, 1)[0] # 4-tuple (file, line, name, 'import ...') 

89 t = _SPACE_(_cannot_, t4[3] or _N_A_) 

90 del tb, t4 

91 return t 

92 

93except NameError: # Python 3+ 

94 from pygeodesy.interns import _utf_8_ 

95 

96 _Bytes = bytes, bytearray 

97 _Strs = str, # tuple 

98 _Xstr = str 

99 

100 def str2ub(sb): 

101 '''Convert C{str} to C{unicode bytes}. 

102 ''' 

103 if isinstance(sb, _Strs): 

104 sb = sb.encode(_utf_8_) 

105 return sb 

106 

107 def ub2str(ub): 

108 '''Convert C{unicode bytes} to C{str}. 

109 ''' 

110 if isinstance(ub, _Bytes): 

111 ub = str(ub.decode(_utf_8_)) 

112 return ub 

113 

114 

115def clips(sb, limit=50, white=NN): 

116 '''Clip a string to the given length limit. 

117 

118 @arg sb: String (C{str} or C{bytes}). 

119 @kwarg limit: Length limit (C{int}). 

120 @kwarg white: Optionally, replace all whitespace (C{str}). 

121 

122 @return: The clipped or unclipped B{C{sb}}. 

123 ''' 

124 T = type(sb) 

125 if len(sb) > limit > 8: 

126 h = limit // 2 

127 sb = T(_ELLIPSIS4_).join((sb[:h], sb[-h:])) 

128 if white: # replace whitespace 

129 sb = T(white).join(sb.split()) 

130 return sb 

131 

132 

133def copysign0(x, y): 

134 '''Like C{math.copysign(x, y)} except C{zero}, I{unsigned}. 

135 

136 @return: C{math.copysign(B{x}, B{y})} if B{C{x}} else 

137 C{type(B{x})(0)}. 

138 ''' 

139 return _copysign(x, (y if y else 0)) if x else copytype(0, x) 

140 

141 

142def copytype(x, y): 

143 '''Return the value of B{x} as C{type} of C{y}. 

144 

145 @return: C{type(B{y})(B{x})}. 

146 ''' 

147 return type(y)(x if x else _0_0) 

148 

149 

150def halfs2(str2): 

151 '''Split a string in 2 halfs. 

152 

153 @arg str2: String to split (C{str}). 

154 

155 @return: 2-Tuple C{(_1st, _2nd)} half (C{str}). 

156 

157 @raise ValueError: Zero or odd C{len(B{str2})}. 

158 ''' 

159 h, r = divmod(len(str2), 2) 

160 if r or not h: 

161 raise _ValueError(str2=str2, txt=_odd_) 

162 return str2[:h], str2[h:] 

163 

164 

165def isbool(obj): 

166 '''Check whether an object is C{bool}ean. 

167 

168 @arg obj: The object (any C{type}). 

169 

170 @return: C{True} if B{C{obj}} is C{bool}ean, 

171 C{False} otherwise. 

172 ''' 

173 return isinstance(obj, bool) # and (obj is False 

174# or obj is True) 

175 

176if isbool(1) or isbool(0): # PYCHOK assert 

177 raise _AssertionError(isbool=1) 

178 

179if _FOR_DOCS: # XXX avoid epidoc Python 2.7 error 

180 

181 def isclass(obj): 

182 '''Return C{True} if B{C{obj}} is a C{class} or C{type}. 

183 

184 @see: Python's C{inspect.isclass}. 

185 ''' 

186 return _inspect.isclass(obj) 

187else: 

188 isclass = _inspect.isclass 

189 

190 

191def iscomplex(obj): 

192 '''Check whether an object is a C{complex} or complex C{str}. 

193 

194 @arg obj: The object (any C{type}). 

195 

196 @return: C{True} if B{C{obj}} is C{complex}, otherwise 

197 C{False}. 

198 ''' 

199 try: # hasattr('conjugate'), hasattr('real') and hasattr('imag') 

200 return isinstance(obj, complex) or (isstr(obj) 

201 and isinstance(complex(obj), complex)) # numbers.Complex? 

202 except (TypeError, ValueError): 

203 return False 

204 

205 

206def isfloat(obj): 

207 '''Check whether an object is a C{float} or float C{str}. 

208 

209 @arg obj: The object (any C{type}). 

210 

211 @return: C{True} if B{C{obj}} is a C{float}, otherwise 

212 C{False}. 

213 ''' 

214 try: 

215 return isinstance( obj, float) or (isstr(obj) 

216 and isinstance(float(obj), float)) 

217 except (TypeError, ValueError): 

218 return False 

219 

220 

221try: 

222 isidentifier = str.isidentifier # Python 3, must be str 

223except AttributeError: # Python 2- 

224 

225 def isidentifier(obj): 

226 '''Return C{True} if B{C{obj}} is a Python identifier. 

227 ''' 

228 return bool(obj and isstr(obj) 

229 and obj.replace(_UNDER_, NN).isalnum() 

230 and not obj[:1].isdigit()) 

231 

232 

233def isinstanceof(obj, *classes): 

234 '''Check an instance of one or several C{classes}. 

235 

236 @arg obj: The instance (C{any}). 

237 @arg classes: One or more classes (C{class}). 

238 

239 @return: C{True} if B{C{obj}} is in instance of 

240 one of the B{C{classes}}. 

241 ''' 

242 return isinstance(obj, classes) 

243 

244 

245def isint(obj, both=False): 

246 '''Check for C{int} type or an integer C{float} value. 

247 

248 @arg obj: The object (any C{type}). 

249 @kwarg both: If C{true}, check C{float} and L{Fsum} 

250 type and value (C{bool}). 

251 

252 @return: C{True} if B{C{obj}} is C{int} or I{integer} 

253 C{float} or L{Fsum}, C{False} otherwise. 

254 

255 @note: Both C{isint(True)} and C{isint(False)} return 

256 C{False} (and no longer C{True}). 

257 ''' 

258 if isinstance(obj, _Ints) and not isbool(obj): 

259 return True 

260 elif both: # and isinstance(obj, (float, Fsum)) 

261 try: # NOT , _Scalars) to include Fsum! 

262 return obj.is_integer() 

263 except AttributeError: 

264 pass # XXX float(int(obj)) == obj? 

265 return False 

266 

267 

268try: 

269 from keyword import iskeyword # Python 2.7+ 

270except ImportError: 

271 

272 def iskeyword(unused): 

273 '''Not Implemented, C{False} always. 

274 ''' 

275 return False 

276 

277 

278def islistuple(obj, minum=0): 

279 '''Check for list or tuple C{type} with a minumal length. 

280 

281 @arg obj: The object (any C{type}). 

282 @kwarg minum: Minimal C{len} required C({int}). 

283 

284 @return: C{True} if B{C{obj}} is C{list} or C{tuple} with 

285 C{len} at least B{C{minum}}, C{False} otherwise. 

286 ''' 

287 return type(obj) in _list_tuple_types and len(obj) >= (minum or 0) 

288 

289 

290def isodd(x): 

291 '''Is B{C{x}} odd? 

292 

293 @arg x: Value (C{scalar}). 

294 

295 @return: C{True} if B{C{x}} is odd, 

296 C{False} otherwise. 

297 ''' 

298 return bool(int(x) & 1) # == bool(int(x) % 2) 

299 

300 

301def isscalar(obj): 

302 '''Check for scalar types. 

303 

304 @arg obj: The object (any C{type}). 

305 

306 @return: C{True} if B{C{obj}} is C{scalar}, C{False} otherwise. 

307 ''' 

308 return isinstance(obj, _Scalars) and not isbool(obj) 

309 

310 

311def issequence(obj, *excls): 

312 '''Check for sequence types. 

313 

314 @arg obj: The object (any C{type}). 

315 @arg excls: Classes to exclude (C{type}), all positional. 

316 

317 @note: Excluding C{tuple} implies excluding C{namedtuple}. 

318 

319 @return: C{True} if B{C{obj}} is a sequence, C{False} otherwise. 

320 ''' 

321 return isinstance(obj, _Seqs) and not (excls and isinstance(obj, excls)) 

322 

323 

324def isstr(obj): 

325 '''Check for string types. 

326 

327 @arg obj: The object (any C{type}). 

328 

329 @return: C{True} if B{C{obj}} is C{str}, C{False} otherwise. 

330 ''' 

331 return isinstance(obj, _Strs) 

332 

333 

334def issubclassof(Sub, *Supers): 

335 '''Check whether a class is a sub-class of some other class(es). 

336 

337 @arg Sub: The sub-class (C{class}). 

338 @arg Supers: One or more C(super) classes (C{class}). 

339 

340 @return: C{True} if B{C{Sub}} is a sub-class of any B{C{Supers}}, 

341 C{False} if not (C{bool}) or C{None} if B{C{Sub}} is not 

342 a class or if no B{C{Supers}} are given or none of those 

343 are a class. 

344 ''' 

345 if isclass(Sub): 

346 t = tuple(S for S in Supers if isclass(S)) 

347 if t: 

348 return bool(issubclass(Sub, t)) 

349 return None 

350 

351 

352def len2(items): 

353 '''Make built-in function L{len} work for generators, iterators, 

354 etc. since those can only be started exactly once. 

355 

356 @arg items: Generator, iterator, list, range, tuple, etc. 

357 

358 @return: 2-Tuple C{(n, items)} of the number of items (C{int}) 

359 and the items (C{list} or C{tuple}). 

360 ''' 

361 if not isinstance(items, _Seqs): # NOT hasattr(items, '__len__'): 

362 items = list(items) 

363 return len(items), items 

364 

365 

366def map1(fun1, *xs): # XXX map_ 

367 '''Apply each B{C{xs}} to a single-argument function and 

368 return a C{tuple} of results. 

369 

370 @arg fun1: 1-Arg function to apply (C{callable}). 

371 @arg xs: Arguments to apply (C{any positional}). 

372 

373 @return: Function results (C{tuple}). 

374 ''' 

375 return tuple(map(fun1, xs)) 

376 

377 

378def map2(func, *xs): 

379 '''Apply arguments to a function and return a C{tuple} of results. 

380 

381 Unlike Python 2's built-in L{map}, Python 3+ L{map} returns a 

382 L{map} object, an iterator-like object which generates the 

383 results only once. Converting the L{map} object to a tuple 

384 maintains the Python 2 behavior. 

385 

386 @arg func: Function to apply (C{callable}). 

387 @arg xs: Arguments to apply (C{list, tuple, ...}). 

388 

389 @return: Function results (C{tuple}). 

390 ''' 

391 return tuple(map(func, *xs)) 

392 

393 

394def neg(x): 

395 '''Negate C{x} unless C{zero} or C{NEG0}. 

396 

397 @return: C{-B{x}} if B{C{x}} else C{0.0}. 

398 ''' 

399 return (-x) if x else _0_0 

400 

401 

402def neg_(*xs): 

403 '''Negate all C{xs} with L{neg}. 

404 

405 @return: A C{map(neg, B{xs})}. 

406 ''' 

407 return map(neg, xs) 

408 

409 

410def _reverange(n): 

411 '''(INTERNAL) Reversed range yielding (n-1, n-2, ..., 1, 0). 

412 ''' 

413 return range(n - 1, -1, -1) 

414 

415 

416def signBit(x): 

417 '''Return C{signbit(B{x})}, like C++. 

418 

419 @return: C{True} if C{B{x} < 0} or C{NEG0} (C{bool}). 

420 ''' 

421 return x < 0 or _MODS.constants.isneg0(x) 

422 

423 

424def _signOf(x, ref): # in .fsums 

425 '''(INTERNAL) Return the sign of B{C{x}} versus B{C{ref}}. 

426 ''' 

427 return +1 if x > ref else (-1 if x < ref else 0) 

428 

429 

430def signOf(x): 

431 '''Return sign of C{x} as C{int}. 

432 

433 @return: -1, 0 or +1 (C{int}). 

434 ''' 

435 try: 

436 s = x.signOf() # Fsum instance? 

437 except AttributeError: 

438 s = _signOf(x, 0) 

439 return s 

440 

441 

442def _sizeof(inst): 

443 '''(INTERNAL) Recursively size an C{inst}ance. 

444 

445 @return: Instance' size in bytes (C{int}), 

446 ignoring class attributes and 

447 counting duplicates only once. 

448 ''' 

449 _zB = _sys.getsizeof 

450 _zD = _zB(None) # some default 

451 

452 def _zR(s, iterable): 

453 z, _s = 0, s.add 

454 for o in iterable: 

455 i = id(o) 

456 if i not in s: 

457 _s(i) 

458 z += _zB(o, _zD) 

459 if isinstance(o, dict): 

460 z += _zR(s, o.keys()) 

461 z += _zR(s, o.values()) 

462 elif isinstance(o, _list_tuple_set_types): 

463 z += _zR(s, o) 

464 else: 

465 try: # size instance' attr values only 

466 z += _zR(s, o.__dict__.values()) 

467 except AttributeError: # None, int, etc. 

468 pass 

469 return z 

470 

471 return _zR(set(), (inst,)) 

472 

473 

474def splice(iterable, n=2, **fill): 

475 '''Split an iterable into C{n} slices. 

476 

477 @arg iterable: Items to be spliced (C{list}, C{tuple}, ...). 

478 @kwarg n: Number of slices to generate (C{int}). 

479 @kwarg fill: Optional fill value for missing items. 

480 

481 @return: A generator for each of B{C{n}} slices, 

482 M{iterable[i::n] for i=0..n}. 

483 

484 @raise TypeError: Invalid B{C{n}}. 

485 

486 @note: Each generated slice is a C{tuple} or a C{list}, 

487 the latter only if the B{C{iterable}} is a C{list}. 

488 

489 @example: 

490 

491 >>> from pygeodesy import splice 

492 

493 >>> a, b = splice(range(10)) 

494 >>> a, b 

495 ((0, 2, 4, 6, 8), (1, 3, 5, 7, 9)) 

496 

497 >>> a, b, c = splice(range(10), n=3) 

498 >>> a, b, c 

499 ((0, 3, 6, 9), (1, 4, 7), (2, 5, 8)) 

500 

501 >>> a, b, c = splice(range(10), n=3, fill=-1) 

502 >>> a, b, c 

503 ((0, 3, 6, 9), (1, 4, 7, -1), (2, 5, 8, -1)) 

504 

505 >>> tuple(splice(list(range(9)), n=5)) 

506 ([0, 5], [1, 6], [2, 7], [3, 8], [4]) 

507 

508 >>> splice(range(9), n=1) 

509 <generator object splice at 0x0...> 

510 ''' 

511 if not isint(n): 

512 raise _TypeError(n=n) 

513 

514 t = iterable 

515 if not isinstance(t, _list_tuple_types): 

516 t = tuple(t) # force tuple, also for PyPy3 

517 

518 if n > 1: 

519 if fill: 

520 fill = _xkwds_get(fill, fill=MISSING) 

521 if fill is not MISSING: 

522 m = len(t) % n 

523 if m > 0: # same type fill 

524 t += type(t)((fill,) * (n - m)) 

525 for i in range(n): 

526 # XXX t[i::n] chokes PyChecker 

527 yield t[slice(i, None, n)] 

528 else: 

529 yield t 

530 

531 

532def unsigned0(x): 

533 '''Unsign if C{0.0}. 

534 

535 @return: C{B{x}} if B{C{x}} else C{0.0}. 

536 ''' 

537 return x if x else _0_0 

538 

539 

540def _xargs_names(callabl): 

541 '''(INTERNAL) Get the C{callabl}'s args names. 

542 ''' 

543 try: 

544 args_kwds = _inspect.signature(callabl).parameters.keys() 

545 except AttributeError: # .signature new Python 3+ 

546 args_kwds = _inspect.getargspec(callabl).args 

547 return tuple(args_kwds) 

548 

549 

550def _xcopy(inst, deep=False): 

551 '''(INTERNAL) Copy an object, shallow or deep. 

552 

553 @arg inst: The object to copy (any C{type}). 

554 @kwarg deep: If C{True} make a deep, otherwise 

555 a shallow copy (C{bool}). 

556 

557 @return: The copy of B{C{inst}}. 

558 ''' 

559 return _deepcopy(inst) if deep else _copy(inst) 

560 

561 

562def _xdup(inst, **items): 

563 '''(INTERNAL) Duplicate an object, replacing some attributes. 

564 

565 @arg inst: The object to copy (any C{type}). 

566 @kwarg items: Attributes to be changed (C{any}). 

567 

568 @return: Shallow duplicate of B{C{inst}} with modified 

569 attributes, if any B{C{items}}. 

570 

571 @raise AttributeError: Some B{C{items}} invalid. 

572 ''' 

573 d = _xcopy(inst, deep=False) 

574 for n, v in items.items(): 

575 if not hasattr(d, n): 

576 t = _MODS.named.classname(inst) 

577 t = _SPACE_(_DOT_(t, n), _invalid_) 

578 raise _AttributeError(txt=t, this=inst, **items) 

579 setattr(d, n, v) 

580 return d 

581 

582 

583def _xgeographiclib(where, *required): 

584 '''(INTERNAL) Import C{geographiclib} and check required version. 

585 ''' 

586 try: 

587 _xpackage(_xgeographiclib) 

588 import geographiclib 

589 except ImportError as x: 

590 raise _xImportError(x, where) 

591 return _xversion(geographiclib, where, *required) 

592 

593 

594def _xImportError(x, where, **name): 

595 '''(INTERNAL) Embellish an C{ImportError}. 

596 ''' 

597 t = _SPACE_(_required_, _by_, _xwhere(where, **name)) 

598 return _ImportError(_Xstr(x), txt=t, cause=x) 

599 

600 

601def _xinstanceof(*Types, **name_value_pairs): 

602 '''(INTERNAL) Check C{Types} of all C{name=value} pairs. 

603 

604 @arg Types: One or more classes or types (C{class}), 

605 all positional. 

606 @kwarg name_value_pairs: One or more C{B{name}=value} pairs 

607 with the C{value} to be checked. 

608 

609 @raise TypeError: One of the B{C{name_value_pairs}} is not 

610 an instance of any of the B{C{Types}}. 

611 ''' 

612 if Types and name_value_pairs: 

613 for n, v in name_value_pairs.items(): 

614 if not isinstance(v, Types): 

615 raise _TypesError(n, v, *Types) 

616 else: 

617 raise _AssertionError(Types=Types, name_value_pairs=name_value_pairs) 

618 

619 

620def _xnumpy(where, *required): 

621 '''(INTERNAL) Import C{numpy} and check required version. 

622 ''' 

623 try: 

624 _xpackage(_xnumpy) 

625 import numpy 

626 except ImportError as x: 

627 raise _xImportError(x, where) 

628 return _xversion(numpy, where, *required) 

629 

630 

631def _xpackage(_xpkg): 

632 '''(INTERNAL) Check dependency to be excluded. 

633 ''' 

634 n = _xpkg.__name__[2:] 

635 if n in _XPACKAGES: 

636 x = _SPACE_(n, _in_, _PYGEODESY_XPACKAGES_) 

637 e = _enquote(_getenv(_PYGEODESY_XPACKAGES_, NN)) 

638 raise ImportError(_EQUAL_(x, e)) 

639 

640 

641def _xor(x, *xs): 

642 '''(INTERNAL) Exclusive-or C{x} and C{xs}. 

643 ''' 

644 for x_ in xs: 

645 x ^= x_ 

646 return x 

647 

648 

649def _xscipy(where, *required): 

650 '''(INTERNAL) Import C{scipy} and check required version. 

651 ''' 

652 try: 

653 _xpackage(_xscipy) 

654 import scipy 

655 except ImportError as x: 

656 raise _xImportError(x, where) 

657 return _xversion(scipy, where, *required) 

658 

659 

660def _xsubclassof(*Classes, **name_value_pairs): 

661 '''(INTERNAL) Check (super) class of all C{name=value} pairs. 

662 

663 @arg Classes: One or more classes or types (C{class}), 

664 all positional. 

665 @kwarg name_value_pairs: One or more C{B{name}=value} pairs 

666 with the C{value} to be checked. 

667 

668 @raise TypeError: One of the B{C{name_value_pairs}} is not 

669 a (sub-)class of any of the B{C{Classes}}. 

670 ''' 

671 for n, v in name_value_pairs.items(): 

672 if not issubclassof(v, *Classes): 

673 raise _TypesError(n, v, *Classes) 

674 

675 

676def _xversion(package, where, *required, **name): 

677 '''(INTERNAL) Check the C{package} version vs B{C{required}}. 

678 ''' 

679 n = len(required) 

680 if n: 

681 t = _xversion_info(package) 

682 if t[:n] < required: 

683 t = _SPACE_(package.__name__, _version_, _DOT_(*t), 

684 _below_, _DOT_(*required), 

685 _required_, _by_, _xwhere(where, **name)) 

686 raise ImportError(t) 

687 return package 

688 

689 

690def _xversion_info(package): # in .karney 

691 '''(INTERNAL) Get the C{package.__version_info__} as a 2- or 

692 3-tuple C{(major, minor, revision)} if C{int}s. 

693 ''' 

694 try: 

695 t = package.__version_info__ 

696 except AttributeError: 

697 t = package.__version__.strip() 

698 t = t.replace(_DOT_, _SPACE_).split()[:3] 

699 return map2(int, t) 

700 

701 

702def _xwhere(where, **name): 

703 '''(INTERNAL) Get the fully qualified name. 

704 ''' 

705 m = _MODS.named.modulename(where, prefixed=True) 

706 if name: 

707 n = _xkwds_get(name, name=NN) 

708 if n: 

709 m = _DOT_(m, n) 

710 return m 

711 

712 

713if _sys_version_info2 < (3, 10): # see .errors 

714 _zip = zip # PYCHOK exported 

715else: # Python 3.10+ 

716 

717 def _zip(*args): 

718 return zip(*args, strict=True) 

719 

720# **) MIT License 

721# 

722# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved. 

723# 

724# Permission is hereby granted, free of charge, to any person obtaining a 

725# copy of this software and associated documentation files (the "Software"), 

726# to deal in the Software without restriction, including without limitation 

727# the rights to use, copy, modify, merge, publish, distribute, sublicense, 

728# and/or sell copies of the Software, and to permit persons to whom the 

729# Software is furnished to do so, subject to the following conditions: 

730# 

731# The above copyright notice and this permission notice shall be included 

732# in all copies or substantial portions of the Software. 

733# 

734# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 

735# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

736# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 

737# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 

738# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 

739# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 

740# OTHER DEALINGS IN THE SOFTWARE.