How to use the wsgidav.dav_provider.DAVCollection function in WsgiDAV

To help you get started, we’ve selected a few WsgiDAV examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mar10 / wsgidav / wsgidav / samples / mongo_dav_provider.py View on Github external
def __init__(self, path, environ):
        DAVCollection.__init__(self, path, environ)
        self.conn = self.provider.conn
        self.db = self.conn[self.name]
github mar10 / wsgidav / wsgidav / samples / virtual_dav_provider.py View on Github external
data["title"] for data in _get_res_list_by_attr(self.catType, self.name)
        ]
        names.sort()
        return names

    def get_member(self, name):
        for data in _get_res_list_by_attr(self.catType, self.name):
            if data["title"] == name:
                return VirtualResource(join_uri(self.path, name), self.environ, data)
        return None


# ============================================================================
# VirtualResource
# ============================================================================
class VirtualResource(DAVCollection):
    """A virtual 'resource', displayed as a collection of artifacts and files."""

    _artifactNames = (
        ".Info.txt",
        ".Info.html",
        ".Description.txt",
        # ".Admin.html",
    )
    _supportedProps = [
        "{virtres:}key",
        "{virtres:}title",
        "{virtres:}status",
        "{virtres:}orga",
        "{virtres:}tags",
        "{virtres:}description",
    ]
github mar10 / wsgidav / wsgidav / samples / virtual_dav_provider.py View on Github external
resList = [data for data in _resourceData if attrVal in data.get("tags")]
    return resList


def _get_res_by_key(key):
    """"""
    for data in _resourceData:
        if data["key"] == key:
            return data
    return None


# ============================================================================
#
# ============================================================================
class RootCollection(DAVCollection):
    """Resolve top-level requests '/'."""

    _visibleMemberNames = ("by_orga", "by_tag", "by_status")
    _validMemberNames = _visibleMemberNames + ("by_key",)

    def __init__(self, environ):
        DAVCollection.__init__(self, "/", environ)

    def get_member_names(self):
        return self._visibleMemberNames

    def get_member(self, name):
        # Handle visible categories and also /by_key/...
        if name in self._validMemberNames:
            return CategoryTypeCollection(join_uri(self.path, name), self.environ)
        return None
github mar10 / wsgidav / wsgidav / samples / virtual_dav_provider.py View on Github external
_validMemberNames = _visibleMemberNames + ("by_key",)

    def __init__(self, environ):
        DAVCollection.__init__(self, "/", environ)

    def get_member_names(self):
        return self._visibleMemberNames

    def get_member(self, name):
        # Handle visible categories and also /by_key/...
        if name in self._validMemberNames:
            return CategoryTypeCollection(join_uri(self.path, name), self.environ)
        return None


class CategoryTypeCollection(DAVCollection):
    """Resolve '/catType' URLs, for example '/by_tag'."""

    def __init__(self, path, environ):
        DAVCollection.__init__(self, path, environ)

    def get_display_info(self):
        return {"type": "Category type"}

    def get_member_names(self):
        names = []
        for data in _resourceData:
            if self.name == "by_status":
                if not data["status"] in names:
                    names.append(data["status"])
            elif self.name == "by_orga":
                if not data["orga"] in names:
github mar10 / wsgidav / wsgidav / fs_dav_provider.py View on Github external
environ=self.environ,
            )

    def set_last_modified(self, dest_path, time_stamp, dry_run):
        """Set last modified time for destPath to timeStamp on epoch-format"""
        # Translate time from RFC 1123 to seconds since epoch format
        secs = util.parse_time_string(time_stamp)
        if not dry_run:
            os.utime(self._file_path, (secs, secs))
        return True


# ========================================================================
# FolderResource
# ========================================================================
class FolderResource(DAVCollection):
    """Represents a single existing file system folder DAV resource.

    See also _DAVResource, DAVCollection, and FilesystemProvider.
    """

    def __init__(self, path, environ, file_path):
        super(FolderResource, self).__init__(path, environ)
        self._file_path = file_path
        #        self._dict = None
        self.file_stat = os.stat(self._file_path)
        # Setting the name from the file path should fix the case on Windows
        self.name = os.path.basename(self._file_path)
        self.name = compat.to_native(self.name)  # .encode("utf8")

    # Getter methods for standard live properties
    def get_creation_date(self):
github mar10 / wsgidav / wsgidav / samples / mongo_dav_provider.py View on Github external
from wsgidav import compat, util
from wsgidav.dav_provider import DAVCollection, DAVNonCollection, DAVProvider
from wsgidav.util import join_uri

import pymongo


__docformat__ = "reStructuredText"

_logger = util.get_module_logger(__name__)


# ============================================================================
#
# ============================================================================
class ConnectionCollection(DAVCollection):
    """Root collection, lists all mongo databases."""

    def __init__(self, path, environ):
        DAVCollection.__init__(self, path, environ)
        self.conn = self.provider.conn

    def get_member_names(self):
        return [name.encode("utf8") for name in self.conn.database_names()]

    def get_member(self, name):
        return DbCollection(join_uri(self.path, name), self.environ)


class DbCollection(DAVCollection):
    """Mongo database, contains mongo collections."""
github mar10 / wsgidav / wsgidav / samples / virtual_dav_provider.py View on Github external
def __init__(self, path, environ):
        DAVCollection.__init__(self, path, environ)
github mar10 / wsgidav / wsgidav / samples / dav_provider_tools.py View on Github external
from wsgidav.dav_provider import DAVCollection, DAVNonCollection

import os
import stat


__docformat__ = "reStructuredText en"

_logger = util.get_module_logger(__name__)

# ============================================================================
# VirtualCollection
# ============================================================================


class VirtualCollection(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(VirtualCollection, self).__init__(path, environ)
        if compat.is_basestring(display_info):
            display_info = {"type": display_info}
        assert type(display_info) is dict
        assert type(member_name_list) is list
        self.display_info = display_info
        self.member_name_list = member_name_list

    def get_display_info(self):
github mar10 / wsgidav / wsgidav / samples / virtual_dav_provider.py View on Github external
def __init__(self, environ):
        DAVCollection.__init__(self, "/", environ)
github mar10 / wsgidav / wsgidav / samples / virtual_dav_provider.py View on Github external
names.append(tag)

        names.sort()
        return names

    def get_member(self, name):
        if self.name == "by_key":
            data = _get_res_by_key(name)
            if data:
                return VirtualResource(join_uri(self.path, name), self.environ, data)
            else:
                return None
        return CategoryCollection(join_uri(self.path, name), self.environ, self.name)


class CategoryCollection(DAVCollection):
    """Resolve '/catType/cat' URLs, for example '/by_tag/cool'."""

    def __init__(self, path, environ, catType):
        DAVCollection.__init__(self, path, environ)
        self.catType = catType

    def get_display_info(self):
        return {"type": "Category"}

    def get_member_names(self):
        names = [
            data["title"] for data in _get_res_list_by_attr(self.catType, self.name)
        ]
        names.sort()
        return names