Skip to content

mixins

xsdata.codegen.mixins

ContainerInterface

Bases: ABC

A class list wrapper with an easy access api.

Parameters:

Name Type Description Default
config GeneratorConfig

The generator configuration instance

required
Source code in xsdata/codegen/mixins.py
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class ContainerInterface(abc.ABC):
    """A class list wrapper with an easy access api.

    Args:
        config: The generator configuration instance
    """

    __slots__ = ("config", "data")

    def __init__(self, config: GeneratorConfig):
        self.config = config
        self.data: Dict[str, List[Class]] = {}

    @abc.abstractmethod
    def __iter__(self) -> Iterator[Class]:
        """Yield an iterator for the class map values."""

    @abc.abstractmethod
    def process(self):
        """Run the processor and filter steps."""

    @abc.abstractmethod
    def find(self, qname: str, condition: Callable = return_true) -> Optional[Class]:
        """Find class that matches the given qualified name and condition callable.

        Classes are allowed to have the same qualified name, e.g. xsd:Element
        extending xsd:ComplexType with the same name, you can provide and additional
        callback to filter the classes like the tag.

        Args:
            qname: The qualified name of the class
            condition: A user callable to filter further

        Returns:
            A class instance or None if no match found.
        """

    @abc.abstractmethod
    def find_inner(self, source: Class, qname: str) -> Class:
        """Search by qualified name for a specific inner class or fail.

        Args:
            source: The source class to search for the inner class
            qname: The qualified name of the inner class to look up

        Returns:
            The inner class instance

        Raises:
            CodeGenerationError: If the inner class is not found.
        """

    @abc.abstractmethod
    def first(self, qname: str) -> Class:
        """Return the first class that matches the qualified name.

        Args:
            qname: The qualified name of the class

        Returns:
            The first matching class

        Raises:
            KeyError: If no class matches the qualified name
        """

    @abc.abstractmethod
    def add(self, item: Class):
        """Add class instance to the container.

        Args:
            item: The class instance to add
        """

    @abc.abstractmethod
    def remove(self, *items: Class):
        """Safely remove classes from the container.

        Args:
            items: The classes to remove
        """

    @abc.abstractmethod
    def extend(self, items: List[Class]):
        """Add a list of classes to the container.

        Args:
            items: The list of class instances to add
        """

    @abc.abstractmethod
    def reset(self, item: Class, qname: str):
        """Update the given class qualified name.

        Args:
            item: The target class instance to update
            qname: The new qualified name of the class
        """

    @abc.abstractmethod
    def set(self, items: List[Class]):
        """Set the list of classes to the container.

        Args:
            items: The list of classes
        """

__iter__() abstractmethod

Yield an iterator for the class map values.

Source code in xsdata/codegen/mixins.py
23
24
25
@abc.abstractmethod
def __iter__(self) -> Iterator[Class]:
    """Yield an iterator for the class map values."""

process() abstractmethod

Run the processor and filter steps.

Source code in xsdata/codegen/mixins.py
27
28
29
@abc.abstractmethod
def process(self):
    """Run the processor and filter steps."""

find(qname, condition=return_true) abstractmethod

Find class that matches the given qualified name and condition callable.

Classes are allowed to have the same qualified name, e.g. xsd:Element extending xsd:ComplexType with the same name, you can provide and additional callback to filter the classes like the tag.

Parameters:

Name Type Description Default
qname str

The qualified name of the class

required
condition Callable

A user callable to filter further

return_true

Returns:

Type Description
Optional[Class]

A class instance or None if no match found.

Source code in xsdata/codegen/mixins.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@abc.abstractmethod
def find(self, qname: str, condition: Callable = return_true) -> Optional[Class]:
    """Find class that matches the given qualified name and condition callable.

    Classes are allowed to have the same qualified name, e.g. xsd:Element
    extending xsd:ComplexType with the same name, you can provide and additional
    callback to filter the classes like the tag.

    Args:
        qname: The qualified name of the class
        condition: A user callable to filter further

    Returns:
        A class instance or None if no match found.
    """

find_inner(source, qname) abstractmethod

Search by qualified name for a specific inner class or fail.

Parameters:

Name Type Description Default
source Class

The source class to search for the inner class

required
qname str

The qualified name of the inner class to look up

required

Returns:

Type Description
Class

The inner class instance

Raises:

Type Description
CodeGenerationError

If the inner class is not found.

Source code in xsdata/codegen/mixins.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@abc.abstractmethod
def find_inner(self, source: Class, qname: str) -> Class:
    """Search by qualified name for a specific inner class or fail.

    Args:
        source: The source class to search for the inner class
        qname: The qualified name of the inner class to look up

    Returns:
        The inner class instance

    Raises:
        CodeGenerationError: If the inner class is not found.
    """

first(qname) abstractmethod

Return the first class that matches the qualified name.

Parameters:

Name Type Description Default
qname str

The qualified name of the class

required

Returns:

Type Description
Class

The first matching class

Raises:

Type Description
KeyError

If no class matches the qualified name

Source code in xsdata/codegen/mixins.py
62
63
64
65
66
67
68
69
70
71
72
73
74
@abc.abstractmethod
def first(self, qname: str) -> Class:
    """Return the first class that matches the qualified name.

    Args:
        qname: The qualified name of the class

    Returns:
        The first matching class

    Raises:
        KeyError: If no class matches the qualified name
    """

add(item) abstractmethod

