Prepare static and dynamic search structures.
1596
def _compile(self):
        '''  '''
        self.static = {}
        self.dynamic = []
        def fpat_sub(m):
            return m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:'
        for rule in self.rules:
            target = self.routes[rule]
            if not self.syntax.search(rule):
                self.static[rule.replace('\\:',':')] = target
                continue
            gpat = self._compile_pattern(rule)
            fpat = re.sub(r'(\\*)(\(\?P<[^>]*>|\((?!\?))', fpat_sub, gpat.pattern)
            gpat = gpat if gpat.groupindex else None
            try:
                combined = '%s|(%s)' % (self.dynamic[-1][0].pattern, fpat)
                self.dynamic[-1] = (re.compile(combined), self.dynamic[-1][1])
                self.dynamic[-1][1].append((gpat, target))
            except (AssertionError, IndexError) as e: # AssertionError: Too many groups
                self.dynamic.append((re.compile('(^%s$)'%fpat),
                                    [(gpat, target)]))
            except re.error as e:
                raise RouteSyntaxError("Could not add Route: %s (%s)" % (rule, e))
1138302
def _apply_search_backrefs(pattern, flags=0):
    """"""

    if isinstance(pattern, (str, bytes)):
        re_verbose = VERBOSE & flags
        if flags & V0:
            re_version = V0
        elif flags & V1:
            re_version = V1
        else:
            re_version = 0
        if not (flags & DEBUG):
            pattern = _cached_search_compile(pattern, re_verbose, re_version, type(pattern))
        else:  # pragma: no cover
            pattern = _bregex_parse._SearchParser(pattern, re_verbose, re_version).parse()
    elif isinstance(pattern, Bregex):
        if flags:
            raise ValueError("Cannot process flags argument with a compiled pattern")
        pattern = pattern._pattern
    elif isinstance(pattern, _REGEX_TYPE):
        if flags:
            raise ValueError("Cannot process flags argument with a compiled pattern!")
    else:
        raise TypeError("Not a string or compiled pattern!")
    return pattern
1087228
protected function prepareProjectData(): void
  {
    parent::prepareProjectData();

    // Get file list form the project by fileset ID.
    $sources               = $this->getProject()->getReference($this->sourcesFilesetId);
    $this->sourceFileNames = $sources->getDirectoryScanner($this->getProject())->getIncludedFiles();
    $suc                   = ksort($this->sourceFileNames);
    if ($suc===false) $this->logError("ksort failed.");
  }
564860
@PostConstruct
    public void initialize() {
        for (final SearchScope scope : SearchScope.values()) {
            if (scope.ordinal() == this.searchControls.getSearchScope()) {
                this.searchScope = scope;
            }
        }
    }
65609
function prepare()
    {
        $this->query = null;
        $this->count = null;
        $this->items = null;
    }
826975
def prepare(cls, options, round_manager):
    """"""
    super(NodeResolve, cls).prepare(options, round_manager)
    for resolver in cls._resolver_by_type.values():
      resolver.prepare(options, round_manager)
386511
protected function prepare(): void
  {
    if (!$this->prepared)
    {
      $this->fieldSets->prepare('');

      $this->prepared = true;
    }
  }
965773
def _prepare_resources(self, variables, overrides=None):
        """"""

        if overrides is None:
            overrides = {}

        res_map = {}
        own_map = {}

        for decl in self.resources.values():
            resource = overrides.get(decl.name)

            if resource is None:
                args = _complete_parameters(decl.args, variables)
                resource = decl.type(args)
                own_map[decl.name] = resource

            if decl.autocreate:
                resource.open()

            res_map[decl.name] = resource

        return res_map, own_map
1253366
public function prepare()
  {
    $initFile=$this->basePath . DIRECTORY_SEPARATOR . $this->initScript;

    $this->checkIntegrity(false); //not supported in sqlite

    if(is_file($initFile))
      require($initFile);
    else
    {
      foreach($this->getFixtures() as $tableName=>$fixturePath)
      {
        $this->resetTable($tableName);
        $this->loadFixture($tableName);
      }
    }
    $this->checkIntegrity(true); //not supported in sqlite
  }
