<commit_before>#!/usr/bin/python
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import cgi
import logging
import re

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import memcache
from google.appengine.api import urlfetch

# TODO(nickbaum): unit tests


# TODO(nickbaum): is this the right way to do constants?
class Channel():
  def __init__(self, name, tag):
    self.name = name
    self.tag = tag
    
  # TODO(nickbaum): unit test this
  def matchPath(self, path):
    match = "/" + self.name + "/"
    if path[0:len(match)] == match:
      return true
    else:
      return false
    
Channel.DEV = Channel("dev", "2.0-dev")
Channel.BETA = Channel("beta", "1.1-beta")
Channel.STABLE = Channel("stable", "")
Channel.CHANNELS = [Channel.DEV, Channel.BETA, Channel.STABLE]
Channel.TRUNK = Channel("trunk", "")
Channel.DEFAULT = Channel.STABLE


DEFAULT_CACHE_TIME = 300


class MainPage(webapp.RequestHandler):
  # get page from memcache, or else fetch it from src
  def get(self):
    path = self.request.path
    # special path to invoke the unit tests
    # TODO(nickbaum): is there a less ghetto way to invoke the unit test?
    if path == "/test/":
      self.unitTest()
      return
    # if root, redirect to index.html
    # TODO(nickbaum): this doesn't handle /chrome/extensions/trunk, etc
    if (path == "/chrome/extensions") or (path == "chrome/extensions/"):
      self.redirect("/chrome/extensions/index.html")
      return
    # else remove prefix
    if(path[:18] == "/chrome/extensions"):
      path = path[18:]
    # TODO(nickbaum): there's a subtle bug here: if there are two instances of the app,
    # their default caches will override each other. This is bad!
    result = memcache.get(path)
    if result is None:
      logging.info("Cache miss: " + path)
      url = self.getSrcUrl(path)
      if (url[1] is not Channel.TRUNK) and (url[0] != "http://src.chromium.org/favicon.ico"):
        branch = self.getBranch(url[1])
        url = url[0] % branch
      else:
        url = url[0]<commit_msg>Resolve relative paths to a hypothetical root before fetching docs from source control.<commit_after>#!/usr/bin/python
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import cgi
import logging
import re
import os

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import memcache
from google.appengine.api import urlfetch

# TODO(nickbaum): unit tests


# TODO(nickbaum): is this the right way to do constants?
class Channel():
  def __init__(self, name, tag):
    self.name = name
    self.tag = tag
    
  # TODO(nickbaum): unit test this
  def matchPath(self, path):
    match = "/" + self.name + "/"
    if path[0:len(match)] == match:
      return true
    else:
      return false
    
Channel.DEV = Channel("dev", "2.0-dev")
Channel.BETA = Channel("beta", "1.1-beta")
Channel.STABLE = Channel("stable", "")
Channel.CHANNELS = [Channel.DEV, Channel.BETA, Channel.STABLE]
Channel.TRUNK = Channel("trunk", "")
Channel.DEFAULT = Channel.STABLE


DEFAULT_CACHE_TIME = 300


class MainPage(webapp.RequestHandler):
  # get page from memcache, or else fetch it from src
  def get(self):
    path = os.path.realpath(os.path.join('/', self.request.path))
    # special path to invoke the unit tests
    # TODO(nickbaum): is there a less ghetto way to invoke the unit test?
    if path == "/test":
      self.unitTest()
      return
    # if root, redirect to index.html
    # TODO(nickbaum): this doesn't handle /chrome/extensions/trunk, etc
    if (path == "/chrome/extensions") or (path == "chrome/extensions/"):
      self.redirect("/chrome/extensions/index.html")
      return
    # else remove prefix
    if(path[:18] == "/chrome/extensions"):
      path = path[18:]
    # TODO(nickbaum): there's a subtle bug here: if there are two instances of the app,
    # their default caches will override each other. This is bad!
    result = memcache.get(path)
    if result is None:
      logging.info("Cache miss: " + path)
      url = self.getSrcUrl(path)
      if (url[1] is not Channel.TRUNK) and (url[0] != "http://src.chromium.org/favicon.ico"):
        branch = self.getBranch(url[1])
        url = url[0] % branch
      else:
        url = url[0]
{'fraction_non_alphanumeric': 0.12182296231375986, 'fraction_numerical': 0.009202453987730062, 'mean_word_length': 3.222941720629047, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4625363', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1412, 'n_words': 464}