copperlace.core
index
/home/runner/work/Copperlace/Copperlace/python/copperlace/core.py

 
Modules
       
ctypes

 
Classes
       
builtins.RuntimeError(builtins.Exception)
CopperlaceError
builtins.object
Copperlace
RuleSet

 
class Copperlace(builtins.object)
    Copperlace(ruleset: 'RuleSet') -> 'None'
 
Load-once Copperlace renderer for repeated renders.
 
``Copperlace`` is the recommended high-level API when rendering multiple
rules or rendering the same rule multiple times from one config. It wraps a
``RuleSet`` and can be used as a context manager.
 
  Methods defined here:
__del__(self) -> 'None'
__enter__(self) -> 'Self'
__exit__(self, exc_type: 'type[BaseException] | None', exc: 'BaseException | None', traceback: 'TracebackType | None') -> 'None'
__init__(self, ruleset: 'RuleSet') -> 'None'
Initialize self.  See help(type(self)) for accurate signature.
close(self) -> 'None'
Release the underlying native ruleset handle.
render(self, rule: 'str', context: 'Mapping[str, str] | None' = None) -> 'str'
Render a named rule from the loaded config.
 
Args:
    rule: Name of the rule to render.
    context: Optional initial render context values.
 
Returns:
    Rendered text for the requested rule.
 
Raises:
    CopperlaceError: If the renderer is closed or rendering fails.
render_inferred(self, rule: 'str', context: 'Mapping[str, str] | None' = None) -> 'str'
Render a rule as text, returning formatted JSON for object-valued rules.
 
Args:
    rule: Name of the rule to render.
    context: Optional initial render context values.
 
Returns:
    Rendered text, or formatted JSON for an object-valued rule.
 
Raises:
    CopperlaceError: If the renderer is closed or rendering fails.
render_structured(self, rule: 'str', context: 'Mapping[str, str] | None' = None) -> 'str'
Render a named structured rule from the loaded config as formatted JSON text.
 
Args:
    rule: Name of the structured rule to render.
    context: Optional initial render context values.
 
Returns:
    Formatted JSON text for the requested structured rule.
 
Raises:
    CopperlaceError: If the renderer is closed or rendering fails.

