vendor/tramline

changeset 14:60db9e957c02 gracinet-progress-bar

Adapted for gp.fileupload compatibility
author gracinet
date Sun, 01 Mar 2009 18:39:12 +0000
parents 57410de1cafa
children 25bd7198a978
files src/tramline/core.py src/tramline/progress.py
diffstat 2 files changed, 14 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/src/tramline/core.py
     1.2 +++ b/src/tramline/core.py
     1.3 @@ -1,4 +1,6 @@
     1.4  import os, tempfile, random, sys, errno, mimetools
     1.5 +import cgi
     1.6 +from mod_python import apache
     1.7  
     1.8  OPTION_ALLOW_GROUP_WRITE = 'allow_group_write'
     1.9  TRAMLINE_RANGE_HEADER = 'X-Tramline-Original-Range'
    1.10 @@ -371,6 +373,12 @@
    1.11      def initFromInputFilter(self, filter):
    1.12          headers = filter.req.headers_in
    1.13          self.upload_length = long(headers['Content-Length'])
    1.14 +	qs = filter.req.parsed_uri[apache.URI_QUERY]
    1.15 +	if qs is not None:
    1.16 +           gu_ids = cgi.parse_qs(qs).get('gp.fileupload.id')
    1.17 +           if gu_ids is not None:
    1.18 +              # parse_qs always produces lists
    1.19 +              self.progress_id = filter.req.connection.remote_ip + '-' + gu_ids[0]
    1.20  
    1.21      def pushInput(self, data, out):
    1.22          lines = data.splitlines(True)
     2.1 --- a/src/tramline/progress.py
     2.2 +++ b/src/tramline/progress.py
     2.3 @@ -2,11 +2,11 @@
     2.4  from tramline.core import get_progress
     2.5  
     2.6  def handler(req):
     2.7 -    progress_id = req.uri.rsplit('/', 1)[-1]
     2.8 -    uploaded = get_progress(req, progress_id)
     2.9 -    if uploaded is None:
    2.10 -        req.status = apache.HTTP_NOT_FOUND
    2.11 -    else:
    2.12 -        req.write(str(uploaded))
    2.13 +    progress_id = req.connection.remote_ip + '-' + req.uri.rsplit('/', 1)[-1]
    2.14 +    progress = get_progress(req, progress_id)
    2.15 +
    2.16      req.content_type = "text/plain"
    2.17 +    req.headers_out['Content-length'] = str(len(progress))
    2.18 +    req.write(progress)
    2.19 +
    2.20      return apache.OK