<commit_before>from fileutils import EXTENSIONS, Path, UnsafePath, OutOfRootException, PathDoesntExistsException
import fileutils
import encode

from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseRedirect, StreamingHttpResponse
from django.shortcuts import render, redirect

from operator import itemgetter
import os
import sys

def index(request):
   return HttpResponse("TODO(eriq): index.")

def home(request):
   return HttpResponse("TODO(eriq): home.")

# TODO(eriq): Error handle this.
def fetch_encode(request, urlpath):
   # HACK(eriq): Don't use unsafe path.
   #  It is safe, just not rooted in the media dir.

   path = UnsafePath.from_urlpath(urlpath)

   ext = path.ext()

   if not ext in EXTENSIONS:
      raise Http404

   mime = EXTENSIONS[ext]['mime']

   if not mime:
      raise Http404

   address = "{}/{}".format(settings.CACHE_SERVE_BASE, urlpath)<commit_msg>Redirect for index and home.<commit_after>from fileutils import EXTENSIONS, Path, UnsafePath, OutOfRootException, PathDoesntExistsException
import fileutils
import encode

from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseRedirect, StreamingHttpResponse
from django.shortcuts import render, redirect

from operator import itemgetter
import os
import sys

# TODO(eriq): ?
def index(request):
   return HttpResponseRedirect(reverse('browse'))

# TODO(eriq): Playlists and what-ot.
def home(request):
   return HttpResponseRedirect(reverse('browse'))

# TODO(eriq): Error handle this.
def fetch_encode(request, urlpath):
   # HACK(eriq): Don't use unsafe path.
   #  It is safe, just not rooted in the media dir.

   path = UnsafePath.from_urlpath(urlpath)

   ext = path.ext()

   if not ext in EXTENSIONS:
      raise Http404

   mime = EXTENSIONS[ext]['mime']

   if not mime:
      raise Http404

   address = "{}/{}".format(settings.CACHE_SERVE_BASE, urlpath)
{'fraction_non_alphanumeric': 0.08761186999528968, 'fraction_numerical': 0.008478568064060292, 'mean_word_length': 4.867403314917127, 'pattern_counts': {'":': 0, '<': 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': '4031031', 'n_tokens_mistral': 665, 'n_tokens_neox': 623, 'n_words': 200}