Commits

Anonymous committed 1a5096b

Fix disable flag into a require_session.

Comments (0)

Files changed (3)

gp/fileupload/storage.py

     """
 
     def __init__(self, application, upload_to, tempdir=None,
-                 exclude_paths=None, max_size=0):
+                 exclude_paths=None, max_size=0, require_session=False):
         self.application = application
 
         if not os.path.isdir(upload_to):
             self.exclude_paths = None
 
         self.max_size = max_size
+        self.require_session = require_session
 
     def __call__(self, environ, start_response):
         req = Request(environ)
             return resp(environ, start_response)
 
         elif req.method == 'POST':
-            return self.store(req)(environ, start_response)
+            if (not self.require_session or
+                SESSION_NAME in environ.get('QUERY_STRING', '')):
+                return self.store(req)(environ, start_response)
 
         return self.application(environ, start_response)
 

gp/fileupload/upload.py

     """
 
     def __init__(self, application, tempdir=TEMP_DIR,
-                 max_size=None, disable_gpupload=False):
+                 max_size=None, require_session=False):
         self.application = application
         if not tempdir:
             self.tempdir = TEMP_DIR
         if max_size:
             log.info('Max upload size: %s' % max_size)
 
-        self.disable_gpupload = disable_gpupload
+        self.require_session = require_session
 
     def __call__(self, environ, start_response):
         req = Request(environ)
                     path = os.path.join(STATIC_DIR, filename)
                     return FileApp(path)(environ, start_response)
 
-        elif environ['REQUEST_METHOD'] == 'POST' and \
-             SESSION_NAME in environ.get('QUERY_STRING', '') and \
-             not self.disable_gpupload:
-            return self.upload(req)(environ, start_response)
+        elif environ['REQUEST_METHOD'] == 'POST':
+            if (not self.require_session or
+                SESSION_NAME in environ.get('QUERY_STRING', '')):
+                return self.upload(req)(environ, start_response)
 
         return self.application(environ, start_response)
 
     def tempfiles(self, session, environ):
-        filename = environ.get('REMOTE_USER','') + session
         return (os.path.join(self.tempdir, session+'.size'),
                os.path.join(self.tempdir, session+'.stats'))
 
             return exc.HTTPServerError('File is too big')
 
         log.debug('Start session "%s", length: %s', session, length)
-
         sfile = open(statfile, 'w')
         sfile.write(str(length))
         sfile.close()
         return resp
 
     def status(self, req):
-        if self.disable_gpupload:
-            data = json.dumps({'state': 2 })
-            resp = Response()
-            resp.content_type = 'application/json'
-            if 'callback' in req.GET:
-                resp.body = req.GET['callback'] + '(' + data + ')'
-            else:
-                resp.body = data
-            return resp
-
         session = req.path_info.split('/')[-1]
 
         if not session.isdigit():
 
 def make_app(application, global_conf, tempdir=None, max_size=0,
              upload_to=None, exclude_paths=None, include_files=None,
-             disable_gpupload=False):
+             require_session=False):
     """build a FileUpload application
     """
 
         # use Mo
         max_size = int(max_size)*1024*1024
 
+    if require_session in ['true', 'True']:
+        require_session = True
+    else:
+        require_session = False
+
     if upload_to:
         if exclude_paths is None:
             exclude_paths = []
         else:
             if isinstance(exclude_paths, basestring):
                 exclude_paths = [f for f in exclude_paths.split(' ') if f]
-        application = Storage(application, upload_to, tempdir, exclude_paths,
-                              max_size)
+        application = Storage(
+            application, upload_to, tempdir, exclude_paths,
+            max_size=max_size, require_session=require_session)
 
     if include_files:
         if isinstance(include_files, basestring):
             include_files = [f for f in include_files.split(' ') if f]
         application = ResourceInjection(application, include_files)
 
-    disable_gpupload = disable_gpupload in ['true', 'True', True]
-
-    return FileUpload(application, tempdir=tempdir,
-                      max_size=max_size, disable_gpupload=disable_gpupload)
+    return FileUpload(
+        application, tempdir=tempdir,
+        max_size=max_size, require_session=require_session)
 tempdir= %(here)s/tmp/
 #upload_to = %(here)s/share/
 include_files = fileupload.css jquery.fileupload.*
-disable_gpupload = false
+require_session = false
+
 
 [server:main]
 use= egg:PasteScript#cherrypy