Coverage for pygeodesy/interns.py: 97%

445 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-09-20 13:43 -0400

1# -*- coding: utf-8 -*- 

2 

3u'''Single C{str}ing constants, C{intern}'ed across C{pygeodesy} 

4modules and function L{pygeodesy.machine}. 

5''' 

6import sys as _sys 

7 

8_COMMASPACE_ = ', ' # overriden below 

9_pf2List = [] # cached _platform2 list 

10_Py3List = [] # cached _pythonarchine list 

11 

12_sub_packages = 'auxilats', 'deprecated', 'geodesicx' # PYCHOK in .lazily, 

13# ... make._dist, MANIFEST, setup.setup, test.bases, test.testModules 

14 

15 

16class _Dash(str): 

17 '''(INTERNAL) Extended C{str} for prefix_DASH_. 

18 ''' 

19 def __call__(self, *args): 

20 '''Join C{self} plus all B{C{args}} like C{'-'.join((self,) + B{args})}. 

21 ''' 

22 return _DASH_(self, *args) # re-callable 

23 

24 

25class _Int(int): 

26 '''(INTERNAL) Unique C{int}. 

27 ''' 

28 pass 

29 

30 

31class Str_(str): 

32 '''Extended, I{callable} C{str} class, not nameable. 

33 

34 @see: Nameable and callable class L{pygeodesy.Str}. 

35 ''' 

36 def join_(self, *args): 

37 '''Join all positional B{C{args}} like C{self.join(B{args})}. 

38 

39 @return: All B{C{args}} joined by this instance (L{Str_}). 

40 

41 @note: An other L{Str_} instance is returned to make the 

42 result re-callable. 

43 ''' 

44 return Str_(str.join(self, map(str, args))) # re-callable 

45 

46 __call__ = join_ 

47 

48NN = Str_('') # PYCHOK Nomen Nescio <https://Wiktionary.org/wiki/N.N.> 

49 

50 

51class _Prefix(Str_): 

52 '''(INTERNAL) Extended C{str} for prefix. 

53 ''' 

54 def __call__(self, *args): 

55 '''Join C{self} plus all B{C{args}} like C{" ".join((self,) + B{args})}. 

56 ''' 

57 return _SPACE_.join_(self, *args) # re-callable 

58 

59 

60class _PyPy__(str): # overwritten by singleton below 

61 '''(INTERNAL) Extended C{str} for C{"PyPy"} and version. 

62 ''' 

63 def __call__(self, version=NN): 

64 '''Return C{"PyPy <version>"} or C{NN}. 

65 ''' 

66 v = version or _sys.version 

67 if _PyPy__ in v: 

68 v = v.split(_PyPy__)[1].split(None, 1)[0] # == _DOT_.join(_sys.pypy_version_info[:3]) 

69 return NN(_PyPy__, v) 

70 else: 

71 return NN 

72 

73 

74class _Python_(str): # overwritten by singleton below 

75 '''(INTERNAL) Extended C{str} for C{"Python"} and version. 

76 ''' 

77 def __call__(self, version=NN): 

78 '''Return C{"Python <version>"}. 

79 ''' 

80 v = version or _sys.version 

81 return _SPACE_(self, v.split(None, 1)[0]) 

82 

83 

84class _Range(str): 

85 '''(INTERNAL) Extended C{str} for C{range} strings. 

86 ''' 

87 def __call__(self, lo, hi, lopen=False, ropen=False, 

88 prec=0, sep=_COMMASPACE_): 

89 '''Return the range as C{"(lo, hi)"}, C{"(lo, hi]"}, 

90 C{"[lo, hi)"} or C{"[lo, hi]"}. 

91 ''' 

92 from pygeodesy.streprs import Fmt 

93 r = NN(Fmt.f(lo, prec=prec), sep, 

94 Fmt.f(hi, prec=prec)) 

95 f = (Fmt.PAREN if ropen else Fmt.LOPEN) if lopen else \ 

96 (Fmt.ROPEN if ropen else Fmt.SQUARE) 

97 return f(r) 

98 

99 

100class _Slicer(str): 

101 '''(INTERNAL) String slicer C{.fromX} or C{.tillY}. 

102 ''' 

103 def __getattr__(self, name): # .fromX, .tillY 

104 n = len(name) - 4 

