python-hserver/hserver/api/FileObject.py

37 lines
823 B
Python
Raw Normal View History

2018-03-09 11:50:31 +01:00
from hserver.api import WebObject
from objectbroker 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):
2018-03-29 13:13:56 +02:00
def __init__(self, path, readOnly = False):
self.__path = path
self.__readOnly = readOnly
self.__files = {}
2018-03-09 11:50:31 +01:00
def __dir__(self):
2018-03-29 13:13:56 +02:00
return os.listdir( self.__path )
2018-03-09 11:50:31 +01:00