Binary value content.
199573
def value(self):
        # type: () -> bytes
        """"""
        v = self.file
        return v.open("rb").read() if v is not None else v
463052
def from_bin(cls, value):
        """"""
        value = value.lstrip('b')
        if len(value) == 32:
            return cls(int(value, 2))
        elif len(value) == 128:
            return cls(int(value, 2))
        else:
            return ValueError('%r: invalid binary notation' % (value,))
276968
def binary_value_or_stdin(value):
    
    if value is None:
        reader = io.open(sys.stdin.fileno(), mode='rb', closefd=False)
        return reader.read()
    elif six.PY3:
        return os.fsencode(value)
    else:
        return value
626631
def _readuintle(self, length, start):
        """"""
        if length % 8:
            raise InterpretError("Little-endian integers must be whole-byte. "
                                 "Length = {0} bits.", length)
        assert start + length <= self.len
        absolute_pos = start + self._offset
        startbyte, offset = divmod(absolute_pos, 8)
        val = 0
        if not offset:
            endbyte = (absolute_pos + length - 1) // 8
            chunksize = 4 # for 'L' format
            while endbyte - chunksize + 1 >= startbyte:
                val <<= 8 * chunksize
                val += struct.unpack('<L', bytes(self._datastore.getbyteslice(endbyte + 1 - chunksize, endbyte + 1)))[0]
                endbyte -= chunksize
            for b in xrange(endbyte, startbyte - 1, -1):
                val <<= 8
                val += self._datastore.getbyte(b)
        else:
            data = self._slice(start, start + length)
            assert data.len % 8 == 0
            data._reversebytes(0, self.len)
            for b in bytearray(data.bytes):
                val <<= 8
                val += b
        return val
648092
def to_binary_string(self):
        """"""
        timestamp = datetime_to_timestamp(self.when)
        token = binascii.unhexlify(self.token)
        return struct.pack(self.FORMAT_PREFIX + '{0}s'.format(len(token)),
                           timestamp, len(token), token)
809430
def byte_to_bitstring(byte):
    """"""
    assert 0 <= byte <= 0xff
    bits = [int(x) for x in list(bin(byte + 0x100)[3:])]
    return bits
859455
def wrap_content_as_binary_if_needed(func_, *args, **kwargs):
    
    assert isinstance(args[0], dict)
    try:
        args[0][CONTENT_FIELD] = BINARY(args[0].get(CONTENT_FIELD, b""))
    except (r.errors.ReqlDriverCompileError, AttributeError):  # pragma: no cover
        pass  # toss in the object as string
    return func_(*args, **kwargs)
1054600
def _norm(self, value):
        """"""
        self._bit_value = value * self._unit_value
        self._byte_value = self._bit_value / 8.0
669042
def to_binary(decimal, length):
        
        b = bitstring.Bits(int=decimal, length=length)
        return b.bin
448049
def fp(x):
    

    def bin32(f):
        """ Returns ASCII representation for a 32 bit integer value
        """
        result = ''
        a = int(f) & 0xFFFFFFFF  # ensures int 32

        for i in range(32):
            result = str(a % 2) + result
            a = a >> 1

        return result

    def bindec32(f):
        """ Returns binary representation of a mantissa x (x is float)
        """
        result = '0'
        a = f

        if f >= 1:
            result = bin32(f)

        result += '.'
        c = int(a)

        for i in range(32):
            a -= c
            a *= 2
            c = int(a)
            result += str(c)

        return result

    e = 0  # exponent
    s = 1 if x < 0 else 0  # sign
    m = abs(x)  # mantissa

    while m >= 1:
        m /= 2.0
        e += 1

    while 0 < m < 0.5:
        m *= 2.0
        e -= 1

    M = bindec32(m)[3:]
    M = str(s) + M
    E = bin32(e + 128)[-8:] if x != 0 else bin32(0)[-8:]

    return M, E
829283
def encode(binary):
    """"""
    encoded = io.BytesIO()
    gzip_file = dict(mode='wb', fileobj=encoded, compresslevel=LEVEL)
    with gzip.GzipFile(**gzip_file) as file_:
        file_.write(binary)
    encoded.seek(0)
    return encoded.read()
381484
def bytes(self):
        """"""
        addrbyte = b'\x00\x00\x00'
        if self.addr is not None:
            addrbyte = self.addr
        return addrbyte
714518
def encode(self, value):
        '''
        
        '''
        kassert.is_of_types(value, Bits)
        remainder = len(value) % 8
        if remainder:
            value += Bits(bin='0' * (8 - remainder))
        return value
860563
def is_binary(filename):
    
    with open(filename, 'rb') as fp:
        data = fp.read(1024)
        if not data:
            return False
        if b'\0' in data:
            return True
        return False
684082
def ReadLsbBytes(rd, offset, value_size):
  """"""

  encoding = None
  if value_size == 1:
    encoding = '<B'
  elif value_size == 2:
    encoding = '<H'
  elif value_size == 4:
    encoding = '<L'
  else:
    raise errors.HidError('Invalid value size specified')

  ret, = struct.unpack(encoding, rd[offset:offset + value_size])
  return ret
417439
def _encode(self, value):
        ""
        if isinstance(value, bytes):
            return value
        elif isinstance(value, (int, long)):
            value = str(value).encode('utf-8')
        elif isinstance(value, float):
            value = repr(value).encode('utf-8')
        elif not isinstance(value, basestring):
            value = str(value).encode('utf-8')
        else:
            value = value.encode('utf-8', 'strict')
        return value
1007638
def _data_is_binary(self, data):
        """"""
        if isinstance(data, six.binary_type):
            return True
        elif isinstance(data, list):
            return functools.reduce(
                lambda a, b: a or b, [self._data_is_binary(item)
                                      for item in data], False)
        elif isinstance(data, dict):
            return functools.reduce(
                lambda a, b: a or b, [self._data_is_binary(item)
                                      for item in six.itervalues(data)],
                False)
        else:
            return False