105 if n > 0: 

106 # assert len('till') == len(_from_) == 4 

107 if name.startswith('till'): 

108 i = self.find(name[4:]) 

109 return self if i < 0 else _Slicer(self[:i + n]) 

110 elif name.startswith(_from_): 

111 i = self.find(name[4:]) 

112 return self if i < 0 else _Slicer(self[i:]) 

113 return str.__getattr__(self, name) # PYCHOK no cover 

114 

115 

116class MISSING(object): 

117 '''(INTERNAL) Singleton C{str}. 

118 ''' 

119 def toRepr(self, **unused): 

120 return self.__class__.__name__ 

121 

122 __repr__ = __str__ = toStr = toRepr 

123 

124MISSING = MISSING() # PYCHOK singleton 

125MISSING.__name__ = str(MISSING) 

126 

127# __DUNDER__-style names would get mangled in classes 

128_0_ = '0' # PYCHOK 'zero' 

129_0to9_ = '0123456789' # PYCHOK OK 

130_1_ = '1' # PYCHOK OK 

131_2_ = '2' # PYCHOK OK 

132_3_ = '3' # PYCHOK OK 

133_4_ = '4' # PYCHOK OK 

134_a_ = 'a' # PYCHOK OK 

135_A_ = 'A' # PYCHOK OK 

136_a12_ = 'a12' # PYCHOK OK 

137_area_ = 'area' # PYCHOK OK 

138_Airy1830_ = 'Airy1830' # PYCHOK OK 

139_AiryModified_ = 'AiryModified' # PYCHOK OK 

140_ambiguous_ = 'ambiguous' # PYCHOK OK 

141_AMPERSAND_ = Str_('&') # PYCHOK OK 

142_an_ = 'an' # PYCHOK OK 

143_and_ = 'and' # PYCHOK OK 

144# _AND_ = _AMPERSAND_ # PYCHOK OK 

145_angle_ = 'angle' # PYCHOK OK 

146_antipodal_ = 'antipodal' # PYCHOK OK 

147_areaOf_ = 'areaOf' # PYCHOK OK 

148_arg_ = 'arg' # PYCHOK OK 

149_at_ = 'at' # PYCHOK OK 

150_AT_ = Str_('@') # PYCHOK OK 

151_AtoZnoIO_ = _Slicer('ABCDEFGHJKLMNPQRSTUVWXYZ') # PYCHOK in .gars, .mgrs and .wgrs 

152_attribute_ = 'attribute' # PYCHOK OK 

153_azi1_ = 'azi1' # PYCHOK OK 

154_azi12_ = 'azi12' # PYCHOK OK 

155_azi2_ = 'azi2' # PYCHOK OK 

156_azimuth_ = 'azimuth' # PYCHOK OK 

157_b_ = 'b' # PYCHOK OK 

158_B_ = 'B' # PYCHOK OK 

159_BACKSLASH_ = Str_('\\') # PYCHOK OK 

160_band_ = 'band' # PYCHOK OK 

161_BANG_ = Str_('!') # PYCHOK OK 

162_BAR_ = Str_('|') # PYCHOK OK 

163_bearing_ = 'bearing' # PYCHOK OK 

164_Bessel1841_ = 'Bessel1841' # PYCHOK OK 

165_beta_ = 'beta' # PYCHOK OK 

166_by_ = 'by' # PYCHOK OK 

167_c_ = 'c' # PYCHOK OK 

168_C_ = 'C' # PYCHOK OK 

169_cartesian_ = 'cartesian' # PYCHOK OK 

170_center_ = 'center' # PYCHOK OK 

171# _CIRCUMFLEX_ = Str_('^') # PYCHOK OK 

172_Clarke1866_ = 'Clarke1866' # PYCHOK OK 

173_Clarke1880IGN_ = 'Clarke1880IGN' # PYCHOK OK 

174_clip_ = 'clip' # PYCHOK OK 

175_clipid_ = 'clipid' # PYCHOK OK 

176_coincident_ = 'coincident' # PYCHOK OK 

177_colinear_ = 'colinear' # PYCHOK OK 

178_COLON_ = Str_(':') # PYCHOK OK 

179_COLONSPACE_ = Str_(': ') # PYCHOK OK 

180_COMMA_ = Str_(',') # PYCHOK OK 

