CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-comtypes

Pure Python COM package for Windows COM automation and interoperability

88

0.98x
Overview
Eval results
Files

task.mdevals/scenario-5/

Data Validator COM Service

Build a COM service that validates structured data and provides detailed error information when validation fails.

Requirements

Create a Python COM server that validates data dictionaries against predefined rules. When validation fails, the service must use COM error information interfaces to provide:

  • A descriptive error message explaining what validation rule failed
  • The interface ID (IID) where the error occurred
  • A help file path (can be a documentation URL)
  • A help context identifier (can be an error code)

The validator should support two types of validation rules:

  1. Required fields: Check that specified fields exist in the data dictionary
  2. Type validation: Verify that field values match expected Python types (str, int, float, bool)

Implementation

Your implementation should:

  1. Define a COM interface for the data validator
  2. Implement a COM server class that performs validation
  3. Use comtypes error reporting functions to provide detailed error information when validation fails
  4. Include helper methods to configure validation rules and validate data

When validation fails, use the appropriate comtypes functions to create and set error information that COM clients can retrieve.

Test Cases

  • When validating {"name": "John"} with a required field rule for "email", the validator raises a COM error with detailed error information accessible via IErrorInfo. @test

  • When validating {"age": "thirty"} with a type rule expecting "age" to be int, the validator raises a COM error with error information including description, IID, and help context. @test

  • When validating {"name": "Alice", "age": 25} with rules requiring "name" (str) and "age" (int), validation succeeds without raising errors. @test

@generates

from comtypes import COMObject, GUID, IUnknown, COMMETHOD
from ctypes import HRESULT

class IDataValidator(IUnknown):
    """COM interface for data validation with detailed error reporting"""
    _iid_ = GUID("{...}")  # Define appropriate GUID

    # Define interface methods for:
    # - Setting validation rules
    # - Validating data
    # - Retrieving validation results

class DataValidator(COMObject):
    """
    COM server that validates data dictionaries and provides detailed error
    information via IErrorInfo when validation fails.
    """

    def __init__(self):
        """Initialize the validator with empty rule set"""
        pass

    def set_rules(self, rules: dict) -> None:
        """
        Configure validation rules.

        Args:
            rules: Dictionary mapping field names to validation rules
                  Example: {"name": {"required": True, "type": str}}
        """
        pass

    def validate(self, data: dict) -> bool:
        """
        Validate data against configured rules.

        Args:
            data: Dictionary to validate

        Returns:
            True if validation succeeds

        Raises:
            COMError with detailed error information (via IErrorInfo) if validation fails.
            Error information should include description, IID, help file, and help context.
        """
        pass

Dependencies { .dependencies }

comtypes { .dependency }

Provides COM interoperability for Python on Windows, including error reporting interfaces.

Install with Tessl CLI

npx tessl i tessl/pypi-comtypes

tile.json