🔍 Code Extractor

class RequestContext

Maturity: 48

RequestContext is a class that provides basic WSS (Windows SharePoint Services) context information including site, web, list, and list item details for SharePoint operations.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/request_context.py
Lines:
5 - 23
Complexity:
moderate

Purpose

This class serves as a context provider for SharePoint operations, allowing retrieval of context information about SharePoint objects such as the current Web application, site collection, site, list, or list item. It extends ClientObject to provide SharePoint-specific context management and supports operations on mounted folders through remote context retrieval.

Source Code

class RequestContext(ClientObject):
    """
    Provides basic WSS context information: site, web, list, and list item.

    Use this class to return context information about such objects as the current Web application, site collection,
        site, list, or list item.
    """

    def get_remote_context(self):
        """
        Returns the SP.RequestContext for the mounted folder.
        Returns null if this is not an attempt to render or act upon a mounted folder.
        """
        return_type = RequestContext(self.context)
        qry = ServiceOperationQuery(
            self, "GetRemoteContext", None, None, None, return_type
        )
        self.context.add_query(qry)
        return return_type

Parameters

Name Type Default Kind
bases ClientObject -

Parameter Details

context: A context object (likely a ClientContext or similar) that provides the connection and state information for SharePoint operations. This is inherited from the ClientObject base class and is required for all SharePoint API interactions.

Return Value

Instantiation returns a RequestContext object that can be used to query SharePoint context information. The get_remote_context() method returns a new RequestContext instance representing the context for a mounted folder, or null if the current operation is not related to a mounted folder.

Class Interface

Methods

get_remote_context(self) -> RequestContext

Purpose: Returns the RequestContext for a mounted folder, or null if the current operation is not related to a mounted folder

Returns: A new RequestContext instance representing the remote context for the mounted folder, or null if not applicable

Attributes

Name Type Description Scope
context ClientContext The parent context object that provides connection and state information for SharePoint operations. Inherited from ClientObject base class. instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_object import ClientObject
from office365.runtime.queries.service_operation import ServiceOperationQuery

Usage Example

# Assuming you have a ClientContext instance already configured
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext

# Setup authentication and context
site_url = 'https://yourtenant.sharepoint.com/sites/yoursite'
auth_context = AuthenticationContext(site_url)
auth_context.acquire_token_for_user('username', 'password')
client_context = ClientContext(site_url, auth_context)

# Create RequestContext instance
request_context = RequestContext(client_context)

# Get remote context for mounted folders
remote_context = request_context.get_remote_context()
client_context.execute_query()

# The remote_context will contain context information for the mounted folder
# or will be null if not operating on a mounted folder

Best Practices

  • Always ensure a valid ClientContext is passed to the constructor before instantiating RequestContext
  • Call execute_query() on the parent context after calling get_remote_context() to actually execute the query and retrieve results
  • Check if the returned remote context is null before attempting to use it, as it will be null when not operating on mounted folders
  • RequestContext instances are typically created with an existing context object and should not be instantiated without proper SharePoint authentication
  • The get_remote_context() method adds a query to the context's query queue but does not execute it immediately - execution is deferred until execute_query() is called on the parent context
  • This class follows the SharePoint CSOM (Client-Side Object Model) pattern where operations are batched and executed together

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ClientContext 68.7% similar

    SharePoint client context (SharePoint v1 API)

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/client_context.py
  • class RequestUserContext 66.8% similar

    Represents the user context for the current SharePoint request, providing access to user information and context details typically available at the /_api/me endpoint.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/request_user_context.py
  • class ComponentContextInfo 61.0% similar

    A wrapper class for SharePoint's ContextInfo object, specifically designed for internal use with client-side components.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/clientsidecomponent/component_context_info.py
  • class QueryContext 59.2% similar

    QueryContext is a data container class that encapsulates query context properties for Microsoft Office Server Search REST API operations.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/search/query/context.py
  • class GroupCreationContext 58.8% similar

    A client value class representing the context for creating a SharePoint group, inheriting from ClientValue base class.

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