181_COMMASPACE_ = Str_(_COMMASPACE_) # PYCHOK OK 

182_composite_ = 'composite' # PYCHOK OK 

183_concentric_ = 'concentric' # PYCHOK OK 

184_convergence_ = _Prefix('convergence') # PYCHOK OK 

185_conversion_ = 'conversion' # PYCHOK OK 

186_convex_ = 'convex' # PYCHOK OK 

187_cubic_ = 'cubic' # PYCHOK OK 

188_d_ = 'd' # PYCHOK OK 

189_D_ = 'D' # PYCHOK OK 

190_DASH_ = Str_('-') # PYCHOK == _MINUS_ 

191_datum_ = 'datum' # PYCHOK OK 

192_decode3_ = 'decode3' # PYCHOK OK 

193_deg_ = 'deg' # PYCHOK OK 

194_degrees_ = 'degrees' # PYCHOK OK 

195_degrees2_ = 'degrees2' # PYCHOK SQUARED 

196_delta_ = 'delta' # PYCHOK OK 

197_DEPRECATED_ = 'DEPRECATED' # PYCHOK OK 

198_DEQUALSPACED_ = Str_(' == ') # PYCHOK OK 

199_distance_ = 'distance' # PYCHOK OK 

200_distant_ = _Prefix('distant') # PYCHOK OK 

201_doesn_t_exist_ = "doesn't exist" # PYCHOK OK 

202_DOT_ = Str_('.') # PYCHOK OK 

203_down_ = 'down' # PYCHOK OK 

204_e_ = 'e' # PYCHOK OK 

205_E_ = 'E' # PYCHOK OK 

206_earth_ = 'earth' # PYCHOK OK 

207_east_ = 'east' # PYCHOK OK 

208_easting_ = 'easting' # PYCHOK OK 

209_ecef_ = 'ecef' # PYCHOK OK 

210_edge_ = 'edge' # PYCHOK OK 

211_elevation_ = 'elevation' # PYCHOK OK 

212_ELLIPSIS_ = Str_('...') # PYCHOK OK 

213_ELLIPSIS4_ = Str_('....') # PYCHOK OK 

214# _ELLIPSISPACED_ = Str_(' ... ') # PYCHOK <https://www.ThePunctuationGuide.com/ellipses.html> 

215_ellipsoid_ = 'ellipsoid' # PYCHOK OK 

216_ellipsoidal_ = 'ellipsoidal' # PYCHOK OK 

217_enabled_ = 'enabled' # PYCHOK OK 

218_encode_ = 'encode' # PYCHOK OK 

219_end_ = 'end' # PYCHOK OK 

220_epoch_ = 'epoch' # PYCHOK OK 

221_eps_ = 'eps' # PYCHOK OK 

222_EQUAL_ = Str_('=') # PYCHOK OK 

223_EQUALSPACED_ = Str_(' = ') # PYCHOK OK 

224_Error_ = 'Error' # PYCHOK OK 

225_exceed_PI_radians_ = 'exceed PI radians' # PYCHOK OK 

226_exceeds_ = _Prefix('exceeds') # PYCHOK OK 

227# _EXCLAMATION_ = _BANG_ # PYCHOK OK 

228_exists_ = 'exists' # PYCHOK OK 

229_f_ = 'f' # PYCHOK OK 

230_F_ = 'F' # PYCHOK OK 

231_feet_ = 'feet' # PYCHOK OK 

232_few_ = 'few' # PYCHOK OK 

233_fi_ = 'fi' # PYCHOK OK 

234_finite_ = 'finite' # PYCHOK OK 

235_from_ = 'from' # PYCHOK OK 

236_g_ = 'g' # PYCHOK OK 

237_gamma_ = 'gamma' # PYCHOK OK 

238_GRS80_ = 'GRS80' # PYCHOK OK 

239_h_ = 'h' # PYCHOK OK 

240_H_ = 'H' # PYCHOK OK 

241_HASH_ = '#' # PYCHOK OK 

242_height_ = 'height' # PYCHOK OK 

243_hemipole_ = 'hemipole' # PYCHOK OK 

244_i_ = 'i' # PYCHOK OK 

245_iadd_op_ = '+=' # PYCHOK OK 

246_immutable_ = 'immutable' # PYCHOK OK 

