class PrincipalType
An enumeration-style class that defines constants representing different types of principals in a SharePoint or similar access control system.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/principal/type.py
1 - 23
simple
Purpose
PrincipalType serves as a constants container for identifying and filtering different types of security principals (users, groups, distribution lists, etc.) in access control and permission management scenarios. It provides integer flag values that can be used individually or combined using bitwise operations to represent multiple principal types simultaneously. The 'All' constant (15) represents a bitwise OR of all individual types, allowing operations on all principal types at once.
Source Code
class PrincipalType:
"""Specifies the type of a principal."""
def __init__(self):
pass
None_ = 0
"""Do not specify a principal type."""
User = 1
"""A user principal type."""
DistributionList = 2
"""A distribution list principal type."""
SecurityGroup = 4
"""A security group principal type."""
SharePointGroup = 8
"""A SharePoint group principal type."""
All = 15
"""All principal types."""
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
__init__: The constructor takes no parameters and performs no initialization. It exists only to allow instantiation of the class, though the class is primarily used for its class-level constants rather than instance creation.
Return Value
Instantiating PrincipalType returns an instance of the class with no instance-specific state. The class itself provides integer constants (None_=0, User=1, DistributionList=2, SecurityGroup=4, SharePointGroup=8, All=15) that can be accessed directly via the class name without instantiation.
Class Interface
Methods
__init__(self) -> None
Purpose: Initializes an instance of PrincipalType (though instantiation is not typically necessary)
Returns: None - creates an empty instance with no state
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
None_ |
int | Constant value 0 indicating no principal type is specified | class |
User |
int | Constant value 1 representing a user principal type (bit flag: 2^0) | class |
DistributionList |
int | Constant value 2 representing a distribution list principal type (bit flag: 2^1) | class |
SecurityGroup |
int | Constant value 4 representing a security group principal type (bit flag: 2^2) | class |
SharePointGroup |
int | Constant value 8 representing a SharePoint group principal type (bit flag: 2^3) | class |
All |
int | Constant value 15 representing all principal types combined (1|2|4|8=15) | class |
Usage Example
# Access constants directly from the class (recommended approach)
from principal_type import PrincipalType
# Check for user principal type
if principal_type == PrincipalType.User:
print("This is a user principal")
# Use bitwise operations to combine types
user_and_group = PrincipalType.User | PrincipalType.SecurityGroup
# Check if a type includes users (bitwise AND)
if principal_type & PrincipalType.User:
print("Includes user principals")
# Use All to represent all principal types
all_principals = PrincipalType.All
# Instantiation (not typically necessary)
pt = PrincipalType()
user_type = pt.User # Same as PrincipalType.User
Best Practices
- Access constants directly via the class name (e.g., PrincipalType.User) rather than creating instances, as this is a constants container class.
- The integer values are designed as bit flags (powers of 2: 1, 2, 4, 8) allowing bitwise operations to combine multiple types.
- Use bitwise OR (|) to combine multiple principal types: PrincipalType.User | PrincipalType.SecurityGroup
- Use bitwise AND (&) to check if a combined value includes a specific type: if value & PrincipalType.User
- The 'All' constant (15) is the bitwise OR of all individual types (1|2|4|8=15), useful for operations affecting all principal types.
- The 'None_' constant uses an underscore suffix to avoid conflict with Python's None keyword.
- This class follows an older Python pattern for enumerations; consider using Python's enum.IntFlag for new code with similar requirements.
- No state management is needed as this class only provides constant values.
- Thread-safe by design as it only contains immutable class-level integer constants.
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class PrincipalSource 72.8% similar
-
class RoleType 69.1% similar
-
class Principal 67.5% similar
-
class PageType 63.6% similar
-
class Principal_v1 63.0% similar