Server-Side Python Mapping for Interfaces
Skeleton Classes
On the server side, interfaces map to skeleton classes. A skeleton is an abstract base class from which you derive your servant class and define a method for each operation on the corresponding interface. For example, consider our Slice definition for the Node interface:
module Filesystem
{
interface Node
{
idempotent string name();
}
// ...
}
The Python mapping generates the following definition for this interface:
class Node(Ice.Object, ABC):
@abstractmethod
def name(self, current: Current) -> str | Awaitable[str]:
pass
The important points to note here are:
As for the client side, Slice modules are mapped to Python packages with the same name, so the skeleton class definitions are part of the
Filesystempackage.The name of the skeleton class is the same as the Slice interface (
Node).The skeleton class is an abstract base class with an abstract method for each operation defined in the Slice interface.
The skeleton class inherits from
Ice.Object(which forms the root of the Ice object hierarchy).
Ice.Object Servant Base Class
The Slice pseudo-interface Object is mapped to the Ice.Object class in Python.
Servant Classes
In order to provide an implementation for an Ice object, you must create a servant class that inherits from the corresponding skeleton class. For example, to create a servant for the Node interface, you could write:
from Filesystem import Node
import Ice
class MNode(Node):
def __init__(self, name: str):
self._name = name
def name(self, _: Ice.Current) -> str:
return self._name
Note that MNode implements Node, the skeleton class.
As far as Ice is concerned, the MNode class must implement only a single method: the abstract method name. This makes the servant class a concrete class that you can instantiate. You can add other methods and attributes as you see fit to support your implementation. For example, in the preceding definition, we added a _name instance attribute and an initializer.