247_in_ = 'in' # PYCHOK OK 

248_incompatible_ = 'incompatible' # PYCHOK OK 

249_INF_ = 'INF' # PYCHOK OK 

250_infinite_ = 'infinite' # PYCHOK _not_finite_ 

251_initial_ = 'initial' # PYCHOK OK 

252_inside_ = 'inside' # PYCHOK OK 

253_insufficient_ = 'insufficient' # PYCHOK OK 

254_intersection_ = 'intersection' # PYCHOK OK 

255_Intl1924_ = 'Intl1924' # PYCHOK OK 

256_invalid_ = 'invalid' # PYCHOK OK 

257_invokation_ = 'invokation' # PYCHOK OK 

258_isclockwise_ = 'isclockwise' # PYCHOK OK 

259_ispolar_ = 'ispolar' # PYCHOK OK 

260_j_ = 'j' # PYCHOK OK 

261_k0_ = 'k0' # PYCHOK OK 

262_kind_ = 'kind' # PYCHOK OK 

263_knots_ = 'knots' # PYCHOK OK 

264_Krassovski1940_ = 'Krassovski1940' # PYCHOK OK 

265_Krassowsky1940_ = 'Krassowsky1940' # PYCHOK OK 

266_LANGLE_ = '<' # PYCHOK OK 

267_lam_ = 'lam' # PYCHOK OK 

268_lat_ = 'lat' # PYCHOK OK 

269_lat0_ = 'lat0' # PYCHOK OK 

270_lat1_ = 'lat1' # PYCHOK OK 

271_lat2_ = 'lat2' # PYCHOK OK 

272_latlon_ = 'latlon' # PYCHOK OK 

273_LatLon_ = 'LatLon' # PYCHOK OK 

274_LCURLY_ = '{' # PYCHOK LBRACE 

275_len_ = 'len' # PYCHOK OK 

276_limit_ = 'limit' # PYCHOK OK 

277_line_ = 'line' # PYCHOK OK 

278_linear_ = 'linear' # PYCHOK OK 

279_LPAREN_ = '(' # PYCHOK OK 

280_lon_ = 'lon' # PYCHOK OK 

281_lon0_ = 'lon0' # PYCHOK OK 

282_lon1_ = 'lon1' # PYCHOK OK 

283_lon2_ = 'lon2' # PYCHOK OK 

284_low_ = 'low' # PYCHOK OK 

285_LSQUARE_ = '[' # PYCHOK LBRACK 

286_ltp_ = 'ltp' # PYCHOK OK 

287_m_ = 'm' # PYCHOK OK 

288_M_ = 'M' # PYCHOK OK 

289_m12_ = 'm12' # PYCHOK OK 

290_M12_ = 'M12' # PYCHOK OK 

291_M21_ = 'M21' # PYCHOK OK 

292_MANT_DIG_ = 'MANT_DIG' # PYCHOK OK 

293_MAX_ = 'MAX' # PYCHOK OK 

294_mean_ = 'mean' # PYCHOK OK 

295_meanOf_ = 'meanOf' # PYCHOK OK 

296_meridional_ = 'meridional' # PYCHOK OK 

297_meter_ = 'meter' # PYCHOK OK 

298_meter2_ = 'meter2' # PYCHOK SQUARED 

299_MGRS_ = 'MGRS' # PYCHOK OK 

300_MIN_ = 'MIN' # PYCHOK OK 

301_MINUS_ = _DASH_ # PYCHOK OK 

302_module_ = 'module' # PYCHOK OK 

303_n_ = 'n' # PYCHOK OK 

304_N_ = 'N' # PYCHOK OK 

305_n_a_ = 'n/a' # PYCHOK OK 

306_N_A_ = 'N/A' # PYCHOK OK 

307_NAD27_ = 'NAD27' # PYCHOK OK 

308_NAD83_ = 'NAD83' # PYCHOK OK 

309_name_ = 'name' # PYCHOK OK 

310_NAN_ = 'NAN' # PYCHOK OK 

311_near_ = _Dash('near') # PYCHOK OK 

312_nearestOn2_ = 'nearestOn2' # PYCHOK OK 

313_negative_ = 'negative' # PYCHOK OK 

314_NL_ = Str_('\n') # PYCHOK OK 