658071
private void preloadDynamicCaches() {
        List<CacheService> dynamicCacheServices = CacheRegistry.getInstance().getDynamicCacheServices();
        for (CacheService dynamicCacheService : dynamicCacheServices) {
            if (dynamicCacheService instanceof PreloadableCache) {
                try {
                    PreloadableCache preloadableCache = (PreloadableCache)dynamicCacheService;
                    RegisteredService regServ = preloadableCache.getClass().getAnnotation(RegisteredService.class);
                    Map<String,String> params = new HashMap<>();
                    Parameter[] parameters = regServ.parameters();
                    if (parameters != null) {
                        for (Parameter parameter : parameters) {
                            if (parameter.name().length() > 0)
                                params.put(parameter.name(), parameter.value());
                        }
                    }
                    preloadableCache.initialize(params);
                    preloadableCache.loadCache();
                }
                catch (Exception ex) {
                    logger.severeException("Failed to preload " + dynamicCacheService.getClass(), ex);
                }
            }
            synchronized(allCaches) {
                allCaches.put(dynamicCacheService.getClass().getName(), dynamicCacheService);
            }
        }
    }
269635
def build_dynamic(self, db, extra=None, safe_mode=False):
        """"""
        result = dict()
        for var, query in iteritems(self.dynamic):
            result[var] = db.query(query, safe_mode=safe_mode, additional_locals=extra)
        return result
94000
def _prepare_patterns(self, pattern_dict):
        """"""
        dict_compiled = {}
        dict_text = {}
        dict_dscr = {}
        for platform, patterns in pattern_dict.items():
            dict_text[platform] = {}
            dict_compiled[platform] = {}
            dict_dscr[platform] = {}

            for key, pattern in patterns.items():
                try:
                    text_pattern = None
                    compiled_pattern = None
                    description_pattern = None

                    if isinstance(pattern, str):
                        text_pattern = pattern
                        compiled_pattern = re.compile(text_pattern, re.MULTILINE)
                        description_pattern = key

                    elif isinstance(pattern, dict):
                        text_pattern = pattern['pattern']
                        compiled_pattern = re.compile(text_pattern, re.MULTILINE)
                        description_pattern = pattern['description']

                    elif isinstance(pattern, list):
                        text_pattern = self._concatenate_patterns(key, pattern)
                        compiled_pattern = re.compile(text_pattern, re.MULTILINE)
                        description_pattern = key

                    dict_text[platform][key] = text_pattern
                    dict_compiled[platform][key] = compiled_pattern
                    dict_dscr[platform][key] = description_pattern

                except re.error as e:
                    raise RuntimeError("Pattern compile error: {} ({}:{})".format(e.message, platform, key))

        return dict_compiled, dict_text, dict_dscr
789608
private function prepareBuilder(): void
    {
        if (!file_exists($this->getReportCacheDir())) {
            @mkdir($this->getReportCacheDir(), 0777, true);
        }

        $this->builder
             ->setCacheDir($this->getReportCacheDir())
             ->initialise();

        return;
    }
