Esempio n. 1
0
 def serve_static(self, request):
   path = request.path[1:]
   if os.path.exists(path) and os.path.isfile(path):
     return Response(body=open(path,'rb').read(),content_type=mimetypes.guess_type(path)[0])
   elif os.path.exists(path + 'index.html'):
     return Response(body=open(path+'index.html','rb').read(),content_type='text/html')
   elif os.path.exists(path) and os.path.isdir(path):
     return Response(body='\n'.join(os.listdir(path)),content_type='text/plain')
   elif settings._404: return settings._404(request)
   else:
     return Response(body='404 Not Found',content_type='text/plain',status_code=404)
Esempio n. 2
0
 def serve_dynamic(self, request):
   view,args,kwargs = resolve(request,self.urls)
   if view: response = view(request,*args,**kwargs)
   elif settings._404: response = settings._404(request)
   else: response = Response(body='404 Not Found',content_type='text/plain',status_code=404)
   return response