315_NLATvar_ = Str_(_NL_ + '@var ') # PYCHOK OK 

316_NLHASH_ = Str_(_NL_ + '# ') # PYCHOK OK 

317# _NLNL_ = _DNL_ # PYCHOK OK 

318_NN_ = 'NN' # PYCHOK OK 

319_no_ = _Prefix('no') # PYCHOK OK 

320_north_ = 'north' # PYCHOK OK 

321_northing_ = 'northing' # PYCHOK OK 

322_NorthPole_ = 'NorthPole' # PYCHOK OK 

323_not_ = _Prefix('not') # PYCHOK OK 

324_NOTEQUAL_ = _BANG_ + _EQUAL_ # PYCHOK OK 

325_not_finite_ = 'not finite' # PYCHOK _not_(_finite_), _infinite_ 

326_not_scalar_ = 'not scalar' # PYCHOK _not_(_scalar_) 

327_NTF_ = 'NTF' # PYCHOK OK 

328_null_ = 'null' # PYCHOK OK 

329_number_ = 'number' # PYCHOK OK 

330_numpy_ = 'numpy' # PYCHOK OK 

331_Nv00_ = 'Nv00' # PYCHOK OK 

332_of_ = 'of' # PYCHOK OK 

333_on_ = 'on' # PYCHOK OK 

334_opposite_ = 'opposite' # PYCHOK OK 

335_or_ = 'or' # PYCHOK OK 

336_other_ = 'other' # PYCHOK OK 

337_outside_ = 'outside' # PYCHOK OK 

338_overlap_ = 'overlap' # PYCHOK OK 

339_parallel_ = 'parallel' # PYCHOK OK 

340_PERCENT_ = '%' # PYCHOK OK 

341_PERCENTDOTSTAR_ = '%.*' # PYCHOK _DOT_(_PERCENT_, _STAR_) 

342_phi_ = 'phi' # PYCHOK OK 

343_PLUS_ = Str_('+') # PYCHOK OK 

344_PLUSMINUS_ = _PLUS_ + _MINUS_ # PYCHOK OK 

345_point_ = 'point' # PYCHOK OK 

346_points_ = 'points' # PYCHOK OK 

347_pole_ = 'pole' # PYCHOK OK 

348_precision_ = 'precision' # PYCHOK OK 

349_prime_vertical_ = 'prime_vertical' # PYCHOK OK 

350_pygeodesy_ = 'pygeodesy' # PYCHOK OK 

351_pygeodesy_abspath_ = 'pygeodesy_abspath' # PYCHOK OK 

352_PyPy__ = _PyPy__('PyPy ') # PYCHOK + _SPACE_ 

353_Python_ = _Python_('Python') # PYCHOK singleton 

354_python_ = 'python' # PYCHOK OK 

355_QUOTE1_ = "'" # PYCHOK OK 

356_QUOTE2_ = '"' # PYCHOK OK 

357# _QUOTE3_ = "'''" # PYCHOK OK 

358# _QUOTE6_ = '"""' # PYCHOK OK 

359_R_ = 'R' # PYCHOK OK 

360_radians_ = 'radians' # PYCHOK OK 

361_radians2_ = 'radians2' # PYCHOK SQUARED 

362_radius_ = 'radius' # PYCHOK OK 

363_radius1_ = 'radius1' # PYCHOK OK 

364_radius2_ = 'radius2' # PYCHOK OK 

365_range_ = _Range('range') # PYCHOK OK 

366_RANGLE_ = '>' # PYCHOK OK 

367_RCURLY_ = '}' # PYCHOK RBRACE 

368_reciprocal_ = 'reciprocal' # PYCHOK OK 

369_reframe_ = 'reframe' # PYCHOK OK 

370_resolution_ = 'resolution' # PYCHOK OK 

371_rIn_ = 'rIn' # PYCHOK OK 

372_RPAREN_ = ')' # PYCHOK OK 

373_RSQUARE_ = ']' # PYCHOK RBRACK 

374_s_ = 's' # PYCHOK OK 

375_S_ = 'S' # PYCHOK OK 

376_s12_ = 's12' # PYCHOK OK 

377_S12_ = 'S12' # PYCHOK OK 

378_scalar_ = 'scalar' # PYCHOK OK 

379_scale_ = 'scale' # PYCHOK OK 

