Precaches template chunks.
350014
public function precacheTemplate()
    {
        // Extract template chunks from grid template

        // header
        $header = $this->template->cloneRegion('header');
        $header_col = $header->cloneRegion('col');
        $header_sort = $header_col->cloneRegion('sort');
        $header->del('cols');

        // data row and column
        $row = $this->row_t;
        $col = $row->cloneRegion('col');
        $row->setHTML('row_id', '{$id}');
        $row->trySetHTML('odd_even', '{$odd_even}');
        $row->del('cols');

        // totals row and column
        if ($t_row = $this->totals_t) {
            $t_col = $t_row->cloneRegion('col');
            $t_row->del('cols');
        }

        // Add requested columns to row templates
        foreach ($this->columns as $name => $column) {

            // header row
            $header_col
                ->set('descr', $column['descr'])
                ->trySet('type', $column['type']);

            // sorting
            // TODO: rewrite this (and move into Advanced)
            if (isset($column['sortable'])) {
                $s = $column['sortable'];
                $header_sort
                    ->trySet('order', $s[0])
                    ->trySet('sorticon', $this->sort_icons[$s[0]]);
                $header_col
                    ->trySet('sortid', $sel = $this->name.'_sort_'.$name)
                    ->setHTML('sort', $header_sort->render());

                $this->js('click', $this->js()->reload(array($this->name.'_sort' => $s[1])))
                    ->_selector('#'.$sel);
            } else {
                $header_col
                    ->del('sort')
                    ->tryDel('sortid')
                    ->tryDel('sort_del');
            }

            // add thparams for header columns
            if ($column['thparam']) {
                $header_col->trySetHTML('thparam', $column['thparam']);
            } else {
                $header_col->tryDel('thparam');
            }
            $header->appendHTML('cols', $header_col->render());

            // data row
            $col->del('content')
                ->setHTML('content', '{$'.$name.'}')
                ->setHTML('tdparam', '{tdparam_'.$name.'}style="white-space:nowrap"{/}');
            $row->appendHTML('cols', $col->render());

            // totals row
            if (isset($t_row) && isset($t_col)) {
                $t_col
                    ->del('content')
                    ->setHTML('content', '{$'.$name.'}')
                    ->trySetHTML('tdparam', '{tdparam_'.$name.'}style="white-space:nowrap"{/}');
                $t_row
                    ->appendHTML('cols', $t_col->render());
            }
        }

        // Generate templates from rendered strings

        // header
        $this->template->setHTML('header', $this->show_header ? $header->render() : '');

        // data row
        $this->row_t = $this->app->add('GiTemplate');
        /** @type GiTemplate $this->row_t */
        $this->row_t->loadTemplateFromString($row->render());

        // totals row
        if (isset($t_row) && $this->totals_t) {
            $this->totals_t = $this->app->add('GiTemplate');
            /** @type GiTemplate $this->totals_t */
            $this->totals_t->loadTemplateFromString($t_row->render());
        }
    }
488513
def process_templates(input_dir, target_dir, context):
    
    if not target_dir.endswith('/'):
        target_dir = "{}/".format(target_dir)
    if not os.path.exists(target_dir):
        LOGGER.info('Creating: {}'.format(target_dir))
        os.makedirs(target_dir)
    replicate_directory_tree(input_dir, target_dir)
    templates = find_templates(input_dir)
    for templ in templates:
        output_file = templ.replace(input_dir, target_dir)
        output_file = output_file[:-len('.mustache')]
        render_template(templ,  output_file, context)
