예제 #1
0
    def __call__(self,environ,start_response,path):
        if len(path)==0:
            content_length=int(environ['CONTENT_LENGTH'])
            if content_length<0 or content_length>MAX_LENGTH:
                LOG.error('Content-Length, %d,  out of bounds (%d)',content_length,MAX_LENGTH)
                return response.respond_not_found(start_response)

            serialization_file=os.path.join(configuration['serialization_dir'],randomWord())
            count=0
            while os.path.exists(serialization_file) and count<MAX_TRIES:
                LOG.warning('Serialization file "%s" exists, this is unexpected.  Trying again',serialization_file)
                serialization_file=os.path.join(configuration['serialization_dir'],randomWord())
                count+=1
            if count==MAX_TRIES:
                LOG.error('Unable to create new serialization file after %d attempts. Giving up',count) 
                return response.respond_not_found(start_response)
            
            with open(serialization_file,'w') as f:
                f.write(environ['wsgi.input'].read(content_length))
            return response.respond_ok(os.path.basename(serialization_file),start_response)
        elif path[0][0:1]=='_':
            try:
                f=getattr(self,path[0])
                return f(environ,start_response,path[1:])
            except AttributeError:
                return response.respond_not_found(start_response)
        else:
            serialization_file=os.path.join(configuration['serialization_dir'],*path)
            if os.path.exists(serialization_file):
                return response.respond_file(serialization_file,environ,start_response)
            else:
                return response.respond_not_found(start_response)
예제 #2
0
 def _colorbar(self, environ, start_response, path):
     renderer = Renderer(os.path.splitext(path[0])[0])
     array = COLORBAR_ARRAY
     if renderer.cmap._rgba_under and renderer.cmap._rgba_over:
         array = COLORBAR_ARRAY_UNDER_OVER
     elif renderer.cmap._rgba_under:
         array = COLORBAR_ARRAY_UNDER
     elif renderer.cmap._rgba_over:
         array = COLORBAR_ARRAY_OVER
     image_dir = os.path.join(configuration['frame_dir'], '_colorbar')
     if not os.path.exists(image_dir): os.makedirs(image_dir)
     image_file = os.path.join(image_dir, path[0])
     renderer.write(array, image_file)
     return response.respond_file(image_file, environ, start_response)
예제 #3
0
 def _colorbar(self,environ,start_response,path):
     renderer=Renderer(os.path.splitext(path[0])[0])
     array=COLORBAR_ARRAY
     if renderer.cmap._rgba_under and renderer.cmap._rgba_over:
         array=COLORBAR_ARRAY_UNDER_OVER
     elif renderer.cmap._rgba_under:
         array=COLORBAR_ARRAY_UNDER
     elif renderer.cmap._rgba_over:
         array=COLORBAR_ARRAY_OVER
     image_dir=os.path.join(configuration['frame_dir'],'_colorbar')
     if not os.path.exists(image_dir): os.makedirs(image_dir)
     image_file=os.path.join(image_dir,path[0])
     renderer.write(array,image_file)
     return response.respond_file(image_file,environ,start_response)
예제 #4
0
 def __call__(self,environ,start_response,path):
     LOG.debug("Checking path: %s",path)
     # Handle special calls to methods that start with '_'
     if len(path)>0 and path[0][0:1]=='_':
         try:
             f=getattr(self,path[0])
             return f(environ,start_response,path[1:])
         except AttributeError:
             return response.respond_not_found(start_response)
     else:
         result=self.call(path[:])
         if hasattr(result,'read'): 
             return response.respond_file(result,environ,start_response)
         elif result==None:
             return response.respond_not_found(start_response)
         else:
             return response.respond_ok(result,start_response)
예제 #5
0
 def _resources(self,environ,start_response,path):
     LOG.debug('Getting resource: %s',os.path.join('roesources',*path))
     stream=None
     try:
         resource=os.path.join('resources',*path)
         LOG.debug('Attempting %s,%s',self.__module__,resource)
         stream=resource_stream(self.__module__,resource)
     except IOError:
         resource=os.path.join('resources',*path)
         LOG.debug('Attempting %s,%s','wallander',resource)
         try:
             stream=resource_stream('wallander',resource)
         except IOError:
             if path[0]=='icons':
                 stream=resource_stream('wallander','resources/icons/unknown.svg')
     if stream:
         return response.respond_file(stream,environ,start_response)
     else:
         return response.respond_not_found(start_response)
예제 #6
0
 def __call__(self,environ,start_response,path):
     LOG.debug("path: %s",str(path))
     file=os.path.realpath(os.path.join(self.html_dir,*path))
     LOG.debug("file: '%s'",file)
     if not os.path.exists(file):
         response.respond_not_found(start_response)
     if os.path.isdir(file):
         ndx_file=None
         for f in self.index_files:
             f=os.path.join(file,f)
             if os.path.exists(f):
                 ndx_file=f
                 break
         if ndx_file==None:
             basename=os.path.basename(file)
             ndx_file=cStringIO()
             ndx_file.write("<html><head><title>%s</title></head><body><h1>%s</h1>\n"%(basename,basename))
             for f in os.listdir(file):
                 ndx_file.write('<a href="%s">%s</a></br>\n'%(f,f))
             ndx_file.write("</body></html>")
         file=ndx_file
     return response.respond_file(file,environ,start_response)