Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8918c97d0e
Fetching contributors…

Cannot retrieve contributors at this time

file 78 lines (57 sloc) 2.07 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#!/usr/bin/env python
"""Serves the front page.
"""

__author__ = 'Ryan Barrett <codeherenow@ryanb.org>'

import logging
import os
import urlparse
import webapp2

import appengine_config

from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template


class TemplateHandler(webapp2.RequestHandler):
  """Renders and serves a template based on class attributes.

Subclasses must override at least template_file.

Attributes:
template_vars: dict

Class attributes:
content_type: string
template: path to template file
"""
  content_type = 'text/html'
  template_file = None

  def __init__(self, *args, **kwargs):
    self.template_vars = dict(BASE_TEMPLATE_VARS)
    super(TemplateHandler, self).__init__(*args, **kwargs)

  def get(self):
    self.response.headers['Content-Type'] = self.content_type
    # can't update() because wsgiref.headers.Headers doesn't have it.
    for key, val in BASE_HEADERS.items():
      self.response.headers[key] = val
    self.template_vars.update(self.request.params)
    self.response.out.write(template.render(self.template_file,
                                            self.template_vars))


class FrontPageHandler(TemplateHandler):
  """Renders and serves /, ie the front page.
"""
  template_file = codeherenow.SOURCE.FRONT_PAGE_TEMPLATE


class HostMetaXrdHandler(TemplateHandler):
  """Renders and serves the /.well-known/host-meta XRD file.
"""
  content_type = 'application/xrd+xml'
  template_file = 'templates/host-meta.xrd'


class HostMetaXrdsHandler(TemplateHandler):
  """Renders and serves the /.well-known/host-meta.xrds XRDS-Simple file.
"""
  content_type = 'application/xrds+xml'
  template_file = 'templates/host-meta.xrds'


def main():
  application = webapp2.WSGIApplication(
      [('/', FrontPageHandler),
       ('/.well-known/host-meta', HostMetaXrdHandler),
       ('/.well-known/host-meta.xrds', HostMetaXrdsHandler),
       ],
      debug=appengine_config.DEBUG)
  run_wsgi_app(application)


if __name__ == '__main__':
  main()
Something went wrong with that request. Please try again.