Merge the given blocks into a contiguous block of compressed data.

    :param blocks: the list of blocks
    :rtype: a list of compressed bytes
498778
def merge(blocks):
    

    current_block = blocks[sorted(blocks.keys())[0]]

    compressed_data = []
    eof = False

    while not eof:
        data_size_to_append = None
        next_block = None

        i = 0
        while i < len(current_block.data) - 1:
            current_byte = current_block.data[i]
            next_byte = current_block.data[i + 1]

            if current_byte == RLE_BYTE:
                if next_byte == RLE_BYTE:
                    i += 2
                else:
                    i += 3
            elif current_byte == SPECIAL_BYTE:
                if next_byte in SPECIAL_DEFAULTS:
                    i += 3
                elif next_byte == SPECIAL_BYTE:
                    i += 2
                else:
                    data_size_to_append = i

                    # hit end of file
                    if next_byte == EOF_BYTE:
                        eof = True
                    else:
                        next_block = blocks[next_byte]

                    break
            else:
                i += 1

        assert data_size_to_append is not None, "Ran off the end of a "\
            "block without encountering a block switch or EOF"

        compressed_data.extend(current_block.data[0:data_size_to_append])

        if not eof:
            assert next_block is not None, "Switched blocks, but did " \
                "not provide the next block to switch to"

            current_block = next_block

    return compressed_data
1034070
def deflate_write_block(fo, block_bytes):
    """"""
    # The first two characters and last character are zlib
    # wrappers around deflate data.
    data = compress(block_bytes)[2:-1]

    write_long(fo, len(data))
    fo.write(data)
773276
def replace_blocks(self, blocks):
        """"""
        start = 0
        bulk_insert = self.bulk_insert
        blocks_len = len(blocks)
        select = 'SELECT ?,?,?,?,?'
        query = 'REPLACE INTO gauged_data (namespace, offset, `key`, ' \
            'data, flags) '
        execute = self.cursor.execute
        while start < blocks_len:
            rows = blocks[start:start+bulk_insert]
            params = [param for params in rows for param in params]
            insert = (select + ' UNION ') * (len(rows) - 1) + select
            execute(query + insert, params)
            start += bulk_insert
373827
def tokenize_block(iterable, token_types):
    
    lines = FileWrapper(iterable)
    parse_buffer = ParseBuffer()
    line = lines.peek()
    while line is not None:
        for token_type in token_types:
            if token_type.start(line):
                result = token_type.read(lines)
                if result is not None:
                    parse_buffer.append((token_type, result))
                    break
        else:  # unmatched newlines
            next(lines)
            parse_buffer.loose = True
        line = lines.peek()
    return parse_buffer
231826
def save_block(self, data, dest):
        
        write_csv(dest, data, self.sep, self.fmt, 'no-header')
683000
def _finalize_block_blob(self, sd, metadata, digest):
        # type: (SyncCopy, blobxfer.models.synccopy.Descriptor, dict,
        #        str) -> None
        
        blobxfer.operations.azure.blob.block.put_block_list(
            sd.dst_entity, sd.last_block_num, digest, metadata)
        if blobxfer.util.is_not_empty(sd.dst_entity.replica_targets):
            for ase in sd.dst_entity.replica_targets:
                blobxfer.operations.azure.blob.block.put_block_list(
                    ase, sd.last_block_num, digest, metadata)
488426
def gather_blocks_2d(x, indices):
  """"""
  x_shape = common_layers.shape_list(x)
  x = reshape_range(x, 2, 4, [tf.reduce_prod(x_shape[2:4])])
  # [length, batch, heads, dim]
  x_t = tf.transpose(x, [2, 0, 1, 3])
  x_new = tf.gather(x_t, indices)
  # returns [batch, heads, num_blocks, block_length ** 2, dim]
  return tf.transpose(x_new, [2, 3, 0, 1, 4])
1101444
private void updateBlocks() {
        for (Block<S, L> block : splitBlocks) {
            // Ignore blocks that have no elements in their sub blocks.
            int inSubBlocks = block.getElementsInSubBlocks();
            if (inSubBlocks == 0) {
                continue;
            }

            boolean blockRemains = (inSubBlocks < block.size());

            boolean reuseBlock = !blockRemains;

            List<UnorderedCollection<State<S, L>>> subBlocks = block.getSubBlocks();
            // If there is only one sub block which contains all elements of
            // the block, then no split needs to be performed.
            if (!blockRemains && subBlocks.size() == 1) {
                block.clearSubBlocks();
                continue;
            }

            Iterator<UnorderedCollection<State<S, L>>> subBlockIt = subBlocks.iterator();

            if (reuseBlock) {
                UnorderedCollection<State<S, L>> first = subBlockIt.next();
                block.getStates().swap(first);
                updateBlockReferences(block);
            }

            while (subBlockIt.hasNext()) {
                UnorderedCollection<State<S, L>> subBlockStates = subBlockIt.next();

                if (blockRemains) {
                    for (State<S, L> state : subBlockStates) {
                        block.removeState(state.getBlockReference());
                    }
                }

                Block<S, L> subBlock = new Block<>(numBlocks++, subBlockStates);
                updateBlockReferences(subBlock);
                newBlocks.add(subBlock);
                addToPartition(subBlock);
            }

            newBlocks.add(block);
            block.clearSubBlocks();

            // If the split block previously was in the queue, add all newly
            // created blocks to the queue. Otherwise, it's enough to add
            // all but the largest
            if (removeFromSplitterQueue(block)) {
                addAllToSplitterQueue(newBlocks);
            } else {
                addAllButLargest(newBlocks);
            }
            newBlocks.clear();
        }

        splitBlocks.clear();
    }
759321
def map_blocks(data, f, blen=None, storage=None, create='array', **kwargs):
    """"""

    # setup
    storage = _util.get_storage(storage)
    if isinstance(data, tuple):
        blen = max(_util.get_blen_array(d, blen) for d in data)
    else:
        blen = _util.get_blen_array(data, blen)
    if isinstance(data, tuple):
        _util.check_equal_length(*data)
        length = len(data[0])
    else:
        length = len(data)

    # block-wise iteration
    out = None
    for i in range(0, length, blen):
        j = min(i+blen, length)

        # obtain blocks
        if isinstance(data, tuple):
            blocks = [d[i:j] for d in data]
        else:
            blocks = [data[i:j]]

        # map
        res = f(*blocks)

        # store
        if out is None:
            out = getattr(storage, create)(res, expectedlen=length, **kwargs)
        else:
            out.append(res)

    return out
59645
def join(self, *data: Iterable[MaybeBytes]) -> bytes:
        
        return self.how.join([bytes(item) for item in chain(*data)])
90642
def flatten_blocks(lines, num_indents=-1):
    
    # The standard indent is four spaces
    INDENTATION = " " * 4

    if not lines:
        return ""

    # If this is a string, add the indentation and finish here
    if isinstance(lines, six.string_types):
        return INDENTATION * num_indents + lines

    # If this is not a string, join the lines and recurse
    return "\n".join([flatten_blocks(line, num_indents + 1) for line in lines])
1221882
def blocks2numList(blocks, n):
    """"""
    toProcess = copy.copy(blocks)
    returnList = []
    for numBlock in toProcess:
        inner = []
        for i in range(0, n):
            inner.append(numBlock % 256)
            numBlock >>= 8
        inner.reverse()
        returnList.extend(inner)
    return returnList
14212
def _protect_consolidate(self, f):
        
        blocks_before = len(self._data.blocks)
        result = f()
        if len(self._data.blocks) != blocks_before:
            self._clear_item_cache()
        return result
1136297
def _writeblocks(cls, blocks, available, cont_size, padding_func):
        """"""

        # write everything except padding
        data = bytearray()
        for block in blocks:
            if isinstance(block, Padding):
                continue
            data += cls._writeblock(block)
        blockssize = len(data)

        # take the padding overhead into account. we always add one
        # to make things simple.
        padding_block = Padding()
        blockssize += len(cls._writeblock(padding_block))

        # finally add a padding block
        info = PaddingInfo(available - blockssize, cont_size)
        padding_block.length = min(info._get_padding(padding_func),
                                   cls._MAX_SIZE)
        data += cls._writeblock(padding_block, is_last=True)

        return data
650963
def _split_file(f, blocksize):
    

    f_bytes = f.read()
    blocks = [int.from_bytes(f_bytes[i:i+blocksize].ljust(blocksize, b'0'), sys.byteorder) 
            for i in range(0, len(f_bytes), blocksize)]
    return len(f_bytes), blocks
417972
def stitch_block(block_list):
    '''
    
    '''
    block_out = [[]]
    for block in block_list:
        num_row = len(block)
        row_len = len(block[0])
        if len(block_out) < num_row:
            for i in range(num_row-len(block_out)):
                block_out.append([None]*len(block_out[0]))
        for row_out, row_in in zip(block_out, block):
            row_out.extend(row_in)
        if len(block_out) > num_row:
            for row_out in block_out[num_row:]:
                row_out.extend([None]*row_len)
    return block_out
1131468
public static List<Block> removeEmptyBlocks(final Collection<Block> blocks) {
      List<Block> cleanBlocks = Lists.newArrayListWithExpectedSize(blocks.size());
      for(Block block : blocks) {
         if(block.content.isEmpty()) {
            continue;
         }

         if(isWhitespace(block.content)) {
            continue;
         }

         cleanBlocks.add(block);
      }
      return cleanBlocks;
   }