Class methods defined here:
from_file(path: 'str | Path', processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'Self'
Create a renderer from a configuration file.
 
Args:
    path: Path to the configuration file.
    processors: Optional custom processor callbacks.
 
Returns:
    A ``Copperlace`` renderer that can render rules repeatedly.
 
Raises:
    CopperlaceError: If the file cannot be loaded, parsed, or compiled.
from_string(config: 'str', processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'Self'
Create a renderer from a configuration string.
 
Args:
    config: configuration text containing Copperlace rules.
    processors: Optional custom processor callbacks.
 
Returns:
    A ``Copperlace`` renderer that can render rules repeatedly.
 
Raises:
    CopperlaceError: If the config cannot be parsed or compiled.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class CopperlaceError(builtins.RuntimeError)
    Raised when Copperlace cannot parse config, render a rule, or call native code.
 
 
Method resolution order:
CopperlaceError
builtins.RuntimeError
builtins.Exception
builtins.BaseException
builtins.object

Data descriptors defined here:
__weakref__
list of weak references to the object

Methods inherited from builtins.RuntimeError:
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.

Static methods inherited from builtins.RuntimeError:
__new__(*args, **kwargs) class method of builtins.RuntimeError
Create and return a new object.  See help(type) for accurate signature.

Methods inherited from builtins.BaseException:
__getattribute__(self, name, /)
Return getattr(self, name).
__reduce__(...)
Helper for pickle.
__repr__(self, /)
Return repr(self).
__setstate__(...)
__str__(self, /)
Return str(self).
add_note(...)
Exception.add_note(note) --
add a note to the exception
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
class RuleSet(builtins.object)
    RuleSet(handle: 'ctypes.c_void_p', processor_registry: 'object | None' = None) -> 'None'
 
Compiled Copperlace rules loaded from configuration.
 
Use :meth:`from_string` or :meth:`from_file` to compile config once, then
call :meth:`render` repeatedly. ``RuleSet`` owns a native handle, so callers
should use it as a context manager or call :meth:`close` when finished.
 
  Methods defined here:
__del__(self) -> 'None'
__enter__(self) -> 'Self'
__exit__(self, exc_type: 'type[BaseException] | None', exc: 'BaseException | None', traceback: 'TracebackType | None') -> 'None'
__init__(self, handle: 'ctypes.c_void_p', processor_registry: 'object | None' = None) -> 'None'
Initialize self.  See help(type(self)) for accurate signature.
close(self) -> 'None'
Release this ruleset's native handle.
 
Calling ``close`` more than once is allowed. Rendering after close raises
``CopperlaceError``.
render(self, rule: 'str', context: 'Mapping[str, str] | None' = None) -> 'str'
Render a named rule from this ruleset.
 
Each call uses a fresh render context, so per-render bindings are
consistent within one output but do not carry over to later renders.
``context`` provides initial string bindings for this render only.
 
Args:
    rule: Name of the rule to render.
    context: Optional initial render context values.
 
Returns:
    Rendered text for the requested rule.
 
Raises:
    CopperlaceError: If this ruleset is closed or rendering fails.
render_inferred(self, rule: 'str', context: 'Mapping[str, str] | None' = None) -> 'str'
Render a rule as text, returning formatted JSON for object-valued rules.
 
String-valued and list-valued rules use normal text rendering. Object-valued
structured rules return formatted JSON text.
 
Args:
    rule: Name of the rule to render.
    context: Optional initial render context values.
 
Returns:
    Rendered text, or formatted JSON for an object-valued rule.
 
Raises:
    CopperlaceError: If this ruleset is closed or rendering fails.
render_structured(self, rule: 'str', context: 'Mapping[str, str] | None' = None) -> 'str'
Render a named structured rule from this ruleset as formatted JSON text.
 
Args:
    rule: Name of the structured rule to render.
    context: Optional initial render context values.
 
Returns:
    Formatted JSON text for the requested structured rule.
 
Raises:
    CopperlaceError: If this ruleset is closed or rendering fails.

Class methods defined here:
from_file(path: 'str | Path', processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'Self'
Compile a ruleset from a configuration file.
 
Args:
    path: Path to the configuration file.
    processors: Optional custom processor callbacks.
 
Returns:
    A ``RuleSet`` backed by a native Copperlace handle.
 
Raises:
    CopperlaceError: If the file cannot be loaded, parsed, or compiled.
from_string(config: 'str', processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'Self'
Compile a ruleset from a configuration string.
 
Args:
    config: configuration text containing Copperlace rules.
    processors: Optional custom processor callbacks.
 
Returns:
    A ``RuleSet`` backed by a native Copperlace handle.
 
Raises:
    CopperlaceError: If the config cannot be parsed or compiled.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
render_file(path: 'str | Path', rule: 'str', context: 'Mapping[str, str] | None' = None, *, processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'str'
Render one rule from a configuration file.
 
This convenience helper loads the file, renders one rule, and releases the
native handle. Use ``Copperlace.from_file`` for repeated renders.
 
Args:
    path: Path to the configuration file.
    rule: Name of the rule to render.
    context: Optional initial render context values.
    processors: Optional custom processor callbacks.
 
Returns:
    Rendered text for the requested rule.
 
Raises:
    CopperlaceError: If loading, parsing, compilation, or rendering fails.
render_file_inferred(path: 'str | Path', rule: 'str', context: 'Mapping[str, str] | None' = None, *, processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'str'
Render one rule from a configuration file, returning formatted JSON for object-valued rules.
render_file_structured(path: 'str | Path', rule: 'str', context: 'Mapping[str, str] | None' = None, *, processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'str'
Render one structured rule from a configuration file as formatted JSON text.
 
This convenience helper loads the file, renders one structured rule, and
releases the native handle.
 
Args:
    path: Path to the configuration file.
    rule: Name of the structured rule to render.
    context: Optional initial render context values.
    processors: Optional custom processor callbacks.
 
Returns:
    Formatted JSON text for the requested structured rule.
 
Raises:
    CopperlaceError: If loading, parsing, compilation, or rendering fails.
render_str(config: 'str', rule: 'str', context: 'Mapping[str, str] | None' = None, *, processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'str'
Render one rule from a configuration string.
 
This convenience helper compiles the config, renders one rule, and releases
the native handle. Use ``Copperlace.from_string`` for repeated renders.
 
Args:
    config: configuration text containing Copperlace rules.
    rule: Name of the rule to render.
    context: Optional initial render context values.
    processors: Optional custom processor callbacks.
 
Returns:
    Rendered text for the requested rule.
 
Raises:
    CopperlaceError: If parsing, compilation, or rendering fails.
render_str_inferred(config: 'str', rule: 'str', context: 'Mapping[str, str] | None' = None, *, processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'str'
Render one rule from a configuration string, returning formatted JSON for object-valued rules.
render_str_structured(config: 'str', rule: 'str', context: 'Mapping[str, str] | None' = None, *, processors: 'Mapping[str, Callable[[str], str]] | None' = None) -> 'str'
Render one structured rule from a configuration string as formatted JSON text.
 
This convenience helper compiles the config, renders one structured rule,
and releases the native handle.
 
Args:
    config: configuration text containing Copperlace rules.
    rule: Name of the structured rule to render.
    context: Optional initial render context values.
    processors: Optional custom processor callbacks.
 
Returns:
    Formatted JSON text for the requested structured rule.
 
Raises:
    CopperlaceError: If parsing, compilation, or rendering fails.

 
Data
        Self = typing.Self