37922
void search() {

        CmsSearchReplaceSettings settings = new CmsSearchReplaceSettings();
        settings.setSiteRoot((String)m_siteSelect.getValue());
        settings.setType((SearchType)m_searchType.getValue());
        settings.setPaths(Collections.singletonList(m_searchRoot.getValue()));
        settings.setIgnoreSubSites(m_ignoreSubSites.getValue().booleanValue());
        I_CmsResourceType type = (I_CmsResourceType)m_resourceType.getValue();
        if (type != null) {
            settings.setTypes(type.getTypeName());
        }
        if (SearchType.resourcetype.equals(m_searchType.getValue())
            | SearchType.renameContainer.equals(m_searchType.getValue())) {
            settings.setTypes(
                CmsResourceTypeXmlContainerPage.getStaticTypeName()
                    + ","
                    + CmsResourceTypeXmlContainerPage.MODEL_GROUP_TYPE_NAME);
        }

        if (SearchType.renameContainer.equals(m_searchType.getValue())) {
            try {
                CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
                cms.getRequestContext().setSiteRoot("");
                CmsResource element = cms.readResource(m_resourceSearch.getValue());
                settings.setElementResource(element);
            } catch (CmsException e) {
                LOG.error("Can not read resource", e);
            }
        }

        if (m_replace.getValue().booleanValue()) {
            try {
                CmsProject workProject = A_CmsUI.getCmsObject().readProject((CmsUUID)m_workProject.getValue());
                settings.setProject(workProject.getName());
            } catch (CmsException e) {
                // ignore
            }
            if (SearchType.resourcetype.equals(m_searchType.getValue())) {
                try {
                    CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
                    cms.getRequestContext().setSiteRoot("");
                    CmsResource resource = cms.readResource(m_replaceResource.getValue());
                    settings.setReplacepattern(CmsSearchReplaceSettings.replaceElementInPagePattern(resource));
                } catch (CmsException e) {
                    LOG.error("Unable to read resource.", e);
                }
            } else if (SearchType.renameContainer.equals(m_searchType.getValue())) {
                settings.setReplacepattern(m_oldName.getValue() + ";" + m_newName.getValue());
            } else {

                settings.setReplacepattern(m_replacePattern.getValue());
            }

        }

        if (SearchType.resourcetype.equals(m_searchType.getValue())
            | SearchType.renameContainer.equals(m_searchType.getValue())) {
            try {
                CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
                cms.getRequestContext().setSiteRoot("");
                CmsResource resource = cms.readResource(m_resourceSearch.getValue());
                settings.setSearchpattern(CmsSearchReplaceSettings.searchElementInPagePattern(resource));
            } catch (CmsException e) {
                LOG.error("Unable to read resource.", e);
            }
        } else {

            settings.setSearchpattern(m_searchPattern.getValue());
        }
        if (settings.getType().isContentValuesOnly()) {
            if (m_locale.getValue() != null) {
                settings.setLocale(m_locale.getValue().toString());
            }
            settings.setXpath(m_xPath.getValue());
        }
        if (settings.getType().isSolrSearch()) {
            settings.setQuery(m_solrQuery.getValue());
            settings.setSource((String)m_searchIndex.getValue());
        }

        if (settings.getType().isPropertySearch()) {
            settings.setProperty((CmsPropertyDefinition)m_property.getValue());
            settings.setForceReplace(m_replace.getValue().booleanValue());
        }

        m_app.search(settings, true);
    }
946399
def preprocess_search_hit(pid, record_hit, links_factory=None, **kwargs):
        """"""
        links_factory = links_factory or (lambda x, **k: dict())
        record = dict(
            pid=pid,
            metadata=record_hit['_source'],
            links=links_factory(pid, record_hit=record_hit, **kwargs),
            revision=record_hit['_version'],
            created=None,
            updated=None,
        )
        # Move created/updated attrs from source to object.
        for key in ['_created', '_updated']:
            if key in record['metadata']:
                record[key[1:]] = record['metadata'][key]
                del record['metadata'][key]
        return record
1008986
void prepare(Map stormConf, TopologyContext context, OutputCollector collector,
                 KeyValueState<TaskStream, WindowState> windowState) {
        init(stormConf, context, collector, windowState);
        super.prepare(stormConf, context, collector);
    }
1085551
function prepare (o) {
    try {
      var input = checkInput(o)
      var q = Queries.mkQuery(input)

      // we have win!
      return [q]
    } catch (err) {
      // other than spewing, we ignore errors
      console.error(err.stack)

      // so this request will be flatmapped away
      return []
    }
  }