MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _chooseEncBase

Method _chooseEncBase

pager_lib/pyasn1/codec/ber/encoder.py:419–450  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

417 return ms, int(m), encbase, e
418
419 def _chooseEncBase(self, value):
420 m, b, e = value
421 encBase = [2, 8, 16]
422 if value.binEncBase in encBase:
423 return self._dropFloatingPoint(m, value.binEncBase, e)
424
425 elif self.binEncBase in encBase:
426 return self._dropFloatingPoint(m, self.binEncBase, e)
427
428 # auto choosing base 2/8/16
429 mantissa = [m, m, m]
430 exponent = [e, e, e]
431 sign = 1
432 encbase = 2
433 e = float('inf')
434
435 for i in range(3):
436 (sign,
437 mantissa[i],
438 encBase[i],
439 exponent[i]) = self._dropFloatingPoint(mantissa[i], encBase[i], exponent[i])
440
441 if abs(exponent[i]) < abs(e) or (abs(exponent[i]) == abs(e) and mantissa[i] < m):
442 e = exponent[i]
443 m = int(mantissa[i])
444 encbase = encBase[i]
445
446 if LOG:
447 LOG('automatically chosen REAL encoding base %s, sign %s, mantissa %s, '
448 'exponent %s' % (encbase, sign, m, e))
449
450 return sign, m, encbase, e
451
452 def encodeValue(self, value, asn1Spec, encodeFun, **options):
453 if asn1Spec is not None:

Callers 1

encodeValueMethod · 0.95

Calls 2

_dropFloatingPointMethod · 0.95
rangeFunction · 0.85

Tested by

no test coverage detected