xml-pipeline/third_party/xmlable/_user.py
dullfig 82b5fcdd78 Replace MessageBus with aiostream-based StreamPump
Major refactor of the message pump architecture:

- Replace bus.py with stream_pump.py using aiostream for composable
  stream processing with natural fan-out via flatmap
- Add to_id field to MessageState for explicit routing
- Fix routing to use to_id.class format (e.g., "greeter.greeting")
- Generate XSD schemas from xmlified payload classes
- Fix xmlable imports (absolute -> relative) and parse_element ctx

New features:
- handlers/hello.py: Sample Greeting/GreetingResponse handler
- config/organism.yaml: Sample organism configuration
- 41 tests (31 unit + 10 integration) all passing

Schema changes:
- envelope.xsd: Allow any namespace payloads (##other -> ##any)

Dependencies added to pyproject.toml:
- aiostream>=0.5 (core dependency)
- pyhumps, termcolor (for xmlable)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 10:41:17 -08:00

71 lines
1.7 KiB
Python

"""
The IXmlify interface
- Contains the methods needed to make get_xobject work
- Allows type checking of user's implementations
"""
from abc import ABC, abstractmethod
from lxml.etree import _Element
from ._xobject import XObject
from ._utils import AnyType
class IXmlify(ABC):
"""
A useful interface for ensuring the attributes required for
@manual_xmlify are present
"""
@staticmethod
@abstractmethod
def get_xobject() -> XObject:
"""
produces an xobject encapsulates the:
- xsd usage (e.g <xs:element name="..." type="thisclass!"/>)
- xml template
- xml value
- parsing
```
@manual_xmlify
class Foo(IXmlify):
def get_xobject() -> XObject:
class MyObj(XObject):
# ... definitions
return MyObj
```
"""
pass
@staticmethod
@abstractmethod
def xsd_forward(add_ns: dict[str, str]) -> _Element:
"""
Produces the forward declaration
- xsd definition of the class's type
```
@manual_xmlify
class Foo(IXmlify):
def xsd_forward(add_ns: dict[str, str]) -> _Element:
return Element('{XMLSchema}complexType', name="Foo", ...)
```
"""
pass
@staticmethod
@abstractmethod
def xsd_dependencies() -> set[AnyType]:
"""
The user classes that need to be before this first
For example:
```
@manual_xmlify
class A(IXMlify):
# xobject uses Foo and Bar
def xsd_depedencies() -> set[type]:
return {Foo, Bar}
```
"""
pass