text
stringlengths
0
828
if isinstance(num, bool):
return if_bool
elif isinstance(num, int):
return True
try:
number = float(num)
return not (isnan(number) or isinf(number))
except (TypeError, ValueError):
return False"
4348,"def _VarintDecoder(mask):
""""""Return an encoder for a basic varint value (does not include tag).
Decoded values will be bitwise-anded with the given mask before being
returned, e.g. to limit them to 32 bits. The returned decoder does not
take the usual ""end"" parameter -- the caller is expected to do bounds checking
after the fact (often the caller can defer such checking until later). The
decoder returns a (value, new_pos) pair.
""""""
def DecodeVarint(buffer, pos):
result = 0
shift = 0
while 1:
if pos > len(buffer) -1:
raise NotEnoughDataException( ""Not enough data to decode varint"" )
b = buffer[pos]
result |= ((b & 0x7f) << shift)
pos += 1
if not (b & 0x80):
result &= mask
return (result, pos)
shift += 7
if shift >= 64:
raise _DecodeError('Too many bytes when decoding varint.')
return DecodeVarint"
4349,"def _SignedVarintDecoder(mask):
""""""Like _VarintDecoder() but decodes signed values.""""""
def DecodeVarint(buffer, pos):
result = 0
shift = 0
while 1:
if pos > len(buffer) -1:
raise NotEnoughDataException( ""Not enough data to decode varint"" )
b = local_ord(buffer[pos])
result |= ((b & 0x7f) << shift)
pos += 1
if not (b & 0x80):
if result > 0x7fffffffffffffff:
result -= (1 << 64)
result |= ~mask
else:
result &= mask
return (result, pos)
shift += 7
if shift >= 64:
raise _DecodeError('Too many bytes when decoding varint.')
return DecodeVarint"
4350,"def varintSize(value):
""""""Compute the size of a varint value.""""""
if value <= 0x7f: return 1
if value <= 0x3fff: return 2
if value <= 0x1fffff: return 3
if value <= 0xfffffff: return 4
if value <= 0x7ffffffff: return 5
if value <= 0x3ffffffffff: return 6
if value <= 0x1ffffffffffff: return 7
if value <= 0xffffffffffffff: return 8
if value <= 0x7fffffffffffffff: return 9
return 10"
4351,"def signedVarintSize(value):
""""""Compute the size of a signed varint value.""""""
if value < 0: return 10
if value <= 0x7f: return 1
if value <= 0x3fff: return 2
if value <= 0x1fffff: return 3
if value <= 0xfffffff: return 4
if value <= 0x7ffffffff: return 5
if value <= 0x3ffffffffff: return 6
if value <= 0x1ffffffffffff: return 7
if value <= 0xffffffffffffff: return 8
if value <= 0x7fffffffffffffff: return 9
return 10"
4352,"def _VarintEncoder():
""""""Return an encoder for a basic varint value.""""""
local_chr = chr
def EncodeVarint(write, value):
bits = value & 0x7f
value >>= 7
while value:
write(0x80|bits)
bits = value & 0x7f
value >>= 7
return write(bits)
return EncodeVarint"