paste.progress – Track progress of uploads

Upload Progress Monitor

This is a WSGI middleware component which monitors the status of files being uploaded. It includes a small query application which will return a list of all files being uploaded by particular session/user.

>>> from paste.httpserver import serve
>>> from paste.urlmap import URLMap
>>> from paste.auth.basic import AuthBasicHandler
>>> from paste.debug.debugapp import SlowConsumer, SimpleApplication
>>> # from paste.progress import *
>>> realm = 'Test Realm'
>>> def authfunc(username, password):
...     return username == password
>>> map = URLMap({})
>>> ups = UploadProgressMonitor(map, threshold=1024)
>>> map['/upload'] = SlowConsumer()
>>> map['/simple'] = SimpleApplication()
>>> map['/report'] = UploadProgressReporter(ups)
>>> serve(AuthBasicHandler(ups, realm, authfunc))
serving on...


This is experimental, and will change in the future.

Module Contents

class paste.progress.UploadProgressMonitor(application, threshold=None, timeout=None)

monitors and reports on the status of uploads in progress



This is the next application in the WSGI stack.


This is the size in bytes that is needed for the upload to be included in the monitor.


This is the amount of time (in seconds) that a upload remains in the monitor after it has finished.



This returns a list of environ dict objects for each upload being currently monitored, or finished but whose time has not yet expired.

For each request environ that is monitored, there are several variables that are stored:


This is the total number of bytes received for the given request; it can be compared with CONTENT_LENGTH to build a percentage complete. This is an integer value.


This is the time (in seconds) when the request was started as obtained from time.time(). One would want to format this for presentation to the user, if necessary.


This is the time (in seconds) when the request was finished, canceled, or otherwise disconnected. This is None while the given upload is still in-progress.
TODO: turn monitor into a queue and purge queue of finished
requests that have passed the timeout period.
class paste.progress.UploadProgressReporter(monitor)

reports on the progress of uploads for a given user

This reporter returns a JSON file (for use in AJAX) listing the uploads in progress for the given user. By default, this reporter uses the REMOTE_USER environment to compare between the current request and uploads in-progress. If they match, then a response record is formed.


This member function can be overriden to provide alternative matching criteria. It takes two environments, the first is the current request, the second is a current upload.


This member function takes an environment and builds a dict that will be used to create a JSON mapping for the given upload. By default, this just includes the percent complete and the request url.