text:
package search

import (
	"bytes"
	"fmt"
)

// search/Explanation.java

type Explanation interface {
	// Indicate whether or not this Explanation models a good match.
	// By default, an Explanation represents a "match" if the value is positive.
	IsMatch() bool
	// The value assigned to this explanation node.
	Value() float32
}

type ExplanationSPI interface {
	Explanation
	// A short one line summary which should contian all high level information
	// about this Explanation, without the Details.
	Summary() string
	Details() []Explanation
}

/* Expert: Describes the score computation for document and query. */
type ExplanationImpl struct {
	spi         ExplanationSPI
	value       float32       // the value of this node
	description string        // what it represents
	details     []Explanation // sub-explanations
}

func newExplanation(value float32, description string) *ExplanationImpl {
	ans := &ExplanationImpl{value: value, description: description}
	ans.spi = ans
	return ans
}

func (exp *ExplanationImpl) IsMatch() bool       { return exp.value > 0.0 }
func (exp *ExplanationImpl) Value() float32      { return exp.value }
func (exp *ExplanationImpl) Description() string { return exp.description }

func (exp *ExplanationImpl) Summary() string {
	return fmt.Sprintf("%v = %v", exp.value, exp.description)
}

// The sub-nodes of this explanation node.
func (exp *ExplanationImpl) Details() []Explanation {
	return exp.details
}

// Adds a sub-node to this explanation node
func (exp *ExplanationImpl) addDetail(detail Explanation) {
	exp.details = append(exp.details, detail)
}

// Render an explanation as text.
func (exp *ExplanationImpl) String() string {
	return explanationToString(exp.spi, 0)
}

func explanationToString(exp ExplanationSPI, depth int) string {
	assert(depth <= 1000) // potential dead loop
	var buf bytes.Buffer
	for i := 0; i < depth; i++ {
		buf.WriteString("  ")
	}
	buf.WriteString(exp.Summary())
	buf.WriteString("\n")

	for _, v := range exp.Details() {
		buf.WriteString(explanationToString(v.(ExplanationSPI), depth+1))
	}

	return buf.String()
}

// search/ComplexExplanation.java

/*
Expert: Describes the score computation for the doucment and query,
and can distinguish a match independent of a postive value.
*/
type ComplexExplanation struct {
	*ExplanationImpl
	match interface{}
}

func newEmptyComplexExplanation() *ComplexExplanation {
	ans := new(ComplexExplanation)
	ans.ExplanationImpl = new(ExplanationImpl)
	ans.spi = ans
	return ans
}

func newComplexExplanation(match bool, value float32, desc string) *ComplexExplanation {
	ans := new(ComplexExplanation)
	ans.ExplanationImpl = newExplanation(value, desc)
	ans.spi = ans
	ans.match = match
	return ans
}

/*
Indicates whether or not this Explanation models a good match.

If the match status is explicitly set (i.e.: not nil) this method
uses it; otherwise it defers to the superclass.
*/
func (e *ComplexExplanation) IsMatch() bool {
	return e.match != nil && e.match.(bool) || e.match == nil && e.ExplanationImpl.IsMatch()
}

func (e *ComplexExplanation) Summary() string {
	if e.match == nil {
		return e.ExplanationImpl.Summary()
	}
	return fmt.Sprintf("%v = %v %v", e.Value(),
		map[bool]string{true: "(MATCH)", false: "(NON_MATCH)"}[e.IsMatch()],
		e.Description())
}


text:
typedef double real;
extern "C" void distdriver_(long int *n,long int *len,
                 real *dists,
                 long int *toggle,
                 long int *ia,long int *ib,real *crit);

namespace RDPickers {

  RDKit::VECT_INT_VECT HierarchicalClusterPicker::cluster(const double *distMat,
                                                          unsigned int poolSize,
                                                          unsigned int pickSize) const {
    PRECONDITION(distMat, "Invalid Distance Matrix");
    PRECONDITION((poolSize >= pickSize),
                 "pickSize cannot be larger than the poolSize");

    // Do the clustering
    long int method = (long int)d_method;
    long int len = poolSize*(poolSize-1);
    long int *ia = (long int *)calloc(poolSize, sizeof(long int));
    long int *ib = (long int *)calloc(poolSize, sizeof(long int));
    real *crit = (real *)calloc(poolSize,sizeof(real));
    CHECK_INVARIANT(ia,"failed to allocate memory");
    CHECK_INVARIANT(ib,"failed to allocate memory");
    CHECK_INVARIANT(crit,"failed to allocate memory");
    long int poolSize2=static_cast<long int>(poolSize);

    distdriver_(&poolSize2, // number of items in the pool
                &len, // number of entries in the distance matrix
                (real *)distMat, // distance matrix
                &method, // the clustering method (ward, slink etc.)
                ia, // int vector with clustering history
                ib, // one more clustering history matrix
                crit // I believe this is a vector the difference in heights of two clusters
                );

    // we have the clusters now merge then until the number of clusters is same
    // as the number of picks we need
    // before we do that a bit of explanation on the vectors "ia" and "ib"
    //  - We with each item in the pool as an individual cluster
    //  - then we use the vectors ia and ib to merge them.
    //     ia and ib provides the ids of the clusters that need to be merged
    //     it is assumed that when a cluster ia[j] is merged with ib[j]
    //     ia[j] is replaced by the new cluster in the cluster list
    //
    RDKit::VECT_INT_VECT clusters;
    for (unsigned int i = 0; i < poolSize; i++) {
      RDKit::INT_VECT cls;
      cls.push_back(i);
      clusters.push_back(cls);
    }

    // do the merging, each round of of this loop eleminates one cluster
    RDKit::INT_VECT removed;
    for (unsigned int i = 0; i < (poolSize - pickSize); i++) {
      int cx1 = ia[i] - 1;
      int cx2 = ib[i] - 1;

      // add the items from cluster cx2 to cx1
      // REVIEW: merge function???
      for (RDKit::INT_VECT_CI cx2i = clusters[cx2].begin(); cx2i != clusters[cx2].end(); cx2i++) {
        clusters[cx1].push_back(*cx2i);
      }

      // mark the second cluster as removed
      removed.push_back(cx2);
    }
    free(ia);
    free(ib);
    free(crit);

    // sort removed so that looping will be easier later
    std::sort(removed.begin(), removed.end());

    //some error checking here, uniqueify removed and the vector should not changed
    // REVIEW can we put this inside a #ifdef DEBUG?
    RDKit::INT_VECT_CI nEnd = std::unique(removed.begin(), removed.end());
    CHECK_INVARIANT(nEnd == removed.end(), "Somehow there are duplicates in the list of removed clusters");

    RDKit::VECT_INT_VECT res;
    unsigned int j = 0;
    for (unsigned int i = 0; i < poolSize; i++) {
      if (static_cast<int>(i) == removed[j]) {
        j++;
        continue;
      }
      res.push_back(clusters[i]);
    }
    return res;
  }

  RDKit::INT_VECT HierarchicalClusterPicker::pick(const double *distMat,
                                                  unsigned int poolSize,
                                                  unsigned int pickSize) const {
    PRECONDITION(distMat,"bad distance matrix");
    RDKit::VECT_INT_VECT clusters = this->cluster(distMat, poolSize, pickSize);
    CHECK_INVARIANT(clusters.size() == pickSize, "");

    // the last step: find a representative element from each of the
    // remaining clusters
    RDKit::INT_VECT picks;
    for (unsigned int i = 0; i < pickSize; i++) {
      int pick;
      double minSumD2 = RDKit::MAX_DOUBLE;
      for (RDKit::INT_VECT_CI cxi1 = clusters[i].begin();
           cxi1 != clusters[i].end(); ++cxi1 ) {
        int curPick = (*cxi1);
        double d2sum = 0.0;
        for (RDKit::INT_VECT_CI cxi2 = clusters[i].begin();
             cxi2 != clusters[i].end(); ++cxi2) {
          if (cxi1 == cxi2) {
            continue;
          }
          double d = getDistFromLTM(distMat, curPick, (*cxi2));
          d2sum += (d*d);
        }
        if (d2sum < minSumD2) {
          pick = curPick;
          minSumD2 = d2sum;
        }
      }
      picks.push_back(pick);
    }
    return picks;
  }
}

