[infrae.fileupload][Sylvain Viollon] Add a nice not found if the...

[email protected]
Newsgroups gmane.comp.web.zope.silva.cvs
Message-ID <[email protected]>
author:    Sylvain Viollon
date:      Fri Aug 09 11:20:59 2013 +0200
revision:  10:7e8f506893f3 in infrae.fileupload
branch:    
details:   https://hg.infrae.com/infrae.fileupload?cmd=changeset;node=7e8f506893f3
modified:  src/infrae/fileupload/standalone.py
added:     
removed:   
log:       Add a nice not found if the service isn't properly used.


diffstat:

 src/infrae/fileupload/standalone.py |  19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diffs (34 lines):

diff -r 0dedcffda04d -r 7e8f506893f3 src/infrae/fileupload/standalone.py
--- a/src/infrae/fileupload/standalone.py	Thu Aug 08 18:14:41 2013 +0200
+++ b/src/infrae/fileupload/standalone.py	Fri Aug 09 11:20:59 2013 +0200
@@ -1,5 +1,5 @@
 
-from webob import Response
+from webob import Response, exc
 from infrae.fileupload.middleware import make_filter
 import json
 
@@ -7,13 +7,16 @@
 class StandaloneUpload(object):
 
     def __call__(self, environ, start_response):
-        status = environ['infrae.fileupload.current'].get_status()
-        application = Response()
-        application.body = """
-            <html>
-                <body data-upload-identifier="%s" data-upload-info="%s">
-                </body>
-            </html>
+        if 'infrae.fileupload.current' not in environ:
+            application = exc.HTTPNotFound('Not uploading anything.')
+        else:
+            status = environ['infrae.fileupload.current'].get_status()
+            application = Response()
+            application.body = """
+    <html>
+        <body data-upload-identifier="%s" data-upload-info="%s">
+        </body>
+    </html>
         """ % (str(status['identifier']), json.dumps(status).replace('"', '\\"'))
         return application(environ, start_response)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.