utils.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:osp-api 作者: opensyllabus 项目源码 文件源码
def resource_method_info(self, method) -> tuple:
        """Return the (class) name of the resource and its type, which
        is associated with the provided method (function).

        Used by this class' decorators to determine the name of the
        instance which subclassed this class, e.g., `WorksCollection`,
        as well as passing a nice `enum` for determining if it's
        a collection or singleton resource.

        Arguments:
            method (function): Hopefully a method which belongs
                to an instance that inherited from this class.

        Raises:
            InvalidResourceName: If the function belongs to
                a resource class whose name neither ends in
                `Collection` nor `Singleton`.

        Returns:
            tuple[str, str]: Resource class name, resoure type.

        """

        resource_class_name = self.__class__.__name__
        if resource_class_name.endswith('Collection'):
            resource_type = ResourceType.collection
        elif resource_class_name.endswith('Singleton'):
            resource_type = ResourceType.singleton
        else:
            raise InvalidResourceName(resource_class_name)

        return resource_class_name, resource_type
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号