redpajama_set_name: RedPajamaGithub


text:
<title>Docs for page DocumentProperties.php</title>
<link rel="stylesheet" type="text/css" href="../media/style.css">

    PHPExcel

  		  [ class tree: PHPExcel ]
		  [ index: PHPExcel ]
		  [ all elements ]

      Packages:

              PHPExcel

              PHPExcel_Cell

              PHPExcel_Reader

              PHPExcel_Shared

              PHPExcel_Style

              PHPExcel_Worksheet

              PHPExcel_Worksheet_Drawing

              PHPExcel_Writer

              PHPExcel_Writer_Excel2007

                        Files:

					Cell.php

					DocumentProperties.php

					DocumentSecurity.php

					HashTable.php

					PHPExcel.php

					Style.php

					Worksheet.php

            Classes:

		    		PHPExcel

	    		PHPExcel_Cell

	    		PHPExcel_DocumentProperties

	    		PHPExcel_DocumentSecurity

	    		PHPExcel_HashTable

	    		PHPExcel_Worksheet

Procedural File: DocumentProperties.php

Source Location: /PHPExcel/DocumentProperties.php

Classes:

PHPExcel_DocumentProperties

PHPExcel_DocumentProperties

Page Details:

PHPExcel
 Copyright (c) 2006 - 2007 PHPExcel, Maarten Balliauw
 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.

PHPExcel
 Copyright (c) 2006 - 2007 PHPExcel, Maarten Balliauw
 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Tags:

    filesource:  	Source Code for this file

    version:  	##VERSION##, ##DATE##

    license:  	LGPL

    copyright:  	Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)

		    Documentation generated on Mon, 23 Apr 2007 12:51:30 +0200 by phpDocumentor 1.3.0RC3


text:
<?php

/* @Twig/Exception/traces.txt.twig */
class __TwigTemplate_2180f1762b1090ce8686c02ca350a87a7a7502cfb62484a6fda6504e8acc6534 extends Twig_Template
{
    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        $this->parent = false;

        $this->blocks = array(
        );
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        $__internal_bcf5ca6a45d5fe2b66c7ba91909d63d4ed2f5a7d86b6ee0c7f7173e0a4b03585 = $this->env->getExtension("Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension");
        $__internal_bcf5ca6a45d5fe2b66c7ba91909d63d4ed2f5a7d86b6ee0c7f7173e0a4b03585->enter($__internal_bcf5ca6a45d5fe2b66c7ba91909d63d4ed2f5a7d86b6ee0c7f7173e0a4b03585_prof = new Twig_Profiler_Profile($this->getTemplateName(), "template", "@Twig/Exception/traces.txt.twig"));

        // line 1
        if (twig_length_filter($this->env, $this->getAttribute(($context["exception"] ?? $this->getContext($context, "exception")), "trace", array()))) {
            // line 2
            $context['_parent'] = $context;
            $context['_seq'] = twig_ensure_traversable($this->getAttribute(($context["exception"] ?? $this->getContext($context, "exception")), "trace", array()));
            foreach ($context['_seq'] as $context["_key"] => $context["trace"]) {
                // line 3
                $this->loadTemplate("@Twig/Exception/trace.txt.twig", "@Twig/Exception/traces.txt.twig", 3)->display(array("trace" => $context["trace"]));
                // line 4
                echo "
";
            }
            $_parent = $context['_parent'];
            unset($context['_seq'], $context['_iterated'], $context['_key'], $context['trace'], $context['_parent'], $context['loop']);
            $context = array_intersect_key($context, $_parent) + $_parent;
        }

        $__internal_bcf5ca6a45d5fe2b66c7ba91909d63d4ed2f5a7d86b6ee0c7f7173e0a4b03585->leave($__internal_bcf5ca6a45d5fe2b66c7ba91909d63d4ed2f5a7d86b6ee0c7f7173e0a4b03585_prof);

    }

    public function getTemplateName()
    {
        return "@Twig/Exception/traces.txt.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  30 => 4,  28 => 3,  24 => 2,  22 => 1,);
    }

    /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
    public function getSource()
    {
        @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);

        return $this->getSourceContext()->getCode();
    }

    public function getSourceContext()
    {
        return new Twig_Source("{% if exception.trace|length %}
{% for trace in exception.trace %}
{% include '@Twig/Exception/trace.txt.twig' with { 'trace': trace } only %}

{% endfor %}
{% endif %}
", "@Twig/Exception/traces.txt.twig", "D:\\wamp64\\www\\serveurDeVoeuxOmar\\vendor\\symfony\\symfony\\src\\Symfony\\Bundle\\TwigBundle\\Resources\\views\\Exception\\traces.txt.twig");
    }
}


text:
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/common/file_util.h"

#include <stddef.h>
#include <stdint.h>

#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_icon_set.h"
#include "extensions/common/extension_l10n_util.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/image_util.h"
#include "extensions/common/install_warning.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handler.h"
#include "extensions/common/manifest_handlers/default_locale_handler.h"
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "extensions/strings/grit/extensions_strings.h"
#include "net/base/filename_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"

#include "base/command_line.h"
#include "content/public/common/content_client.h"

using extensions::mojom::ManifestLocation;

