🔍 Code Extractor

class EntityPath

Maturity: 44

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.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/paths/v3/entity.py
Lines:
4 - 17
Complexity:
simple

Purpose

EntityPath provides a way to construct and represent paths to individual entities in a resource hierarchy, typically used in REST API or OData-style URL construction. It handles different key types (integer, string, or None) and formats them appropriately with parentheses notation. The class is designed to work within the Office365 SDK's path resolution system for accessing specific entities by their unique identifiers.

Source Code

class EntityPath(ResourcePath):
    """Path for addressing a single entity by key"""

    @property
    def segment(self):
        if self._key is None:
            return "(<key>)"
        elif isinstance(self._key, int):
            return "({0})".format(self._key)
        return "('{0}')".format(self._key)

    @property
    def delimiter(self):
        return None

Parameters

Name Type Default Kind
bases ResourcePath -

Parameter Details

__init__: Inherits constructor from ResourcePath base class. The exact parameters depend on the parent class implementation, but typically includes a key parameter (_key) that identifies the specific entity being addressed.

Return Value

Instantiation returns an EntityPath object that can generate formatted path segments. The segment property returns a string representation of the entity key in parentheses format: '(<key>)' for None, '(123)' for integers, or '('value')' for strings. The delimiter property returns None, indicating no delimiter is used after this path segment.

Class Interface

Methods

@property segment(self) -> str property

Purpose: Returns a formatted string representation of the entity key enclosed in parentheses, with appropriate formatting based on key type

Returns: A string in the format '(<key>)' if _key is None, '(123)' if _key is an integer, or '('value')' if _key is a string

@property delimiter(self) -> None property

Purpose: Returns the delimiter used after this path segment, which is None for EntityPath indicating no delimiter is needed

Returns: None, indicating no delimiter is used after this path segment

Attributes

Name Type Description Scope
_key int | str | None The key identifier for the entity. Can be an integer for numeric IDs, a string for named entities, or None for placeholder representation. Inherited from parent class. instance

Dependencies

  • office365

Required Imports

from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.paths.entity_path import EntityPath

Usage Example

from office365.runtime.paths.entity_path import EntityPath
from office365.runtime.paths.resource_path import ResourcePath

# Create an EntityPath with an integer key
entity_path_int = EntityPath()
entity_path_int._key = 123
print(entity_path_int.segment)  # Output: (123)

# Create an EntityPath with a string key
entity_path_str = EntityPath()
entity_path_str._key = 'user123'
print(entity_path_str.segment)  # Output: ('user123')

# Create an EntityPath with no key
entity_path_none = EntityPath()
entity_path_none._key = None
print(entity_path_none.segment)  # Output: (<key>)

# Check delimiter
print(entity_path_int.delimiter)  # Output: None

Best Practices

  • EntityPath is designed to be used as part of a larger path construction system, typically chained with other ResourcePath objects
  • The _key attribute should be set after instantiation or passed through the parent class constructor
  • Use integer keys for numeric entity identifiers and string keys for named entities
  • The segment property is read-only and automatically formats the key appropriately
  • This class is typically not instantiated directly by end users but rather created internally by the Office365 SDK when building entity references
  • The delimiter property returning None indicates this is a terminal path segment or uses a different concatenation strategy than typical path delimiters

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class EntityPath_v1 88.2% similar

    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.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/paths/v4/entity.py
  • class ItemPath 76.4% 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 MePath 67.9% 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
  • class DeltaPath 65.9% 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 65.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
← Back to Browse