🔍 Code Extractor

class EntityCollection_v1

Maturity: 33

A collection container which represents a named collections of entities

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/entity_collection.py
Lines:
17 - 63
Complexity:
moderate

Purpose

A collection container which represents a named collections of entities

Source Code

class EntityCollection(ClientObjectCollection[T]):
    """A collection container which represents a named collections of entities"""

    def __init__(self, context, item_type, resource_path=None, parent=None):
        # type: (GraphClient, Type[T], Optional[ResourcePath], Optional[Entity]) -> None
        super(EntityCollection, self).__init__(
            context, item_type, resource_path, parent
        )

    def __getitem__(self, key):
        # type: (int | str) -> T
        """
        :param key: key is used to address an entity by either an index or by identifier
        :type key: int or str
        """
        if isinstance(key, int):
            return super(EntityCollection, self).__getitem__(key)
        elif is_string_type(key):
            return self.create_typed_object(
                resource_path=EntityPath(key, self.resource_path)
            )
        else:
            raise ValueError(
                "Invalid key: expected either an entity index [int] or identifier [str]"
            )

    def add(self, **kwargs):
        # type: (Any) -> T
        """Creates an entity and prepares the query"""
        return_type = self.create_typed_object(kwargs, ItemPath(self.resource_path))
        self.add_child(return_type)
        qry = CreateEntityQuery(self, return_type, return_type)
        self.context.add_query(qry)
        return return_type

    def create_typed_object(self, initial_properties=None, resource_path=None):
        # type: (Optional[dict], Optional[ResourcePath]) -> T
        if resource_path is None:
            resource_path = EntityPath(None, self.resource_path)
        return super(EntityCollection, self).create_typed_object(
            initial_properties, resource_path
        )

    @property
    def context(self):
        # type: () -> GraphClient
        return self._context

Parameters

Name Type Default Kind
bases ClientObjectCollection[T] -

Parameter Details

bases: Parameter of type ClientObjectCollection[T]

Return Value

Returns unspecified type

Class Interface

Methods

__init__(self, context, item_type, resource_path, parent)

Purpose: Internal method: init

Parameters:

  • context: Parameter
  • item_type: Parameter
  • resource_path: Parameter
  • parent: Parameter

Returns: None

__getitem__(self, key)

Purpose: :param key: key is used to address an entity by either an index or by identifier :type key: int or str

Parameters:

  • key: Parameter

Returns: None

add(self)

Purpose: Creates an entity and prepares the query

Returns: None

create_typed_object(self, initial_properties, resource_path)

Purpose: Creates typed

Parameters:

  • initial_properties: Parameter
  • resource_path: Parameter

Returns: None

context(self) property

Purpose: Performs context

Returns: None

Required Imports

from typing import TYPE_CHECKING
from typing import Any
from typing import Optional
from typing import Type
from typing import TypeVar

Usage Example

# Example usage:
# result = EntityCollection(bases)

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class EntityCollection 77.9% similar

    EntityCollection is a generic collection class for managing SharePoint entity sets, extending ClientObjectCollection with SharePoint-specific functionality.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/entity_collection.py
  • class AppCollection 62.5% similar

    AppCollection is a SharePoint entity class representing a collection of Microsoft App Services applications.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/apps/app_collection.py
  • class FormCollection 60.3% similar

    A collection class that manages and provides access to SharePoint list forms, inheriting from EntityCollection[Form].

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/forms/collection.py
  • class VideoItemCollection 60.1% similar

    A collection class for managing VideoItem entities in SharePoint, inheriting from EntityCollection to provide collection-level operations for video items.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/publishing/video/item_collection.py
  • class AttachmentCollection_v1 59.8% similar

    Represents a collection of Attachment resources.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/attachments/collection.py
← Back to Browse