namespace extensions {
namespace file_util {
namespace {

enum SafeInstallationFlag {
  DEFAULT,   // Default case, controlled by a field trial.
  DISABLED,  // Safe installation is disabled.
  ENABLED,   // Safe installation is enabled.
};
SafeInstallationFlag g_use_safe_installation = DEFAULT;

bool g_report_error_for_invisible_icon = false;

// Returns true if the given file path exists and is not zero-length.
bool ValidateFilePath(const base::FilePath& path) {
  int64_t size = 0;
  return base::PathExists(path) && base::GetFileSize(path, &size) && size != 0;
}

// Returns true if the extension installation should flush all files and the
// directory.
bool UseSafeInstallation() {
  if (g_use_safe_installation == DEFAULT) {
    const char kFieldTrialName[] = "ExtensionUseSafeInstallation";
    const char kEnable[] = "Enable";
    return base::FieldTrialList::FindFullName(kFieldTrialName) == kEnable;
  }

  return g_use_safe_installation == ENABLED;
}

enum FlushOneOrAllFiles {
   ONE_FILE_ONLY,
   ALL_FILES
};

// Flush all files in a directory or just one.  When flushing all files, it
// makes sure every file is on disk.  When flushing one file only, it ensures
// all parent directories are on disk.
void FlushFilesInDir(const base::FilePath& path,
                     FlushOneOrAllFiles one_or_all_files) {
  if (!UseSafeInstallation()) {
    return;
  }
  base::FileEnumerator temp_traversal(path,
                                      true,  // recursive
                                      base::FileEnumerator::FILES);
  for (base::FilePath current = temp_traversal.Next(); !current.empty();
      current = temp_traversal.Next()) {
    base::File currentFile(current,
                           base::File::FLAG_OPEN | base::File::FLAG_WRITE);
    currentFile.Flush();
    currentFile.Close();
    if (one_or_all_files == ONE_FILE_ONLY) {
      break;
    }
  }
}

}  // namespace

const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp");

void SetUseSafeInstallation(bool use_safe_installation) {
  g_use_safe_installation = use_safe_installation ? ENABLED : DISABLED;
}

base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir,
                                const std::string& id,
                                const std::string& version,
                                const base::FilePath& extensions_dir) {
  base::FilePath extension_dir = extensions_dir.AppendASCII(id);
  base::FilePath version_dir;

  // Create the extension directory if it doesn't exist already.
  if (!base::PathExists(extension_dir)) {
    if (!base::CreateDirectory(extension_dir))
      return base::FilePath();
  }

  // Get a temp directory on the same file system as the profile.
  base::FilePath install_temp_dir = GetInstallTempDir(extensions_dir);
  base::ScopedTempDir extension_temp_dir;
  if (install_temp_dir.empty() ||
      !extension_temp_dir.CreateUniqueTempDirUnderPath(install_temp_dir)) {
    LOG(ERROR) << "Creating of temp dir under in the profile failed.";
    return base::FilePath();
  }
  base::FilePath crx_temp_source =
      extension_temp_dir.GetPath().Append(unpacked_source_dir.BaseName());
  if (!base::Move(unpacked_source_dir, crx_temp_source)) {
    LOG(ERROR) << "Moving extension from : " << unpacked_source_dir.value()
               << " to : " << crx_temp_source.value() << " failed.";
    return base::FilePath();
  }

  // Try to find a free directory. There can be legitimate conflicts in the case
  // of overinstallation of the same version.
  const int kMaxAttempts = 100;
  for (int i = 0; i < kMaxAttempts; ++i) {
    base::FilePath candidate = extension_dir.AppendASCII(
        base::StringPrintf("%s_%u", version.c_str(), i));
    if (!base::PathExists(candidate)) {
      version_dir = candidate;
      break;
    }
  }

  if (version_dir.empty()) {
    LOG(ERROR) << "Could not find a home for extension " << id << " with "
               << "version " << version << ".";
    return base::FilePath();
  }

  // Flush the source dir completely before moving to make sure everything is
  // on disk. Otherwise a sudden power loss could cause the newly installed
  // extension to be in a corrupted state. Note that empty sub-directories
  // may still be lost.
  FlushFilesInDir(crx_temp_source, ALL_FILES);

  // The target version_dir does not exists yet, so base::Move() is using
  // rename() on POSIX systems. It is atomic in the sense that it will
  // either complete successfully or in the event of data loss be reverted.
  if (!base::Move(crx_temp_source, version_dir)) {
    LOG(ERROR) << "Installing extension from : " << crx_temp_source.value()
               << " into : " << version_dir.value() << " failed.";
    return base::FilePath();
  }

  // Flush one file in the new version_dir to make sure the dir move above is
  // persisted on disk. This is guaranteed on POSIX systems. ExtensionPrefs
  // is going to be updated with the new version_dir later. In the event of
  // data loss ExtensionPrefs should be pointing to the previous version which
  // is still fine.
  FlushFilesInDir(version_dir, ONE_FILE_ONLY);

  return version_dir;
}

void UninstallExtension(const base::FilePath& extensions_dir,
                        const std::string& id) {
  // We don't care about the return value. If this fails (and it can, due to
  // plugins that aren't unloaded yet), it will get cleaned up by
  // ExtensionGarbageCollector::GarbageCollectExtensions.
  base::DeletePathRecursively(extensions_dir.AppendASCII(id));
}

scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
                                       ManifestLocation location,
                                       int flags,
                                       std::string* error) {
  return LoadExtension(extension_path, nullptr, std::string(), location, flags,
                       error);
}

scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
                                       const std::string& extension_id,
                                       ManifestLocation location,
                                       int flags,
                                       std::string* error) {
  return LoadExtension(extension_path, nullptr, extension_id, location, flags,
                       error);
}

scoped_refptr<Extension> LoadExtension(
    const base::FilePath& extension_path,
    const base::FilePath::CharType* manifest_file,
    const std::string& extension_id,
    ManifestLocation location,
    int flags,
    std::string* error) {
  std::unique_ptr<base::DictionaryValue> manifest;
  if (!manifest_file) {
    manifest = LoadManifest(extension_path, error);
  } else {
    manifest = LoadManifest(extension_path, manifest_file, error);
  }
  if (!manifest.get())
    return nullptr;

  if (!extension_l10n_util::LocalizeExtension(
          extension_path, &manifest->GetDict(),
          extension_l10n_util::GetGzippedMessagesPermissionForLocation(
              location),
          error)) {
    return nullptr;
  }

  scoped_refptr<Extension> extension(Extension::Create(
      extension_path, location, *manifest, flags, extension_id, error));
  if (!extension.get())
    return nullptr;

  std::vector<InstallWarning> warnings;
  if (!ValidateExtension(extension.get(), error, &warnings))
    return nullptr;
  extension->AddInstallWarnings(std::move(warnings));

  return extension;
}

std::unique_ptr<base::DictionaryValue> LoadManifest(
    const base::FilePath& extension_path,
    std::string* error) {
  base::FilePath manifest_path = extension_path.Append(kNWJSManifestFilename);

  if (!base::PathExists(manifest_path))
    return LoadManifest(extension_path, kManifestFilename, error);

  std::unique_ptr<base::DictionaryValue> manifest =
    LoadManifest(extension_path, kNWJSManifestFilename, error);
  content::GetContentClient()->LoadNWAppAsExtension(manifest.get(), extension_path, error);

  base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
  if (cmdline->HasSwitch("mixed-context"))
    manifest->SetBoolean(manifest_keys::kNWJSMixedContext, true);

  return manifest;
}

std::unique_ptr<base::DictionaryValue> LoadManifest(
    const base::FilePath& extension_path,
    const base::FilePath::CharType* manifest_filename,
    std::string* error) {
  base::FilePath manifest_path = extension_path.Append(manifest_filename);
  if (!base::PathExists(manifest_path)) {
    *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
    return nullptr;
  }

  JSONFileValueDeserializer deserializer(manifest_path);
  std::unique_ptr<base::Value> root(deserializer.Deserialize(nullptr, error));
  if (!root.get()) {
    if (error->empty()) {
      // If |error| is empty, then the file could not be read.
      // It would be cleaner to have the JSON reader give a specific error
      // in this case, but other code tests for a file error with
      // error->empty().  For now, be consistent.
      *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
    } else {
      *error = base::StringPrintf(
          "%s  %s", manifest_errors::kManifestParseError, error->c_str());
    }
    return nullptr;
  }

  if (!root->is_dict()) {
    *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID);
    return nullptr;
  }

  return base::DictionaryValue::From(std::move(root));
}