362666
function getTemplateResultChunk(result, stack) {
  let chunk = result.readChunk();

  // Skip empty strings
  if (Buffer.isBuffer(chunk) && chunk.length === 0) {
    chunk = result.readChunk();
  }

  // Finished reading, dispose
  if (chunk === null) {
    stack.shift();
  } else if (isTemplateResult(chunk)) {
    // Add to top of stack
    stack.unshift(chunk);
    chunk = getTemplateResultChunk(chunk, stack);
  }

  return chunk;
}
804676
function setCachedTemplateTree( $keyData, $uri, $res, $templatePath, &$extraParameters, &$root )
    {
        $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
        eZTemplateTreeCache::setCachedTree( $key, $uri, $res, $templatePath, $extraParameters, $root );
        eZTemplateTreeCache::storeCache( $key, $templatePath );
    }
915480
def _preallocate_samples(self):
        
        self.prealloc_samples_ = []
        for i in range(self.num_prealloc_samples_):
            self.prealloc_samples_.append(self.sample())
557027
def pre_order(self):
        """"""
        yield self
        for child in self.children:
            for node in child.pre_order():
                yield node
97714
def _chunk_iter(self):
        """"""
        for chunk_offset in self._chunk_offsets():
            yield self._download_chunk(chunk_offset=chunk_offset,
                                       chunk_size=self._chunk_size)
676155
def pack_chunk(tag, data):
        """"""
        to_check = tag + data
        return (struct.pack(b"!I", len(data)) + to_check +
                struct.pack(b"!I", zlib.crc32(to_check) & 0xFFFFFFFF))
719616
def flush_template(context, declaration=None, reconstruct=True):
	
	
	if declaration is None:
		declaration = Line(0, '')
	
	if {'text', 'dirty'}.issubset(context.flag):
		yield declaration.clone(line='yield "".join(_buffer)')
		
		context.flag.remove('text')  # This will force a new buffer to be constructed.
		context.flag.remove('dirty')
		
		if reconstruct:
			for i in ensure_buffer(context):
				yield i
	
	if declaration.stripped == 'yield':
		yield declaration
1259847
def chunks(lst, size):
    """"""
    for i in xrange(0, len(lst), size):
        yield lst[i:i + size]
32407
function transformChunkContents(chunk) {
    var contents = String(chunk.contents);
    try {
      if (chunk.isMarkdown) {
        contents = options.renderMarkdown(contents);
      }
      if (chunk.isTemplate) {
        contents = options.renderTemplate(contents, chunk.data, chunk.data.srcPath);
      }
      chunk.contents = new Buffer(contents);
      if (chunk.data.layout) applyLayout(chunk);
    } catch (err) {
      this.emit('error', new PluginError(logFlag, err.stack || err));
    }
    return chunk;
  }
1032234
def get_template(template_name, data_dir=None, url=None, resume=True, verbose=1):
    """"""
    warn(DEPRECATION_MSG)
    if template_name.startswith('tpl-'):
        template_name = template_name[4:]

    # An aliasing mechanism. Please avoid
    template_name = TEMPLATE_ALIASES.get(template_name, template_name)
    return get_dataset(template_name, dataset_prefix='tpl-', data_dir=data_dir,
                       url=url, resume=resume, verbose=verbose)
1079404
def chunk_sequence(sequence, chunk_length):
    """"""
    for index in range(0, len(sequence), chunk_length):
        yield sequence[index:index + chunk_length]