Add class instance to the container.

Parameters:

Name Type Description Default
item Class

The class instance to add

required
Source code in xsdata/codegen/mixins.py
76
77
78
79
80
81
82
@abc.abstractmethod
def add(self, item: Class):
    """Add class instance to the container.

    Args:
        item: The class instance to add
    """

remove(*items) abstractmethod

Safely remove classes from the container.

Parameters:

Name Type Description Default
items Class

The classes to remove

()
Source code in xsdata/codegen/mixins.py
84
85
86
87
88
89
90
@abc.abstractmethod
def remove(self, *items: Class):
    """Safely remove classes from the container.

    Args:
        items: The classes to remove
    """

extend(items) abstractmethod

Add a list of classes to the container.

Parameters:

Name Type Description Default
items List[Class]

The list of class instances to add

required
Source code in xsdata/codegen/mixins.py
92
93
94
95
96
97
98
@abc.abstractmethod
def extend(self, items: List[Class]):
    """Add a list of classes to the container.

    Args:
        items: The list of class instances to add
    """

reset(item, qname) abstractmethod

Update the given class qualified name.

Parameters:

Name Type Description Default
item Class

The target class instance to update

required
qname str

The new qualified name of the class

required
Source code in xsdata/codegen/mixins.py
100
101
102
103
104
105
106
107
@abc.abstractmethod
def reset(self, item: Class, qname: str):
    """Update the given class qualified name.

    Args:
        item: The target class instance to update
        qname: The new qualified name of the class
    """

set(items) abstractmethod

Set the list of classes to the container.

Parameters:

Name Type Description Default
items List[Class]

The list of classes

required
Source code in xsdata/codegen/mixins.py
109
110
111
112
113
114
115
@abc.abstractmethod
def set(self, items: List[Class]):
    """Set the list of classes to the container.

    Args:
        items: The list of classes
    """

HandlerInterface

Bases: ABC

Class handler interface.

Source code in xsdata/codegen/mixins.py
118
119
120
121
122
123
124
125
126
127
128
129
class HandlerInterface(abc.ABC):
    """Class handler interface."""

    __slots__ = ()

    @abc.abstractmethod
    def process(self, target: Class):
        """Process the given target class.

        Args:
            target: The target class instance
        """

process(target) abstractmethod

Process the given target class.

Parameters:

Name Type Description Default
target Class

The target class instance

required
Source code in xsdata/codegen/mixins.py
123
124
125
126
127
128
129
@abc.abstractmethod
def process(self, target: Class):
    """Process the given target class.

    Args:
        target: The target class instance
    """

RelativeHandlerInterface

Bases: HandlerInterface

An interface for codegen handlers with class container access.

Parameters:

Name Type Description Default
container ContainerInterface

The container instance

required
Source code in xsdata/codegen/mixins.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
class RelativeHandlerInterface(HandlerInterface, metaclass=ABCMeta):
    """An interface for codegen handlers with class container access.

    Args:
        container: The container instance
    """

    __slots__ = "container"

    def __init__(self, container: ContainerInterface):
        self.container = container

    def base_attrs(self, target: Class) -> List[Attr]:
        """Return a list of all parent attrs recursively.

        Args:
            target: The target class

        Returns:
            A list of attr instances.

        """
        attrs: List[Attr] = []
        for extension in target.extensions:
            base = self.container.find(extension.type.qname)

            assert base is not None

            for attr in base.attrs:
                attr.parent = base.qname
                attrs.append(attr)

            attrs.extend(self.base_attrs(base))

        return attrs

    @abc.abstractmethod
    def process(self, target: Class):
        """Process entrypoint for a class.

        Args:
            target: The target class instance
        """

base_attrs(target)

Return a list of all parent attrs recursively.

Parameters:

Name Type Description Default
target Class

The target class

required

Returns:

Type Description
List[Attr]

A list of attr instances.

Source code in xsdata/codegen/mixins.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def base_attrs(self, target: Class) -> List[Attr]:
    """Return a list of all parent attrs recursively.

    Args:
        target: The target class

    Returns:
        A list of attr instances.

    """
    attrs: List[Attr] = []
    for extension in target.extensions:
        base = self.container.find(extension.type.qname)

        assert base is not None

        for attr in base.attrs:
            attr.parent = base.qname
            attrs.append(attr)

        attrs.extend(self.base_attrs(base))

    return attrs

process(target) abstractmethod

Process entrypoint for a class.

Parameters:

Name Type Description Default
target Class

The target class instance

required
Source code in xsdata/codegen/mixins.py
168
169
170
171
172
173
174
@abc.abstractmethod
def process(self, target: Class):
    """Process entrypoint for a class.

    Args:
        target: The target class instance
    """

ContainerHandlerInterface

Bases: ABC

A codegen interface for processing the whole class container.

Parameters:

Name Type Description Default
container ContainerInterface

The class container instance

required
Source code in xsdata/codegen/mixins.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
class ContainerHandlerInterface(abc.ABC):
    """A codegen interface for processing the whole class container.

    Args:
        container: The class container instance
    """

    __slots__ = "container"

    def __init__(self, container: ContainerInterface):
        self.container = container

    @abc.abstractmethod
    def run(self):
        """Run the process for the whole container."""

run() abstractmethod

Run the process for the whole container.

Source code in xsdata/codegen/mixins.py
189
190
191
@abc.abstractmethod
def run(self):
    """Run the process for the whole container."""