bool ValidateExtension(const Extension* extension,
                       std::string* error,
                       std::vector<InstallWarning>* warnings) {
  // Ask registered manifest handlers to validate their paths.
  if (!ManifestHandler::ValidateExtension(extension, error, warnings))
    return false;

  // Check children of extension root to see if any of them start with _ and is
  // not on the reserved list. We only warn, and do not block the loading of the
  // extension.
#if 0
  std::string warning;
  if (!CheckForIllegalFilenames(extension->path(), &warning))
    warnings->push_back(InstallWarning(warning));

  // Check that the extension does not include any Windows reserved filenames.
  std::string windows_reserved_warning;
  if (!CheckForWindowsReservedFilenames(extension->path(),
                                        &windows_reserved_warning)) {
    warnings->push_back(InstallWarning(windows_reserved_warning));
  }

  // Check that extensions don't include private key files.
  std::vector<base::FilePath> private_keys =
      FindPrivateKeyFiles(extension->path());
  if (extension->creation_flags() & Extension::ERROR_ON_PRIVATE_KEY) {
    if (!private_keys.empty()) {
      // Only print one of the private keys because l10n_util doesn't have a way
      // to translate a list of strings.
      *error =
          l10n_util::GetStringFUTF8(IDS_EXTENSION_CONTAINS_PRIVATE_KEY,
                                    private_keys.front().LossyDisplayName());
      return false;
    }
  } else {
    for (size_t i = 0; i < private_keys.size(); ++i) {
      warnings->push_back(InstallWarning(
          l10n_util::GetStringFUTF8(IDS_EXTENSION_CONTAINS_PRIVATE_KEY,
                                    private_keys[i].LossyDisplayName())));
    }
    // Only warn; don't block loading the extension.
  }
#endif
  return true;
}

std::vector<base::FilePath> FindPrivateKeyFiles(
    const base::FilePath& extension_dir) {
  std::vector<base::FilePath> result;
  // Pattern matching only works at the root level, so filter manually.
  base::FileEnumerator traversal(
      extension_dir, /*recursive=*/true, base::FileEnumerator::FILES);
  for (base::FilePath current = traversal.Next(); !current.empty();
       current = traversal.Next()) {
    if (!current.MatchesExtension(kExtensionKeyFileExtension))
      continue;

    std::string key_contents;
    if (!base::ReadFileToString(current, &key_contents)) {
      // If we can't read the file, assume it's not a private key.
      continue;
    }
    std::string key_bytes;
    if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) {
      // If we can't parse the key, assume it's ok too.
      continue;
    }

    result.push_back(current);
  }
  return result;
}

bool CheckForIllegalFilenames(const base::FilePath& extension_path,
                              std::string* error) {
#if 0
  // Enumerate all files and directories in the extension root.
  // There is a problem when using pattern "_*" with FileEnumerator, so we have
  // to cheat with find_first_of and match all.
  const int kFilesAndDirectories =
      base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES;
  base::FileEnumerator all_files(extension_path, false, kFilesAndDirectories);

  base::FilePath file;
  while (!(file = all_files.Next()).empty()) {
    base::FilePath::StringType filename = file.BaseName().value();

    // Skip all filenames that don't start with "_".
    if (filename.find_first_of(FILE_PATH_LITERAL("_")) != 0)
      continue;

    // Some filenames are special and allowed to start with "_".
    if (filename == kLocaleFolder || filename == kPlatformSpecificFolder ||
        filename == FILE_PATH_LITERAL("__MACOSX")) {
      continue;
    }

    *error = base::StringPrintf(
        "Cannot load extension with file or directory name %s. "
        "Filenames starting with \"_\" are reserved for use by the system.",
        file.BaseName().AsUTF8Unsafe().c_str());
    return false;
  }
#endif
  return true;
}

bool CheckForWindowsReservedFilenames(const base::FilePath& extension_dir,
                                      std::string* error) {
  const int kFilesAndDirectories =
      base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES;
  base::FileEnumerator traversal(extension_dir, true, kFilesAndDirectories);

  for (base::FilePath current = traversal.Next(); !current.empty();
       current = traversal.Next()) {
    base::FilePath::StringType filename = current.BaseName().value();
    bool is_reserved_filename = net::IsReservedNameOnWindows(filename);
    if (is_reserved_filename) {
      *error = base::StringPrintf(
          "Cannot load extension with file or directory name %s. "
          "The filename is illegal.",
          current.BaseName().AsUTF8Unsafe().c_str());
      return false;
    }
  }

  return true;
}

base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir) {
  // We do file IO in this function, but only when the current profile's
  // Temp directory has never been used before, or in a rare error case.
  // Developers are not likely to see these situations often.

  // Create the temp directory as a sub-directory of the Extensions directory.
  // This guarantees it is on the same file system as the extension's eventual
  // install target.
  base::FilePath temp_path = extensions_dir.Append(kTempDirectoryName);
  if (base::PathExists(temp_path)) {
    if (!base::DirectoryExists(temp_path)) {
      DLOG(WARNING) << "Not a directory: " << temp_path.value();
      return base::FilePath();
    }
    if (!base::PathIsWritable(temp_path)) {
      DLOG(WARNING) << "Can't write to path: " << temp_path.value();
      return base::FilePath();
    }
    // This is a directory we can write to.
    return temp_path;
  }

  // Directory doesn't exist, so create it.
  if (!base::CreateDirectory(temp_path)) {
    DLOG(WARNING) << "Couldn't create directory: " << temp_path.value();
    return base::FilePath();
  }
  return temp_path;
}

base::FilePath ExtensionURLToRelativeFilePath(const GURL& url) {
  base::StringPiece url_path = url.path_piece();
  if (url_path.empty() || url_path[0] != '/')
    return base::FilePath();

  // Convert %-encoded UTF8 to regular UTF8.
  std::string file_path;
  if (!base::UnescapeBinaryURLComponentSafe(
          url_path, true /* fail_on_path_separators */, &file_path)) {
    // There shouldn't be any escaped path separators or control characters in
    // the path. However, if there are, it's best to just fail.
    return base::FilePath();
  }

  // Drop the leading slashes.
  size_t skip = file_path.find_first_not_of("/\\");
  if (skip != file_path.npos)
    file_path = file_path.substr(skip);

  base::FilePath path = base::FilePath::FromUTF8Unsafe(file_path);

  // It's still possible for someone to construct an annoying URL whose path
  // would still wind up not being considered relative at this point.
  // For example: chrome-extension://id/c:////foo.html
  if (path.IsAbsolute())
    return base::FilePath();

  return path;
}

void SetReportErrorForInvisibleIconForTesting(bool value) {
  g_report_error_for_invisible_icon = value;
}

bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set,
                              const Extension* extension,
                              const char* manifest_key,
                              SkColor background_color,
                              std::string* error) {
  for (const auto& entry : icon_set.map()) {
    const base::FilePath path =
        extension->GetResource(entry.second).GetFilePath();
    if (!ValidateFilePath(path)) {
      constexpr char kIconMissingError[] =
          "Could not load icon '%s' specified in '%s'.";
      *error = base::StringPrintf(kIconMissingError, entry.second.c_str(),
                                  manifest_key);
      return false;
    }

    if (extension->location() == ManifestLocation::kUnpacked) {
      const bool is_sufficiently_visible =
          image_util::IsIconAtPathSufficientlyVisible(path);
      const bool is_sufficiently_visible_rendered =
          image_util::IsRenderedIconAtPathSufficientlyVisible(path,
                                                              background_color);
      UMA_HISTOGRAM_BOOLEAN(
          "Extensions.ManifestIconSetIconWasVisibleForUnpacked",
          is_sufficiently_visible);
      UMA_HISTOGRAM_BOOLEAN(
          "Extensions.ManifestIconSetIconWasVisibleForUnpackedRendered",
          is_sufficiently_visible_rendered);
      if (!is_sufficiently_visible && g_report_error_for_invisible_icon) {
        constexpr char kIconNotSufficientlyVisibleError[] =
            "Icon '%s' specified in '%s' is not sufficiently visible.";
        *error = base::StringPrintf(kIconNotSufficientlyVisibleError,
                                    entry.second.c_str(), manifest_key);
        return false;
      }
    }
  }
  return true;
}

