Returns a possibly valid _ADTSStream or None.

        Args:
            max_bytes (int): maximum bytes to read
176842
def find_stream(cls, fileobj, max_bytes):
        

        r = BitReader(fileobj)
        stream = cls(r)
        if stream.sync(max_bytes):
            stream.offset = (r.get_position() - 12) // 8
            return stream
381484
def bytes(self):
        """"""
        addrbyte = b'\x00\x00\x00'
        if self.addr is not None:
            addrbyte = self.addr
        return addrbyte
289912
def estimate_max_mapq(in_bam, nreads=1e6):
    
    with pysam.Samfile(in_bam, "rb") as work_bam:
        reads = tz.take(int(nreads), work_bam)
        return max([x.mapq for x in reads if not x.is_unmapped])
372525
def from_stream(cls, reader: ReaderAdapter):
        
        @asyncio.coroutine
        def decode_remaining_length():
            """
            Decode message length according to MQTT specifications
            :return:
            """
            multiplier = 1
            value = 0
            buffer = bytearray()
            while True:
                encoded_byte = yield from reader.read(1)
                int_byte = unpack('!B', encoded_byte)
                buffer.append(int_byte[0])
                value += (int_byte[0] & 0x7f) * multiplier
                if (int_byte[0] & 0x80) == 0:
                    break
                else:
                    multiplier *= 128
                    if multiplier > 128 * 128 * 128:
                        raise MQTTException("Invalid remaining length bytes:%s, packet_type=%d" % (bytes_to_hex_str(buffer), msg_type))
            return value

        try:
            byte1 = yield from read_or_raise(reader, 1)
            int1 = unpack('!B', byte1)
            msg_type = (int1[0] & 0xf0) >> 4
            flags = int1[0] & 0x0f
            remain_length = yield from decode_remaining_length()

            return cls(msg_type, flags, remain_length)
        except NoDataException:
            return None
659833
protected B maxReservedStreams(int maxReservedStreams) {
        enforceConstraint("server", "connection", connection);
        enforceConstraint("server", "codec", decoder);
        enforceConstraint("server", "codec", encoder);

        this.maxReservedStreams = checkPositiveOrZero(maxReservedStreams, "maxReservedStreams");
        return self();
    }
121241
def decode(cls, data, bytes_to_read=None):
        
        if isinstance(data, bytes):
            data = io.BytesIO(data)
        if bytes_to_read is None:
            bytes_to_read = Int32.decode(data)

        # if FetchRequest max_bytes is smaller than the available message set
        # the server returns partial data for the final message
        # So create an internal buffer to avoid over-reading
        raw = io.BytesIO(data.read(bytes_to_read))

        items = []
        while bytes_to_read:
            try:
                offset = Int64.decode(raw)
                msg_bytes = Bytes.decode(raw)
                bytes_to_read -= 8 + 4 + len(msg_bytes)
                items.append((offset, len(msg_bytes), Message.decode(msg_bytes)))
            except ValueError:
                # PartialMessage to signal that max_bytes may be too small
                items.append((None, None, PartialMessage()))
                break
        return items
520558
def read(self, nbytes: int = 0) -> bytes:
        
        if nbytes == 0 or len(self.output) <= nbytes:
            data = bytes(self.output)
            del self.output[:]
            return data
        data = bytes(self.output[:nbytes])
        del self.output[:nbytes]
        return data
830231
def _max(self, memory, addr, **kwargs):
        
        return memory.state.solver.max(addr, exact=kwargs.pop('exact', self._exact), **kwargs)
418264
def read(bytes = @length)
      return nil if @pos >= @length
      bytes = @length - @pos if bytes.nil?
      bytes = @length - @pos if @pos + bytes > @length

      out = @data[@pos, bytes]      if @data.kind_of?(String)
      out = @data.read(bytes)       if @data.kind_of?(NTFS::DataRun)

      @pos += out.size
      out
    end
882616
def sync(self, max_bytes):
        """"""

        # at least 2 bytes for the sync
        max_bytes = max(max_bytes, 2)

        r = self._r
        r.align()
        while max_bytes > 0:
            try:
                b = r.bytes(1)
                if b == b"\xff":
                    if r.bits(4) == 0xf:
                        return True
                    r.align()
                    max_bytes -= 2
                else:
                    max_bytes -= 1
            except BitReaderError:
                return False
        return False
475008
def encode_max_apdu_length_accepted(arg):
    """"""
    for i in range(5, -1, -1):
        if (arg >= _max_apdu_length_encoding[i]):
            return i

    raise ValueError("invalid max APDU length accepted: %r" % (arg,))
17112
private static byte getNextValidDecodeByte(byte[] in, IntWrapper pos, int maxPos) {
		byte base64Byte;
		byte decodeByte;
		while (pos.value <= maxPos) {
			base64Byte = in[pos.value++];
			if (base64Byte > -1) {
				decodeByte = DECODE_TABLE[base64Byte];
				if (decodeByte > -1) {
					return decodeByte;
				}
			}
		}
		// padding if reached max position
		return PADDING;
	}
505133
def peak_memory_mb() -> float:
    
    if resource is None or sys.platform not in ('linux', 'darwin'):
        return 0.0

    # TODO(joelgrus): For whatever, our pinned version 0.521 of mypy does not like
    # next line, but later versions (e.g. 0.530) are fine with it. Once we get that
    # figured out, remove the type: ignore.
    peak = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss  # type: ignore

    if sys.platform == 'darwin':
        # On OSX the result is in bytes.
        return peak / 1_000_000

    else:
        # On Linux the result is in kilobytes.
        return peak / 1_000
209177
def parse_byte_range(byte_range, min_byte=0, max_byte=sys.maxint):
    

    if not byte_range:
        return min_byte, max_byte

    begin = byte_range[0] or min_byte
    end = byte_range[1] or max_byte

    if end < begin:
        raise ValueError("End before begin")

    if begin < min_byte:
        raise ValueError("Begin smaller than min")

    if end > max_byte:
        raise ValueError("End larger than max")

    return begin, end
916873
def read_bytes(self, length) -> bytes:
        
        value = self.stream.read(length)
        return value
1192737
async def read_line(stream: asyncio.StreamReader) -> bytes:
    
    # Security: this is bounded by the StreamReader's limit (default = 32 KiB).
    line = await stream.readline()
    # Security: this guarantees header values are small (hard-coded = 4 KiB)
    if len(line) > MAX_LINE:
        raise ValueError("Line too long")
    # Not mandatory but safe - https://tools.ietf.org/html/rfc7230#section-3.5
    if not line.endswith(b"\r\n"):
        raise ValueError("Line without CRLF")
    return line[:-2]
1228561
def decode(self, bytes):
        

        self.buffer = bytes
        self._pos = 0

        Packet = identifier.get_packet_from_id(self._read_variunt())

        # unknown packets will be None from the identifier
        if Packet is None:
            return None

        packet = Packet()
        packet.ParseFromString(self.remaining_bytes())
        return packet