Skip to content

Commit

Permalink
merged Sai changes
Browse files Browse the repository at this point in the history
  • Loading branch information
juvvadi committed May 9, 2011
1 parent 3c53cee commit 38ddbfc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
7 changes: 4 additions & 3 deletions keystone/auth_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import routes
from webob import Response
from webob import Request
from webob import descriptors
from webob.exc import (HTTPNotFound,
HTTPConflict,
HTTPBadRequest)
Expand Down Expand Up @@ -135,18 +136,18 @@ def get_pdf_contract(self, req):
root=get_app_root(),
mimetype="application/pdf")

def get_wadl_contract():
def get_wadl_contract(self, req):
resp = Response()
return template.static_file(resp, req, "identity.wadl",
root=get_app_root(),
mimetype="application/vnd.sun.wadl+xml")
def get_xsd_contract(xsd):
def get_xsd_contract(self, req, xsd):
resp = Response()
return template.static_file(resp, req, "/xsd/" + xsd,
root=get_app_root(),
mimetype="application/xml")

def get_xsd_atom_contract(xsd):
def get_xsd_atom_contract(self, req, xsd):
resp = Response()
return template.static_file(resp, req, "/xsd/atom/" + xsd,
root=get_app_root(),
Expand Down
25 changes: 14 additions & 11 deletions keystone/common/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import os
import functools
import time
from webob import Response
import keystone.logic.types.fault as fault

TEMPLATES = {}
DEBUG = False
TEMPLATE_PATH = ['./', './views/']
Expand Down Expand Up @@ -33,7 +36,7 @@ def __init__(self, source=None, name=None, lookup=[], encoding='utf8', **setting
self.lookup = map(os.path.abspath, lookup)
self.encoding = encoding
self.settings = self.settings.copy() # Copy from class variable
self.settings.update(settings) # Apply
self.settings.update(settings) # Apply
if not self.source and self.name:
self.filename = self.search(self.name, self.lookup)
if not self.filename:
Expand Down Expand Up @@ -227,7 +230,7 @@ def static_file(resp, req, filename, root, guessmime=True, mimetype=None, downlo
"""
root = os.path.abspath(root) + os.sep
filename = os.path.abspath(os.path.join(root, filename.strip('/\\')))
header = dict()
header = {}
if not filename.startswith(root):
#return HTTPError(403, "Access denied.")
return ForbiddenFault("Access denied.")
Expand All @@ -239,30 +242,30 @@ def static_file(resp, req, filename, root, guessmime=True, mimetype=None, downlo
return ForbiddenFault("You do not have permission to access this file.")

if not mimetype and guessmime:
resp.headers['Content-Type'] = mimetypes.guess_type(filename)[0]
resp.content_type = mimetypes.guess_type(filename)[0]
else:
resp.headers['Content-Type'] = mimetype if mimetype else 'text/plain'
resp.content_type = mimetype if mimetype else 'text/plain'

if download == True:
download = os.path.basename(filename)
if download:
resp.headers['Content-Disposition'] = 'attachment; filename="%s"' % download
resp.content_disposition = 'attachment; filename="%s"' % download

stats = os.stat(filename)
lm = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(stats.st_mtime))
resp.headers['Last-Modified'] = lm
resp.last_modified = lm
ims = req.environ.get('HTTP_IF_MODIFIED_SINCE')
if ims:
ims = ims.split(";")[0].strip() # IE sends "<date>; length=146"
ims = parse_date(ims)
if ims is not None and ims >= int(stats.st_mtime):
resp.headers['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
return Response(status=304, header=header)
resp.headers['Content-Length'] = stats.st_size
resp.date = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
return Response(body=None, status=304, headerlist=resp.headerlist)
resp.content_length = stats.st_size
if req.method == 'HEAD':
return resp('', header=header)
return Response(body=None, status=200, headerlist=resp.headerlist)
else:
return resp(open(filename, 'rb'), header=header)
return Response(body=open(filename).read(), status=200, headerlist=resp.headerlist)


def template(tpl, template_adapter=SimpleTemplate, **kwargs):
Expand Down

0 comments on commit 38ddbfc

Please sign in to comment.