MessageBundle* LoadMessageBundle(
    const base::FilePath& extension_path,
    const std::string& default_locale,
    extension_l10n_util::GzippedMessagesPermission gzip_permission,
    std::string* error) {
  error->clear();
  // Load locale information if available.
  base::FilePath locale_path = extension_path.Append(kLocaleFolder);
  if (!base::PathExists(locale_path))
    return nullptr;

  std::set<std::string> chrome_locales;
  extension_l10n_util::GetAllLocales(&chrome_locales);

  base::FilePath default_locale_path = locale_path.AppendASCII(default_locale);
  if (default_locale.empty() ||
      chrome_locales.find(default_locale) == chrome_locales.end() ||
      !base::PathExists(default_locale_path)) {
    *error = l10n_util::GetStringUTF8(
        IDS_EXTENSION_LOCALES_NO_DEFAULT_LOCALE_SPECIFIED);
    return nullptr;
  }

  MessageBundle* message_bundle = extension_l10n_util::LoadMessageCatalogs(
      locale_path, default_locale, gzip_permission, error);

  return message_bundle;
}

base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) {
  return extension_path
      .Append(kVerifiedContentsFilename);
}
base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) {
  return extension_path.Append(kComputedHashesFilename);
}
base::FilePath GetIndexedRulesetDirectoryRelativePath() {
  return base::FilePath(kMetadataFolder).Append(kIndexedRulesetDirectory);
}
base::FilePath GetIndexedRulesetRelativePath(int static_ruleset_id) {
  const char* kRulesetPrefix = "_ruleset";
  std::string filename =
      kRulesetPrefix + base::NumberToString(static_ruleset_id);
  return GetIndexedRulesetDirectoryRelativePath().AppendASCII(filename);
}

std::vector<base::FilePath> GetReservedMetadataFilePaths(
    const base::FilePath& extension_path) {
  return {GetVerifiedContentsPath(extension_path),
          GetComputedHashesPath(extension_path),
          extension_path.Append(GetIndexedRulesetDirectoryRelativePath())};
}

}  // namespace file_util
}  // namespace extensions


text:
/* Javadoc style sheet */

/* Define colors, fonts and other style attributes here to override the defaults */