380_scale0_ = 'scale0' # PYCHOK OK 

381_scipy_ = 'scipy' # PYCHOK OK 

382_semi_circular_ = 'semi-circular' # PYCHOK OK 

383_sep_ = 'sep' # PYCHOK OK 

384_singular_ = 'singular' # PYCHOK OK 

385_SLASH_ = Str_('/') # PYCHOK OK 

386_small_ = 'small' # PYCHOK OK 

387_Sphere_ = 'Sphere' # PYCHOK OK 

388_spherical_ = 'spherical' # PYCHOK OK 

389_SouthPole_ = 'SouthPole' # PYCHOK OK 

390_SPACE_ = Str_(' ') # PYCHOK OK 

391_specified_ = 'specified' # PYCHOK OK 

392_STAR_ = Str_('*') # PYCHOK OK 

393_start_ = 'start' # PYCHOK OK 

394_std_ = 'std' # PYCHOK OK 

395_stdev_ = 'stdev' # PYCHOK OK 

396_supported_ = 'supported' # PYCHOK OK 

397_sx_ = 'sx' # PYCHOK OK 

398_sy_ = 'sy' # PYCHOK OK 

399_sz_ = 'sz' # PYCHOK OK 

400_tbd_ = 'tbd' # PYCHOK OK 

401_TILDE_ = '~' # PYCHOK OK 

402_to_ = 'to' # PYCHOK OK 

403_tolerance_ = _Prefix('tolerance') # PYCHOK OK 

404_too_ = _Prefix('too') # PYCHOK OK 

405_transform_ = 'transform' # PYCHOK OK 

406_tx_ = 'tx' # PYCHOK OK 

407_ty_ = 'ty' # PYCHOK OK 

408_tz_ = 'tz' # PYCHOK OK 

409_UNDER_ = Str_('_') # PYCHOK OK 

410_units_ = 'units' # PYCHOK OK 

411_UNUSED_ = 'UNUSED' # PYCHOK OK 

412_up_ = 'up' # PYCHOK OK 

413_UPS_ = 'UPS' # PYCHOK OK 

414_utf_8_ = 'utf-8' # PYCHOK OK 

415_UTM_ = 'UTM' # PYCHOK OK 

416_V_ = 'V' # PYCHOK OK 

417_valid_ = 'valid' # PYCHOK OK 

418_value_ = 'value' # PYCHOK OK 

419_version_ = 'version' # PYCHOK OK 

420_vs_ = 'vs' # PYCHOK OK 

421_W_ = 'W' # PYCHOK OK 

422_WGS72_ = 'WGS72' # PYCHOK OK 

423_WGS84_ = 'WGS84' # PYCHOK OK 

424_width_ = 'width' # PYCHOK OK 

425_with_ = 'with' # PYCHOK OK 

426_x_ = 'x' # PYCHOK OK 

427_X_ = 'X' # PYCHOK OK 

428_xyz_ = 'xyz' # PYCHOK OK 

429_y_ = 'y' # PYCHOK OK 

430_Y_ = 'Y' # PYCHOK OK 

431_z_ = 'z' # PYCHOK OK 

432_Z_ = 'Z' # PYCHOK OK 

433_zone_ = 'zone' # PYCHOK OK 

434 

435_EW_ = _E_ + _W_ # PYCHOK common cardinals 

436_NE_ = _N_ + _E_ # PYCHOK positive ones 

437_NS_ = _N_ + _S_ # PYCHOK OK 

438_NSEW_ = _NS_ + _EW_ # PYCHOK OK 

439_NW_ = _N_ + _W_ # PYCHOK OK 

440_SE_ = _S_ + _E_ # PYCHOK OK 

441_SW_ = _S_ + _W_ # PYCHOK negative ones 

442# _NESW_ = _NE_ + _SW_ # PYCHOK clockwise 

443 

444_DDOT_ = Str_(_DOT_ * 2) # PYCHOK OK 

445# _DEQUAL_ = Str_(_EQUAL_ * 2) # PYCHOK OK 

446_DNL_ = Str_(_NL_ * 2) # PYCHOK OK 

447# _DSLASH_ = Str_(_SLASH_ * 2) # PYCHOK OK 

448# _DSTAR_ = Str_(_STAR_ * 2) # PYCHOK OK 

