[Grok-dev] Middleware and Grok

bribon alvreinoso at gmail.com
Tue Apr 27 11:55:18 EDT 2010


I'm trying to add a middleware application to create a progress bar when a
file is updating to the server. I've read some tutorial how to make it, but
I haven't got it yet. I'm using paste and gp.fileupload module. This my

This is the middleware application, FileUpload:

from gp.fileupload import make_app
import os

class FileUploadMedia(object):
	"""Wrap a `paste.urlparser.StaticURLParser` to consume stdin if needed"""
	def __init__(self, application):
		self.application = application

	def __call__(self, environ, start_response):
		if environ['REQUEST_METHOD'] == 'POST':
			if 'gp.fileupload.id' in environ['QUERY_STRING']:
				# need to consume so see how many block we have to read
				bsize = 1024
				length = int(environ['CONTENT_LENGTH'])
				print 'upload', length
				blocks = [bsize for i in range(bsize, length, bsize)]

				# read input an write to /dev/null :)
				rfile = environ['form.input']
				[rfile.read(size) for size in blocks]
			# StaticURLParser only deserve GET
			environ['REQUEST_METHOD'] = 'GET'

		return self.application(environ, start_response)

def make_demo(app, global_conf, **local_conf):
	upload_app = make_app(FileUploadMedia(app), {},
		         max_size= None,
		         tempdir=os.path.join('/tmp', 'fileupload'))

	def application(environ, start_response):
	   if '/gp.fileupload/demo.html' in environ['PATH_INFO']:
		  return upload_app(environ, start_response)
	   elif '/gp.fileupload.' in environ['PATH_INFO']:
		  return upload_app(environ, start_response)
		  return app(environ, start_response)
	return application

This is the code at debug.ini:

use = egg:grokserver
filter-with = translogger
paste.app_factory = zope.paste.application:zope_publisher_app_factory

pipeline = fileupload main

paste.filter_factory = FileUploadMedia:make_demo
#use = egg:gp.fileupload
tempdir = %(here)s/data/fileupload

I have some questions:

Where do I have to store the application in the grok server?
How can I get the middleware application running?
Do I need to create a egg?

It would be great if someone could help me out because I got stuck with



View this message in context: http://old.nabble.com/Middleware-and-Grok-tp28378758p28378758.html
Sent from the Grok mailing list archive at Nabble.com.

More information about the Grok-dev mailing list