289546
function render(template, data, block) {
  data = Benchpress.addGlobals(data || {});

  return Promise.try(() => {
    Benchpress.cache[template] = Benchpress.cache[template] || load(template);
    return Benchpress.cache[template];
  }).then((templateFunction) => {
    if (block) {
      templateFunction = templateFunction.blocks && templateFunction.blocks[block];
    }
    if (!templateFunction) {
      return '';
    }

    return runtime(Benchpress.helpers, data, templateFunction);
  });
}
553004
function syncThroughChunks (prevChunk) {
    // all already synced?
    if (index > networkIndex) {
      return deferred.resolve()
    }

    function cachedGetHeader (id) {
      if (prevChunk === undefined ||
          !_.isNumber(id) ||
          Math.floor(id / 2016) !== index - 1) {
        return self.getHeader(id)
      }

      var idx = id % 2016
      var rawHeader = prevChunk.slice(idx * 80, (idx + 1) * 80)
      return Promise.resolve(_.extend(util.buffer2header(rawHeader), {
        height: id,
        hash: util.hashEncode(util.sha256x2(rawHeader))
      }))
    }

    // get not verified chunk for index
    self.connector.headersQuery(index * 2016, {count: 2016})
      .then(function (res) {
        var chunkHex = res.headers
        var prevHeaderPromise = index === 0
          ? {hash: util.zfill('', 64)} // special case for zero header
          : cachedGetHeader(index * 2016 - 1)

        return Promise.all([prevHeaderPromise, new Buffer(chunkHex, 'hex')])
      })
      .spread(function (prevHeader, rawChunk) {
        // compare hashPrevBlock of first header from chunk
        //  and derease index for blockchain reorg if not equal
        var firstHeader = util.buffer2header(rawChunk.slice(0, 80))
        if (firstHeader.hashPrevBlock !== prevHeader.hash) {
          index -= 1
          return timers.setImmediate(syncThroughChunks)
        }

        // remember for verifyHeader
        var prevHeaderHash = prevHeader.hash

        // calculate hash of last header from chunk for blockchain and storage
        var lastHash = util.hashEncode(util.sha256x2(rawChunk.slice(-80)))

        // calculate target for index
        return getTarget(index, headersChain, cachedGetHeader)
          .then(function (target) {
            // verify headers in chunk
            _.range(0, rawChunk.length, 80).forEach(function (offset) {
              var rawHeader = rawChunk.slice(offset, offset + 80)
              var currentHash = util.hashEncode(util.sha256x2(rawHeader))
              var currentHeader = util.buffer2header(rawHeader)

              verifyHeader(currentHash, currentHeader,
                           prevHeaderHash, prevHeader, target, self._isTestnet)

              prevHeaderHash = currentHash
              prevHeader = currentHeader
            })

            // set last hash to storage
            var promises = [self.storage.setLastHash(lastHash)]

            // truncate chunk hashes and headers if compact mode supported
            if (self.storage.compactMode) {
              promises.push(self.storage.truncateChunkHashes(index))
              promises.push(self.storage.truncateHeaders(0))
            }
            // truncate headers if compact mode not supported
            //  affected only when reorg needed
            if (!self.storage.compactMode) {
              promises.push(self.storage.truncateHeaders(index * 2016))
            }

            // wait all storage queries
            return Promise.all(promises)
          })
          .then(function () {
            // save chunk hash or headers
            if (self.storage.compactMode && rawChunk.length === 2016 * 80) {
              var chunkHash = util.hashEncode(util.sha256x2(rawChunk))
              return self.storage.putChunkHashes([chunkHash])

            } else {
              var headers = _.range(0, rawChunk.length, 80).map(function (offset) {
                return rawChunk.slice(offset, offset + 80).toString('hex')
              })
              return self.storage.putHeaders(headers)

            }
          })
          .then(function () {
            // update block hash and height for blockchain
            self.latest = {
              hash: lastHash,
              height: index * 2016 + rawChunk.length / 80 - 1
            }
            self.emit('newBlock', self.latest.hash, self.latest.height)

            // increase chunk index
            index += 1

            // sync next chunk
            timers.setImmediate(syncThroughChunks, rawChunk)
          })
      })
      .catch(function (err) { deferred.reject(err) })
  }
1363441
public function renderRows()
    {
        // precache template chunks
        $this->precacheTemplate();

        // extend CompleteLister renderRows method
        parent::renderRows();

        // if we have at least one data row rendered, then remove not_found message
        if ($this->total_rows) {
            $this->template->del('not_found');
        } elseif ($this->no_records_message) {
            $this->template->del('header');
            $this->template->set('not_found_message', $this->no_records_message);
        }
    }
1228429
def check_cache(self, template):
        '''
        
        '''
        if template not in self.cached:
            self.cache_file(template)
            self.cached.append(template)