/* Page background color */
body { background-color: #FEFEFE; color:#000000; font-family: Helvetica, Tahoma, Arial, sans-serif; }

a
{
  color: #336699;
}
a:hover
{
  text-decoration: underline;
}
/* Headings */
h1
{
  font-size: 145%;
}

h1, h2
{
    border-bottom: 2px solid #EDEDED;
}

/* Table colors */
.TableHeadingColor
{
  background: #D1E29C; color:#000000;
  font-family: Tahoma, Arial, sans-serif;
} /* Dark mauve */
.TableSubHeadingColor
{
    background: #E4EBCE;
    color:#000000;
    font-family: Tahoma, Arial, sans-serif;
}
.TableRowColor
{
    background: #FFFFFF;
    color:#000000;

} /* White */

.TableRowColor td
{
    border: 1px solid; border-color: #AAAAAA;
}

.TableHeadingColor, .TableSubHeadingColor, .TableRowColor
{
  border: 1px solid #E4EBCE;
} /*  */

/* Font used in left-hand frame lists */
.FrameTitleFont   { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
.FrameHeadingFont { font-size:  90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
.FrameItemFont    { font-size:  90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }

/* Navigation bar fonts and colors */
.NavBarCell1    { background-color:#E4EBCE; color:#000000} /* Light mauve */
.NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */
.NavBarFont1    { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;}
.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;}

.NavBarCell2    { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
.NavBarCell3    { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}

hr { border: 1px solid #D1E29C }

table
{
  border: 0px dashed;
}
th { border: 1px }
tr { border: 1px solid; border-color: #AAAAAA; }
td {  }

.diagram
{
    display: inline-block;
    text-align: center;
    border: 1px solid #AAAAAA;
    background: #F7F7F7;
    min-width: 500px;

}
.diagram img
{
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* Colour Lovers
http://www.colourlovers.com/palette/1392493/Android
Smog: #464D5C
Android Robot: #A4C639
Pastel Green: #D1E29C
Decay: #E4EBCE
Ebonics 444: #F0F0F0
*/


text:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EmpMan.Model.Models
{
    [Table("AnnouncementUsers")]
    public class AnnouncementUser
    {
        [Key]
        [Column(Order = 1)]
        public int AnnouncementId { get; set; }

        [Key]
        [Column(Order = 2)]
        public string UserId { get; set; }

        public bool HasRead { get; set; }

        [ForeignKey("UserId")]
        public virtual AppUser AppUser { get; set; }

        [ForeignKey("AnnouncementId")]
        public virtual Announcement Announcement { get; set; }
    }
}


text:
<?php
return [
    /*
    |--------------------------------------------------------------------------
    | User Language Lines
    |--------------------------------------------------------------------------
    |
    */
    'cant_delete_self' => "Vous ne pouvez pas supprimer votre compte.",
    'delete' => "Supprimer",
    'delete_confirmation' => "L'utilisateur a bien été supprimé.",
    'no_enough_users' => "Vous ne pouvez pas supprimer cet utilisateur, il n'y a pas assez d'utilisateurs restants.",
    'success_edit' => "L'utilisateur a bien été modifié.",
    'user_admin_h1' => "Liste des utilisateurs",
    'user_admin_title' => "Liste des utilisateurs",
    'user_edit_admin_h1' => "Éditer l'utilisateur",
    'user_edit_admin_title' => "Éditer l'utilisateur",
];


text:
"""
Template tags for rendering the sidebar.
"""

from django import template

register = template.Library()

class SidebarSelectNode(template.Node):
    def __init__(self, selected):
        self.selected = selected

    def render(self, context):
        # Store page type in template context.
        context['sidebar_selected'] = self.selected
        return ''

@register.tag
def sidebar_select(parser, token):
    try:
        tag_name, selected = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]
    return SidebarSelectNode(str(selected))


text:
sudo update-rc.d -f pitimer remove
sudo cp pitimer.sh /etc/init.d/pitimer
sudo chmod 755 /etc/init.d/pitimer
sudo update-rc.d pitimer defaults

# setup we don't want to run as sudo all of the time.
sudo chown root /usr/local/bin/pi-timer
sudo chmod 4755 /usr/local/bin/pi-timer


text:
@protocol UIWebPDFViewHandlerDelegate

@optional
- (id)alertViewForUIWebPDFViewHandler:(id)arg1;
- (double)minimumVerticalContentOffsetForPDFViewHandler:(id)arg1;
- (id)hostViewForLinkSheet:(id)arg1;
- (id)pdfViewHandler:(id)arg1 actionsForURL:(id)arg2 suggestedActions:(id)arg3;
- (void)pdfViewHandlerCompletedLayoutAndIsUnlocked:(id)arg1;
- (void)highlightSearchResultBounds:(struct CGRect)arg1 resultRects:(id)arg2 contentViews:(id)arg3 forPDFViewHandler:(id)arg4;
- (id)passwordForPDFViewHandler:(id)arg1;
- (struct CGPoint)originForPDFPageLabelViewWithHandler:(id)arg1 proposedOrigin:(struct CGPoint)arg2;
- (struct CGRect)frameForPDFViewWithHandler:(id)arg1 proposedFrame:(struct CGRect)arg2;
- (void)pdfViewHandler:(id)arg1 linkClicked:(id)arg2;
- (void)pdfViewHandler:(id)arg1 willClickLink:(id)arg2;
@end


text:
package com.izforge.izpack.panels.userinput.gui.file;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.logging.Logger;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.izforge.izpack.gui.ButtonFactory;
import com.izforge.izpack.installer.data.GUIInstallData;
import com.izforge.izpack.installer.gui.InstallerFrame;
import com.izforge.izpack.installer.gui.IzPanel;
import com.izforge.izpack.panels.userinput.field.file.AbstractFileField;
import com.izforge.izpack.panels.userinput.field.file.FileFieldView;

public class FileInputField extends JPanel implements ActionListener
{
    private static final long serialVersionUID = 4673684743657328492L;

    private static final transient Logger logger = Logger.getLogger(FileInputField.class.getName());

    /**
     * The field view.
     */
    private final FileFieldView view;

    /**
     * The field.
     */
    private final AbstractFileField field;

    InstallerFrame parentFrame;

    IzPanel parent;

    JTextField filetxt;

    JButton browseBtn;

    GUIInstallData installDataGUI;

    public FileInputField(FileFieldView view, IzPanel parent, GUIInstallData installDataGUI)
    {
        this.view = view;
        this.field = view.getField();
        this.parent = parent;
        this.parentFrame = parent.getInstallerFrame();
        this.installDataGUI = installDataGUI;
        this.initialize();
    }

    public void setFile(String filename)
    {
        filetxt.setText(filename);
    }

    @Override
    public void actionPerformed(ActionEvent arg0)
    {
        if (arg0.getSource() == browseBtn)
        {
            logger.fine("Show directory chooser");
            String initialPath = ".";
            if (filetxt.getText() != null)
            {
                initialPath = filetxt.getText();
            }
            JFileChooser filechooser = new JFileChooser(initialPath);
            prepareFileChooser(filechooser);

            if (filechooser.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION)
            {
                String selectedFile = filechooser.getSelectedFile().getAbsolutePath();
                filetxt.setText(selectedFile);
                logger.fine("Setting current file chooser directory to: " + selectedFile);
            }
        }
    }

    protected void prepareFileChooser(JFileChooser filechooser)
    {
        filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        String fileExtension = field.getFileExtension();
        String fileExtensionDescription = field.getFileExtensionDescription();
        if ((fileExtension != null) && (fileExtensionDescription != null))
        {
            UserInputFileFilter fileFilter = new UserInputFileFilter();
            fileFilter.setFileExt(fileExtension);
            fileFilter.setFileExtDesc(fileExtensionDescription);
            filechooser.setFileFilter(fileFilter);
        }
    }

    public File getSelectedFile()
    {
        File result = null;
        if ((filetxt.getText() != null) && (filetxt.getText().length() > 0))
        {
            result = new File(filetxt.getText());
        }
        return result;
    }

    public boolean validateField()
    {
        String path = filetxt.getText();
        if (path.length() > 0)
        {
            File file = field.getAbsoluteFile(path);
            filetxt.setText(file.getPath());
        }
        return view.validate(filetxt.getText());
    }

    private void initialize()
    {
        int size = field.getSize() < 0 ? 0 : field.getSize();
        filetxt = new JTextField(size);
        filetxt.setName(field.getVariable());
        filetxt.setCaretPosition(0);

        GridBagLayout layout = new GridBagLayout();
        setLayout(layout);
        GridBagConstraints fileTextConstraint = new GridBagConstraints();
        GridBagConstraints fileButtonConstraint = new GridBagConstraints();
        fileTextConstraint.gridx = 0;
        fileTextConstraint.gridy = 0;
        fileTextConstraint.anchor = GridBagConstraints.WEST;
        fileTextConstraint.insets = new Insets(0, 0, 0, 5);
        fileButtonConstraint.gridx = 1;
        fileButtonConstraint.gridy = 0;
        fileButtonConstraint.anchor = GridBagConstraints.WEST;

        // TODO: use separate key for button text
        browseBtn = ButtonFactory.createButton(installDataGUI.getMessages().get("UserInputPanel.search.browse"),
                                               installDataGUI.buttonsHColor);
        browseBtn.addActionListener(this);
        this.add(filetxt, fileTextConstraint);
        this.add(browseBtn, fileButtonConstraint);
    }

    @Override
    public void setEnabled(boolean enabled)
    {
        filetxt.setEnabled(enabled);
        browseBtn.setEnabled(enabled);
    }

}


text:
    #pragma hdrstop
#endif

#if wxUSE_HTML && wxUSE_STREAMS

#ifndef WXPRECOMP
#endif

#include "wx/html/forcelnk.h"
#include "wx/html/m_templ.h"

#include <wx/filefn.h>
#include <wx/stdpaths.h>

FORCE_LINK_ME(nslinks)

class wxHtmlAnchorCell : public wxHtmlCell
{
private:
    wxString m_AnchorName;

public:
    wxHtmlAnchorCell(const wxString& name) : wxHtmlCell()
        { m_AnchorName = name; }
    void Draw(wxDC& WXUNUSED(dc),
              int WXUNUSED(x), int WXUNUSED(y),
              int WXUNUSED(view_y1), int WXUNUSED(view_y2),
              wxHtmlRenderingInfo& WXUNUSED(info)) {}

    DECLARE_NO_COPY_CLASS(wxHtmlAnchorCell)
};

TAG_HANDLER_BEGIN(A, "A")
    TAG_HANDLER_CONSTR(A) { }

    TAG_HANDLER_PROC(tag)
    {
        if (tag.HasParam( wxT("HREF") ))
        {
            wxHtmlLinkInfo oldlnk = m_WParser->GetLink();
            wxColour oldclr = m_WParser->GetActualColor();
            wxString name(tag.GetParam( wxT("HREF") )), target;

            if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") );

            wxColour colour = m_WParser->GetLinkColor();
            wxHtmlLinkInfo linkInfo(name, target);

            if (name.Left(3).IsSameAs((const wxChar*)"EX:", false))
            {
                wxString url = name.Mid(3);
                if (!url.Left(7).IsSameAs((const wxChar*)"http://", false) && !url.Left(6).IsSameAs((const wxChar*)"irc://", false))
                {
                    wxString exePath = wxStandardPaths::Get().GetExecutablePath();
                    wxString path = ::wxPathOnly(exePath);
                    path.Append(wxFileName::GetPathSeparators()[0]);
                    path.Append(url);

                    if (!::wxFileExists(path) && !::wxDirExists(path))
                    {
                        colour = wxColour(0x80, 0x80, 0x80);
                        linkInfo = wxHtmlLinkInfo(wxT("notinstalled.html"), target);
                    }
                }
            }

            m_WParser->SetActualColor(colour);
            m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(colour));
            m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
            m_WParser->SetLink(linkInfo);

            ParseInner(tag);

            m_WParser->SetLink(oldlnk);
            m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
            m_WParser->SetActualColor(oldclr);
            m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));

            return true;
        }
        else return false;
    }

TAG_HANDLER_END(A)

TAGS_MODULE_BEGIN(CustomLinks)

    TAGS_MODULE_ADD(A)

TAGS_MODULE_END(CustomLinks)

#endif


text:
package geomi

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"math/rand"
	"net/http"
	"net/url"
	"sort"
	"strings"
	"sync"
	"time"

	"github.com/mohae/firkin/queue"
	"github.com/temoto/robotstxt-go"
	"golang.org/x/net/html"
)

// Defaults
var (
	DefaultFetchInterval  time.Duration = time.Second                                                                                // default min. time between fetches
	DefaultJitter         time.Duration = time.Second                                                                                // default max additional, random, fetch delay
	DefaultRobotUserAgent string        = "Googlebot (geomi)"                                                                                // default user agent identifier for the bot.
	DefaultUserAgent      string        = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" // the default user agent
)

// Fetcher is an interface that makes it easier to test. In the future, it may be
// useful for other purposes, but that would require exporting the method that uses
// it first.
type Fetcher interface {
	// Fetch returns the body of URL and
	// a slice of URLs found on that page
	Fetch(url string) (body string, r ResponseInfo, urls []string)
}

type Config struct {
	CheckExternalLinks bool          // Whether a HEAD should be performed on external links
	FetchInterval      time.Duration // The minimum time between fetching URLS
	Jitter             time.Duration // The max amount of jitter to add to the FetchInterval, the actual jitter is random.
	RespectRobots      bool          // Whether the robots.txt should be respected
	RestrictToScheme   bool          // Whether the crawl should be restricted to the base URL's scheme
	RobotUserAgent     string        // The user agent for the robot
	UserAgent          string        // The user agent to use.
}

// NewConfig returns a Config struct with Geomi defaults applied.
func NewConfig() *Config {
	return &Config{
		CheckExternalLinks: true,
		FetchInterval:      DefaultFetchInterval,
		Jitter:             DefaultJitter,
		RespectRobots:      true,
		RestrictToScheme:   false,
		RobotUserAgent:     DefaultRobotUserAgent,
		UserAgent:          DefaultUserAgent,
	}
}

// SetFetchInterval sets both the FetchInterval and Jitter to the passed value.
// Min FetchInterval will always be == t while the Max Fetchinterval will always be
// 2t, with most fetches being a random value between t and 2t.
func (c *Config) SetFetchInterval(t time.Duration) {
	c.FetchInterval = t
	c.Jitter = t
}

// a page is a url. This is usually some content wiht a number of elements, but it
// could be something as simple as the url for cat.jpg on your site and represent that
// image.
type Page struct {
	*url.URL
	distance int
	body     string
	links    []string // immediate children
}

// ResponseInfo contains the status and error information from a get
// TODO:
//	Add Expire date
//	Add time for request to return
//	Should the body be in here?
type ResponseInfo struct {
	Status     string
	StatusCode int
	Err        error
}

// Site is a type that implements fetcher
type Site struct {
	*url.URL
}

// Implements fetcher.
// TODO: make the design cleaner
func (s Site) Fetch(url string) (body string, r ResponseInfo, urls []string) {
	// see if the passed url is outside of the baseURL
	resp, err := http.Get(url)
	if err != nil {
		r.Err = err
		return "", r, nil
	}
	defer resp.Body.Close()
	r.Status = resp.Status
	r.StatusCode = resp.StatusCode
	buff := &bytes.Buffer{}
	tee := io.TeeReader(resp.Body, buff)
	tokens := getTokens(tee)
	if len(tokens) == 0 {
		r.Err = fmt.Errorf("%s: nothing in body", url)
		return "", r, nil
	}
	urls, err = s.linksFromTokens(tokens)
	if err != nil {
		r.Err = err
		return "", r, nil
	}
	return buff.String(), r, urls
}

// linksFromTokens returns a list of links (href a) found in the token slice
// TODO should internal links be tracked separatly? i.e. record them in a
// separate var (so they don't get fetched)
func (s *Site) linksFromTokens(tokens []html.Token) ([]string, error) {
	var links []string
	for _, token := range tokens {
		if token.Type == html.StartTagToken && token.DataAtom.String() == "a" {
			for _, attr := range token.Attr {
				// We only care about links that aren't #
				if attr.Key == "href" && !strings.HasPrefix(attr.Val, "#") {
					// parse the url
					url, err := url.Parse(attr.Val)
					if err != nil {
						return nil, err
					}
					link := s.URL.ResolveReference(url)
					links = append(links, link.String())
				}
			}
		}
	}
	return links, nil
}

// Spider crawls the target. It contains all information needed to manage the crawl
// including keeping track of work to do, work done, and the results.
type Spider struct {
	*queue.Queue
	sync.Mutex
	wg            sync.WaitGroup
	*url.URL      // the start url
	Config        *Config
	robots        *robotstxt.Group
	maxDepth      int
	Pages         map[string]Page
	foundURLs     map[string]struct{}     // keeps track of urls found to prevent recrawling
	fetchedURLs   map[string]ResponseInfo // urls that have been fetched with their status
	skippedURLs   map[string]struct{}     // urls within the same domain that are not retrieved
	externalHosts map[string]struct{}     // list of external hosts TODO: elide?
	externalLinks map[string]ResponseInfo // list of external links; if fetched,
}

// returns a Spider with the its site's baseUrl set. The baseUrl is the start point for
// the crawl. It is also the restriction on the crawl:
func NewSpider(start string) (*Spider, error) {
	if start == "" {
		return nil, errors.New("newSpider: the start url cannot be empty")
	}
	var err error
	spider := &Spider{
		Queue:         queue.NewQ(128),
		Config:        NewConfig(),
		Pages:         make(map[string]Page),
		foundURLs:     make(map[string]struct{}),
		fetchedURLs:   make(map[string]ResponseInfo),
		skippedURLs:   make(map[string]struct{}),
		externalHosts: make(map[string]struct{}),
		externalLinks: make(map[string]ResponseInfo),
	}
	spider.URL, err = url.Parse(start)
	if err != nil {
		return nil, err
	}
	return spider, nil
}

// NewSpiderFromConfig returns a spider with it's configuration set to the passed
// config.
func NewSpiderFromConfig(start string, c *Config) (*Spider, error) {
	if start == "" {
		return nil, errors.New("newSpider: the start url cannot be empty")
	}
	var err error
	spider := &Spider{
		Queue:         queue.NewQ(128),
		Config:        c,
		Pages:         make(map[string]Page),
		foundURLs:     make(map[string]struct{}),
		fetchedURLs:   make(map[string]ResponseInfo),
		skippedURLs:   make(map[string]struct{}),
		externalHosts: make(map[string]struct{}),
		externalLinks: make(map[string]ResponseInfo),
	}
	spider.URL, err = url.Parse(start)
	if err != nil {
		return nil, err
	}
	return spider, nil
}

// ExternalHosts returns a sorted list of external hosts
func (s *Spider) ExternalHosts() []string {
	hosts := make([]string, len(s.externalHosts), len(s.externalHosts))
	i := 0
	for k, _ := range s.externalHosts {
		hosts[i] = k
		i++
	}
	sort.Strings(hosts)
	return hosts
}

// ExternalLinks returns a sorted list of external Links
func (s *Spider) ExternalLinks() []string {
	links := make([]string, len(s.externalLinks), len(s.externalLinks))
	i := 0
	for k, _ := range s.externalLinks {
		links[i] = k
		i++
	}
	sort.Strings(links)
	return links
}

// Crawl is the exposed method for starting a crawl at baseURL. The crawl private method
// does the actual work. The depth is the maximum depth, or distance, to crawl from the
// baseURL. If depth == -1, no limits are set and it is expected that the entire site
// will be crawled.
func (s *Spider) Crawl(depth int) (message string, err error) {
	s.maxDepth = depth
	S := Site{URL: s.URL}
	// if we are to respect the robots.txt, set up the info
	if s.Config.RespectRobots {
		s.getRobotsTxt()
	}
	s.Queue.Enqueue(Page{URL: s.URL})
	err = s.crawl(S)
	return fmt.Sprintf("%d nodes were processed; %d external links linking to %d external hosts were not processed", len(s.Pages), len(s.externalLinks), len(s.externalHosts)), err
}

// This crawl does all the work.
func (s *Spider) crawl(fetcher Fetcher) error {
	for !s.Queue.IsEmpty() {
		// get next item from queue
		p, ok := s.Queue.Dequeue()
		if !ok {
			return errors.New("crawl dequeue error: expected a page, got none")
		}
		// if a depth value was passed and the distance is > depth, we are done
		// depth of 0 means no limit
		if s.maxDepth != -1 && p.(Page).distance > s.maxDepth {
			return nil
		}
		page := p.(Page)
		// see if this is an external url
		if s.externalURL(page.URL) {
			if s.Config.CheckExternalLinks {
				s.fetchExternalLink(page.URL)
			}
			continue
		}
		// check to see if this url should be skipped for other reasons
		if s.skip(page.URL) {
			// see if the skipped is external and process accordingly
			continue
		}
		s.foundURLs[page.URL.String()] = struct{}{}
		// get the url
		r := ResponseInfo{}
		page.body, r, page.links = fetcher.Fetch(page.URL.String())
		// add the page and status to the map. map isn't checked for membership becuase we don't
		// fetch found urls.
		s.Lock()
		s.Pages[page.URL.String()] = page
		s.fetchedURLs[page.URL.String()] = r
		s.Unlock()
		// add the urls that the node contains to the queue
		for _, l := range page.links {
			u, _ := url.Parse(l)
			s.Queue.Enqueue(Page{URL: u, distance: page.distance + 1})
		}
		// if there is a wait between fetches, sleep for that + random jitter
		if s.Config.FetchInterval > 0 {
			wait := s.Config.FetchInterval
			// if there is a value for jitter, add a random jitter
			if s.Config.Jitter > 0 {
				n := s.Config.Jitter.Nanoseconds()
				n = rand.Int63n(n)
				wait += time.Duration(n) * time.Nanosecond
			}
			time.Sleep(wait)
		}
	}
	return nil
}

// skip determines whether the url should be skipped.
//   * skip urls that have already been fetched
//   * skip urls that are outside of the basePath
//   * conditionally skip urls that are outside of the current scheme, even if
//     they are within the current pasePath
//   * skip if not allowed by robots
func (s *Spider) skip(u *url.URL) bool {
	s.Lock()
	_, ok := s.foundURLs[u.String()]
	s.Unlock()
	if ok { // if it was found, skip it
		s.addSkippedURL(u)
		return true
	}

	// skip if we are restricted to current scheme
	if s.Config.RestrictToScheme {
		if u.Scheme != s.URL.Scheme {
			s.addSkippedURL(u)
			return true
		}
	}
	if s.Config.RespectRobots {
		ok := s.robotsAllowed(u)
		if !ok {
			return false
		}
	}
	// skip if the url is outside of base
	// remove the scheme + schemePrefix so just the rest of the url is being compared
	if !strings.HasPrefix(u.Path, s.URL.Path) {
		s.addSkippedURL(u)
		return true
	}
	return false
}

// addSkippedURL add's the url info too the skipped info
func (s *Spider) addSkippedURL(u *url.URL) {
	s.Lock()
	s.skippedURLs[u.Path] = struct{}{}
	s.Unlock()
}

// externalURL check's to see if the url is external to the site, host isn't the same.
// and add's that info to the ext structs.
func (s *Spider) externalURL(u *url.URL) bool {
	if u.Host != s.URL.Host {
		s.Lock()
		// see if the host is already in the map
		_, ok := s.externalHosts[u.Host]
		if !ok {
			s.externalHosts[u.Host] = struct{}{}
		}
		// same with url
		_, ok = s.externalLinks[u.String()]
		if !ok {
			s.externalLinks[u.String()] = ResponseInfo{}
		}
		s.Unlock()
		return true
	}
	return false
}

// fetchExternalLink: fetches an external link's HEAD and check's it status. Note, this
// does not implement fetcher
func (s *Spider) fetchExternalLink(u *url.URL) error {
	// if this has already benn fetched, don't
	var ri ResponseInfo
	s.Lock()
	r, _ := s.externalLinks[u.String()]
	s.Unlock()
	if r != ri { // if !0 value, it's been retrieved
		return nil
	}
	resp, err := http.Head(u.String())
	if err != nil {
		r.Err = err
		s.Lock()
		s.externalLinks[u.String()] = r
		s.Unlock()
		return err
	}
	r.Status = resp.Status
	r.StatusCode = resp.StatusCode
	s.Lock()
	s.externalLinks[u.String()] = r
	s.Unlock()
	return nil
}

// getRobotsTxt retrieves and processes the site's robot.txt. If the robots.txt doesn't
// exist, it is assumed that everything is allowed.
func (s *Spider) getRobotsTxt() error {
	resp, err := http.Get("http://" + s.URL.Host)
	if err != nil {
		return err
	}
	robots, err := robotstxt.FromResponse(resp)
	if err != nil {
		return err
	}
	s.robots = robots.FindGroup(s.Config.RobotUserAgent)
	return nil
}

// robotsAllowed checks to see if the passed path is allowed by Robots.txt. If the
// robots isn't set, it's always true
func (s *Spider) robotsAllowed(u *url.URL) bool {
	if s.robots != nil {
		return s.robots.Test(u.Path)
	}
	return true
}

// getTokens returns all tokens in the body
func getTokens(body io.Reader) []html.Token {
	tokens := make([]html.Token, 0)
	page := html.NewTokenizer(body)
	for {
		typ := page.Next()
		if typ == html.ErrorToken {
			return tokens
		}
		tokens = append(tokens, page.Token())
	}
}

func init() {
	// We just use math/rand because it's good enough for our purpose.
	rand.Seed(time.Now().UTC().UnixNano())
}


text:
{% extends "base.html" %}

{% block content %}

        <form class="form" action="" method="POST" id="payment-form">
        {% csrf_token %}

              Card Number
              <input class="form-control" type="text" size="20" data-stripe="number"/>

              CVC
              <input type="text" size="4" data-stripe="cvc" style="color:black;" />

              Expiration (MM/YYYY)
              <input type="text" size="2" data-stripe="exp-month" style="color:black;"/>

             /
            <input type="text" size="4" data-stripe="exp-year" style="color:black;"/>

          <button class="btn btn-success" type="submit">Submit Payment</button>
        </form>

{% endblock %}


text:
<?php
namespace Hz\Cache;

class Base extends \Hz\Base\Object
{

}


text:
package fr.opensagres.xdocreport.webapp.defaultreport;

import fr.opensagres.xdocreport.core.document.DocumentKind;
import fr.opensagres.xdocreport.template.TemplateEngineKind;
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
import fr.opensagres.xdocreport.webapp.datamodel.MetaDataModel;

public class ODTStructures
    extends DefaultReportController
{

    public ODTStructures()
    {
        super( "ODTStructures.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
    }

    @Override
    protected MetaDataModel createMetaDataModel()
    {
        MetaDataModel model = new MetaDataModel();
        model.addSimpleField( "project.name", "XDocReport" );
        return model;
    }

    @Override
    protected FieldsMetadata createFieldsMetadata()
    {
        return FieldsMetadata.EMPTY;
    }
}


text:
The :mod:`nova..objectstore.handler` Module
==============================================================================
.. automodule:: nova..objectstore.handler
  :members:
  :undoc-members:
  :show-inheritance:


text:
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using JiiLib.Components.Dynamic.Extensions;
using JiiLib.Components.Dynamic.Rendering;

namespace JiiLib.Components.Dynamic
{
    public sealed partial class DynamicElement : ComponentBase
    {
#nullable disable warnings
        [Inject] public IRendererFactory Factory { private get; set; }
#nullable enable

        [Parameter] public string? Contents { private get; set; }

        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (Contents is null)
                return;

            var root = new Node(null, "Hello world!");
            var facade = new BuilderFacade(builder, Factory);
            var renderer = Factory.GetRendererForTag(root.Tag);
            renderer.BuildRenderTree(facade, root);
        }
    }
}