449_DUNDER_ = Str_(_UNDER_ * 2) # PYCHOK OK 

450 

451_LR_PAIRS = {_LANGLE_: _RANGLE_, 

452 _LCURLY_: _RCURLY_, 

453 _LPAREN_: _RPAREN_, 

454 _LSQUARE_: _RSQUARE_} # PYCHOK OK 

455 

456 

457def _dunder_nameof(inst, *dflt): 

458 '''(INTERNAL) Get the double_underscore __name__ attr. 

459 ''' 

460 try: 

461 return inst.__name__ 

462 except AttributeError: 

463 pass 

464 return dflt[0] if dflt else inst.__class__.__name__ 

465 

466 

467def _enquote(strs, quote=_QUOTE2_): # in .basics, .solveBase 

468 '''(INTERNAL) Enquote a string containing whitespace. 

469 ''' 

470 if len(strs.split()) > 1: 

471 strs = NN(quote, strs, quote) 

472 return strs 

473 

474 

475def _is(a, b): # PYCHOK no cover 

476 '''(INTERNAL) C{a is b}? in C{PyPy} 

477 ''' 

478 return (a == b) if _isPyPy() else (a is b) 

479 

480 

481def _isPyPy(): 

482 '''(INTERNAL) Is this C{PyPy}? 

483 ''' 

484 # platform.python_implementation() == 'PyPy' 

485 return _pythonarchine()[0].startswith(_PyPy__) 

486 

487 

488def _load_lib(name): 

489 '''(INTERNAL) Load a C{dylib}, B{C{name}} must startwith('lib'). 

490 ''' 

491 # macOS 11+ (aka 10.16) no longer provides direct loading of 

492 # system libraries. As a result, C{ctypes.util.find_library} 

493 # will not find any library, unless previously installed by a 

494 # low-level dlopen(name) call (with the library base C{name}). 

495 from ctypes import CDLL 

496 from ctypes.util import find_library 

497 

498 ns = find_library(name), name 

499 if _sys.platform[:6] == 'darwin': # and os.name == 'posix' 

500 from ctypes import _dlopen, DEFAULT_MODE 

501 from os.path import join 

502 ns += (_DOT_(name, 'dylib'), 

503 _DOT_(name, 'framework'), join( 

504 _DOT_(name, 'framework'), name)) 

505 else: # non-macOS 

506 DEFAULT_MODE = 0 

507 

508 def _dlopen(*unused): 

509 return True 

510 

511 for n in ns: 

512 try: 

513 if n and _dlopen(n, DEFAULT_MODE): # pre-load handle 

514 lib = CDLL(n) # == ctypes.cdll.LoadLibrary(n) 

515 if lib._name: # has a qualified name 

516 return lib 

517 except (AttributeError, OSError): 

518 pass 

519 

520 return None # raise OSError 

521 

522 

523def machine(): 

524 '''Return standard C{platform.machine}, but distinguishing Intel I{native} 

525 from Intel I{emulation} on Apple Silicon (on macOS only). 

526 

527 @return: Machine C{'arm64'} for Apple Silicon I{native}, C{'x86_64'} 

528 for Intel I{native}, C{"arm64_x86_64"} for Intel I{emulation}, 

529 etc. (C{str} with C{comma}s replaced by C{underscore}s). 

530 ''' 

531 return _platform2()[1] 

532 

533 

534def _platform2(sep=NN): 

535 '''(INTERNAL) Get platform architecture and machine as C{2-list} or C{str}. 

536 ''' 

537 L = _pf2List 

538 if not L: 

539 import platform 

540 m = platform.machine() # ARM64, arm64, x86_64, iPhone13,2, etc. 

541 m = m.replace(_COMMA_, _UNDER_) 

542 if m.lower() == 'x86_64': # on Intel or Rosetta2 ... 

543 v = platform.mac_ver() # ... and only on macOS ... 

544 if v and _version2(v[0]) > (10, 15): # ... 11+ aka 10.16 

545 # <https://Developer.Apple.com/forums/thread/659846> 

546 if _sysctl_uint('sysctl.proc_translated') == 1: # and \ 

547# _sysctl_uint('hw.optional.arm64') == 1: # PYCHOK indent 

548 m = _UNDER_('arm64', m) # Apple Si emulating Intel x86-64 

