Skip to content

Instantly share code, notes, and snippets.

@chrisgeo
Created September 25, 2010 22:44
Show Gist options
  • Save chrisgeo/597376 to your computer and use it in GitHub Desktop.
Save chrisgeo/597376 to your computer and use it in GitHub Desktop.
import httplib2
import json
from webob import Response
import logging
import pprint
log = logging.getLogger(__name__)
pp = pprint.PrettyPrinter()
class RequestLoader(object):
"""ComboLoader Object
Creates a combo loader object
"""
def __call__(self, request, config, files):
self.request = request
self.config = config
self.files = files
log.debug(files)
return config['request_type'](request, **kwargs)
class HttpRequest(RequestLoader):
pass
class FileRequest(RequestLoader):
"""FileRequest loads files with a base and path
Concatenates the files given in a list
"""
def __init__(self, request, config, files):
self.files = files
self.config = config
self.request = request
self._combine()
def _combine(self):
content = ""
log.debug(pprint.pformat(self.files))
import pdb; pdb.set_trace()
for ft, items in self.files.items():
for item in items:
try:
log.debug("File Type: %s :::: File Path: %s" % (ft, item))
f = open("%s/%s" % (self._get_file_path(ft), item), 'r')
content += f.read()
f.close()
except IOError as e:
log.error("File not found: %s ::: Continuing..." % e)
pp.pprint(content)
return Response(body=content)
def _get_file_path(self, file_type):
if file_type.lower() == 'js':
return self.config['js_path']
elif file_type.lower() == 'css':
return self.config['css_path']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment