Source code for wsgidav.samples.dav_provider_tools
# (c) 2009-2024 Martin Wendt and contributors; see WsgiDAV https://github.com/mar10/wsgidav# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php"""Tools that make it easier to implement custom WsgiDAV providers."""importosimportstatfromwsgidavimportutilfromwsgidav.dav_providerimportDAVCollection,DAVNonCollection__docformat__="reStructuredText en"_logger=util.get_module_logger(__name__)# ============================================================================# VirtualCollection# ============================================================================
[docs]classVirtualCollection(DAVCollection):"""Abstract base class for collections that contain a list of static members. Member names are passed to the constructor. get_member() is implemented by calling self.provider.get_resource_inst() """def__init__(self,path,environ,display_info,member_name_list):super().__init__(path,environ)ifutil.is_basestring(display_info):display_info={"type":display_info}asserttype(display_info)isdictasserttype(member_name_list)islistself.display_info=display_infoself.member_name_list=member_name_list
[docs]classFileResource(_VirtualNonCollection):"""Represents an existing file."""BUFFER_SIZE=8192def__init__(self,path,environ,file_path):ifnotos.path.exists(file_path):_logger.error(f"FileResource({file_path!r}) does not exist.")super().__init__(path,environ)self.file_path=file_path
[docs]classDAVResolver:"""Return a DAVResource object for a path (None, if not found)."""def__init__(self,parent_resolver,name):self.parent_resolver=parent_resolverself.name=name