549 L[:] = [platform.architecture()[0], # bits 

550 m] # arm64, arm64_x86_64, x86_64, etc. 

551 return sep.join(L) if sep else L # 2-list() 

552 

553 

554def _pythonarchine(sep=NN): # in test/bases.py versions 

555 '''(INTERNAL) Get PyPy and Python versions and C{_platform2} as C{3- or 4-list} or C{str}. 

556 ''' 

557 L = _Py3List 

558 if not L: 

559 v = _sys.version 

560 L[:] = [_Python_(v)] + _platform2() 

561 pypy = _PyPy__(v) 

562 if pypy: 

563 L.insert(0, pypy) 

564 return sep.join(L) if sep else L # 3- or 4-list 

565 

566 

567def _sysctl_uint(name): 

568 '''(INTERNAL) Get an unsigned int sysctl item by name, use on macOS ONLY! 

569 ''' 

570 libc = _load_lib('libc') 

571 if libc: # <https://StackOverflow.com/questions/759892/python-ctypes-and-sysctl> 

572 from ctypes import byref, c_char_p, c_size_t, c_uint, sizeof # get_errno 

573 n = name if str is bytes else bytes(name, _utf_8_) # PYCHOK isPython2 = str is bytes 

574 u = c_uint(0) 

575 z = c_size_t(sizeof(u)) 

576 r = libc.sysctlbyname(c_char_p(n), byref(u), byref(z), None, c_size_t(0)) 

577 else: # could find or load 'libc' 

578 r = -2 

579 return int(r if r else u.value) # -1 ENOENT error, -2 no libc 

580 

581 

582def _under(name): # PYCHOK in .datums, .auxilats, .ups, .utm, .utmupsBase, ... 

583 '''(INTERNAL) Prefix C{name} with I{underscore}. 

584 ''' 

585 return name if name.startswith(_UNDER_) else NN(_UNDER_, name) 

586 

587 

588def _usage(file_py, *args): # in .etm 

589 '''(INTERNAL) Build "usage: python -m ..." cmd line for module B{C{file_py}}. 

590 ''' 

591 import os 

592 m = os.path.dirname(file_py).replace(os.getcwd(), _ELLIPSIS_) \ 

593 .replace(os.sep, _DOT_).strip() 

594 b, x = os.path.splitext(os.path.basename(file_py)) 

595 if x == '.py' and b != '__main__': 

596 m = _DOT_(m or _pygeodesy_, b) 

597 p = NN(_python_, _sys.version_info[0]) 

598 return NN('usage', _SPACE_(_COLON_, p, '-m', _enquote(m), *args)) 

599 

600 

601def _version2(version, n=2): 

602 '''(INTERNAL) Split C{B{version} str} into a C{1-, 2- or 3-tuple} of C{int}s. 

603 ''' 

604 def _ints(vs): 

605 for v in vs: 

606 if v: 

607 try: 

608 yield int(v.strip()) 

609 except (TypeError, ValueError): 

610 pass 

611 

612 t = tuple(_ints(version.split(_DOT_, 2))) 

613 if len(t) < n: 

614 t += (0,) * n 

615 return tuple(t[:n]) 

616 

617 

618__all__ = (_NN_, # not MISSING! 

619 Str_.__name__, # classes 

620 machine.__name__) # in .lazily 

621__version__ = '23.09.13' 

622 

623if __name__ == '__main__': 

624 

625 from pygeodesy import itemsorted, printf 

626 

627 t = b = 0 

628 for n, v in itemsorted(locals(), asorted=False, reverse=True): 

629 if n.endswith(_UNDER_) and n.startswith(_UNDER_) and \ 

630 not n.startswith(_DUNDER_): 

631 t += 1 

632 b += len(v) 

633 m = n[1:-1] 

634 if m != v and m.replace(_UNDER_, _SPACE_) != v: 

635 printf('%4d: %s = %r', t, n, v) 

636 n = len(locals()) 

637 printf('%4d (%d) names, %s chars total, %.2f chars avg', t, n, b, float(b) / t, nl=1) 

638 

639# **) MIT License 

640# 

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

642# 

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

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

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

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

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

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

649# 

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

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

652# 

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

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

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

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

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

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

659# OTHER DEALINGS IN THE SOFTWARE.