hserver-fahrradboerse/hServer/hserver/api/fileobject.py

33 lines
741 B
Python

from hserver.api import WebObject
from hwo import Persistence,NoPersistence
import os
class FileObject(WebObject):
def __init__(self,file=None,path=None,contenttype="application/octet-stream"):
self._file = file
self._path = path
self._content = None
self._contenttype = contenttype
def __call__(self,request,o=None):
if self._content is None:
if self._file is None:
self._file = open( self._path, "rb" )
self._content = self._file.read()
request.setResponseHeader("Content-Type",self._contenttype)
request.getBinaryContentFile().write(self._content)
class DiskFolder(WebObject,Persistence):
def __init__(self,path):
self._path = path
def __dir__(self):
return os.listdir( self._path)