🔍 Code Extractor

class EntityPath_v1

Maturity: 34

EntityPath is a specialized ResourcePath class that represents a path to an entity resource in Office 365, with support for collections and dynamic path patching.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/paths/v4/entity.py
Lines:
4 - 36
Complexity:
moderate

Purpose

EntityPath extends ResourcePath to provide path management for Office 365 entities (like files, folders, or other resources). It maintains a reference to a collection and provides mechanisms to construct and modify resource paths dynamically. The class is designed to work within the Office 365 SDK's path hierarchy, particularly with OneDrive resources, and supports lazy resolution of collection references through parent path traversal.

Source Code

class EntityPath(ResourcePath):
    def __init__(self, key=None, parent=None, collection=None):
        """
        :param str or None key: Entity key
        :param ResourcePath or None collection:
        """
        super(EntityPath, self).__init__(key, parent)
        self._collection = collection

    @property
    def collection(self):
        from office365.onedrive.internal.paths.children import ChildrenPath

        if self._collection is None:
            if isinstance(self.parent, ChildrenPath):
                self._collection = self.parent.collection
            else:
                self._collection = self.parent
        return self._collection

    @property
    def segment(self):
        return str(self._key or "<key>")

    def patch(self, key):
        """
        Patches path
        :type key: str or None
        """
        self._key = key
        self._parent = self.collection
        self.__class__ = EntityPath
        return self

Parameters

Name Type Default Kind
bases ResourcePath -

Parameter Details

key: A string identifier for the entity resource, or None if the key is not yet determined. This typically represents a unique identifier like a file ID or folder ID in the Office 365 resource hierarchy.

parent: A ResourcePath instance representing the parent path in the resource hierarchy, or None if this is a root-level path. Used for building hierarchical path structures.

collection: A ResourcePath instance representing the collection this entity belongs to, or None to have it automatically resolved from the parent path. Collections typically represent container resources like folders or lists.

Return Value

Instantiation returns an EntityPath object that represents a path to an Office 365 entity resource. The patch() method returns self (the EntityPath instance) to allow method chaining. The collection property returns a ResourcePath representing the collection. The segment property returns a string representation of the path segment.

Class Interface

Methods

__init__(self, key=None, parent=None, collection=None)

Purpose: Initializes an EntityPath instance with optional key, parent, and collection parameters

Parameters:

  • key: String identifier for the entity or None
  • parent: ResourcePath instance representing the parent path or None
  • collection: ResourcePath instance representing the collection or None for automatic resolution

Returns: None (constructor)

@property collection(self) -> ResourcePath property

Purpose: Returns the collection this entity belongs to, with lazy resolution from parent if not explicitly set

Returns: ResourcePath instance representing the collection. If parent is a ChildrenPath, returns its collection; otherwise returns the parent itself

@property segment(self) -> str property

Purpose: Returns the string representation of this path segment

Returns: String representation of the key, or '<key>' if key is None or empty

patch(self, key) -> EntityPath

Purpose: Updates the entity path with a new key and resets the parent to the collection

Parameters:

  • key: String identifier to set as the new key, or None to clear the key

Returns: Self (the EntityPath instance) for method chaining

Attributes

Name Type Description Scope
_collection ResourcePath or None Private attribute storing the collection this entity belongs to. May be None initially and resolved lazily via the collection property instance
_key str or None Inherited from ResourcePath. Stores the entity's unique identifier key instance
_parent ResourcePath or None Inherited from ResourcePath. Stores the parent path in the resource hierarchy instance

Dependencies

  • office365

Required Imports

from office365.runtime.paths.resource_path import ResourcePath

Conditional/Optional Imports

These imports are only needed under specific conditions:

from office365.onedrive.internal.paths.children import ChildrenPath

Condition: only when accessing the collection property and the parent is a ChildrenPath instance

Optional

Usage Example

# Basic instantiation
from office365.runtime.paths.resource_path import ResourcePath
from office365.onedrive.internal.paths.entity import EntityPath

# Create a parent path
parent_path = ResourcePath('parent_key')

# Create an entity path with a key
entity_path = EntityPath(key='entity123', parent=parent_path)

# Access the path segment
print(entity_path.segment)  # Output: 'entity123'

# Create an entity path without a key (placeholder)
placeholder_path = EntityPath(parent=parent_path)
print(placeholder_path.segment)  # Output: '<key>'

# Patch the path with a new key
placeholder_path.patch('new_entity456')
print(placeholder_path.segment)  # Output: 'new_entity456'

# Access the collection (automatically resolved from parent)
collection = entity_path.collection

Best Practices

  • Always provide either a key or be prepared to call patch() later to set the key before using the path in API calls
  • The collection property uses lazy evaluation, so it's safe to instantiate EntityPath objects without immediately providing a collection parameter
  • When using patch(), be aware that it modifies the instance in place and changes the parent to the collection, which affects the path hierarchy
  • The patch() method also resets the class type to EntityPath, which suggests it may be used to convert derived classes back to the base EntityPath type
  • EntityPath is designed to work with ChildrenPath instances as parents, which have special collection resolution logic
  • The segment property returns '<key>' as a placeholder when no key is set, which is useful for debugging and path visualization

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class EntityPath 88.2% similar

    EntityPath is a specialized ResourcePath subclass that represents a path for addressing a single entity using a key, formatting the path segment with appropriate syntax based on the key type.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/paths/v3/entity.py
  • class ItemPath 78.2% similar

    ItemPath is a specialized path class that extends EntityPath, representing a path to an item entity in the Office365 API hierarchy.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/paths/item.py
  • class DeltaPath 68.8% similar

    DeltaPath is a specialized path class that represents a 'delta' entity path in the Office365 SDK, inheriting from EntityPath.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/delta_path.py
  • class WebPath 68.1% similar

    WebPath is a specialized ResourcePath subclass that represents web-based resource paths, handling both absolute URLs and relative paths with web-specific path parsing.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/internal/paths/web.py
  • class MePath 67.5% similar

    A specialized EntityPath class representing the resource path for the currently signed-in user in Microsoft Graph API or Office 365 services.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/internal/paths/me.py
← Back to Browse