HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/schema.cpython-310.pyc
o

�N�g���@sdZddlZddlZddlZddlmZdZdZGdd�d�Z	e	�Z
	dd	�Zee�e	_
[Gd
d�de�ZGdd
�d
e�ZGdd�ded�ZGdd�ded�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$e�ZGd%d&�d&e�ZGd'd(�d(e�ZGd)d*�d*e�ZGd+d,�d,e�ZGd-d.�d.e�Z Gd/d0�d0e�Z!Gd1d2�d2e�Z"Gd3d4�d4e�Z#Gd5d6�d6e#�Z$Gd7d8�d8e#�Z%Gd9d:�d:e�Z&Gd;d<�d<e�Z'Gd=d>�d>e�Z(Gd?d@�d@e�Z)dS)Aa,
    :codeauthor: Pedro Algarvio (pedro@algarvio.me)
    :codeauthor: Alexandru Bleotu (alexandru.bleotu@morganstanley.com)


    salt.utils.schema
    ~~~~~~~~~~~~~~~~~

    Object Oriented Configuration - JSON Schema compatible generator

    This code was inspired by `jsl`__, "A Python DSL for describing JSON
    schemas".

    .. __: https://jsl.readthedocs.io/


    A configuration document or configuration document section is defined using
    the py:class:`Schema`, the configuration items are defined by any of the
    subclasses of py:class:`BaseSchemaItem` as attributes of a subclass of
    py:class:`Schema` class.

    A more complex configuration document (containing a defininitions section)
    is defined using the py:class:`DefinitionsSchema`. This type of
    schema supports having complex configuration items as attributes (defined
    extending the py:class:`ComplexSchemaItem`). These items have other
    configuration items (complex or not) as attributes, allowing to verify
    more complex JSON data structures

    As an example:

    .. code-block:: python

        class HostConfig(Schema):
            title = 'Host Configuration'
            description = 'This is the host configuration'

            host = StringItem(
                'Host',
                'The looong host description',
                default=None,
                minimum=1
            )

            port = NumberItem(
                description='The port number',
                default=80,
                required=False,
                minimum=0,
                inclusiveMinimum=False,
                maximum=65535
            )

    The serialized version of the above configuration definition is:

    .. code-block:: python

        >>> print(HostConfig.serialize())
        OrderedDict([
            ('$schema', 'http://json-schema.org/draft-04/schema#'),
            ('title', 'Host Configuration'),
            ('description', 'This is the host configuration'),
            ('type', 'object'),
            ('properties', OrderedDict([
                ('host', {'minimum': 1,
                          'type': 'string',
                          'description': 'The looong host description',
                          'title': 'Host'}),
                ('port', {'description': 'The port number',
                          'default': 80,
                          'inclusiveMinimum': False,
                          'maximum': 65535,
                          'minimum': 0,
                          'type': 'number'})
            ])),
            ('required', ['host']),
            ('x-ordering', ['host', 'port']),
            ('additionalProperties', True)]
        )
        >>> print(salt.utils.json.dumps(HostConfig.serialize(), indent=2))
        {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "title": "Host Configuration",
            "description": "This is the host configuration",
            "type": "object",
            "properties": {
                "host": {
                    "minimum": 1,
                    "type": "string",
                    "description": "The looong host description",
                    "title": "Host"
                },
                "port": {
                    "description": "The port number",
                    "default": 80,
                    "inclusiveMinimum": false,
                    "maximum": 65535,
                    "minimum": 0,
                    "type": "number"
                }
            },
            "required": [
                "host"
            ],
            "x-ordering": [
                "host",
                "port"
            ],
            "additionalProperties": false
        }


    The serialized version of the configuration block can be used to validate a
    configuration dictionary using the `python jsonschema library`__.

    .. __: https://pypi.python.org/pypi/jsonschema

    .. code-block:: python

        >>> import jsonschema
        >>> jsonschema.validate({'host': 'localhost', 'port': 80}, HostConfig.serialize())
        >>> jsonschema.validate({'host': 'localhost', 'port': -1}, HostConfig.serialize())
        Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 478, in validate
            cls(schema, *args, **kwargs).validate(instance)
        File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 123, in validate
            raise error
        jsonschema.exceptions.ValidationError: -1 is less than the minimum of 0

        Failed validating 'minimum' in schema['properties']['port']:
            {'default': 80,
            'description': 'The port number',
            'inclusiveMinimum': False,
            'maximum': 65535,
            'minimum': 0,
            'type': 'number'}

        On instance['port']:
            -1
        >>>


    A configuration document can even be split into configuration sections. Let's reuse the above
    ``HostConfig`` class and include it in a configuration block:

    .. code-block:: python

        class LoggingConfig(Schema):
            title = 'Logging Configuration'
            description = 'This is the logging configuration'

            log_level = StringItem(
                'Logging Level',
                'The logging level',
                default='debug',
                minimum=1
            )

        class MyConfig(Schema):

            title = 'My Config'
            description = 'This my configuration'

            hostconfig = HostConfig()
            logconfig = LoggingConfig()


    The JSON Schema string version of the above is:

    .. code-block:: python

        >>> print salt.utils.json.dumps(MyConfig.serialize(), indent=4)
        {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "title": "My Config",
            "description": "This my configuration",
            "type": "object",
            "properties": {
                "hostconfig": {
                    "id": "https://non-existing.saltstack.com/schemas/hostconfig.json#",
                    "title": "Host Configuration",
                    "description": "This is the host configuration",
                    "type": "object",
                    "properties": {
                        "host": {
                            "minimum": 1,
                            "type": "string",
                            "description": "The looong host description",
                            "title": "Host"
                        },
                        "port": {
                            "description": "The port number",
                            "default": 80,
                            "inclusiveMinimum": false,
                            "maximum": 65535,
                            "minimum": 0,
                            "type": "number"
                        }
                    },
                    "required": [
                        "host"
                    ],
                    "x-ordering": [
                        "host",
                        "port"
                    ],
                    "additionalProperties": false
                },
                "logconfig": {
                    "id": "https://non-existing.saltstack.com/schemas/logconfig.json#",
                    "title": "Logging Configuration",
                    "description": "This is the logging configuration",
                    "type": "object",
                    "properties": {
                        "log_level": {
                            "default": "debug",
                            "minimum": 1,
                            "type": "string",
                            "description": "The logging level",
                            "title": "Logging Level"
                        }
                    },
                    "required": [
                        "log_level"
                    ],
                    "x-ordering": [
                        "log_level"
                    ],
                    "additionalProperties": false
                }
            },
            "additionalProperties": false
        }

        >>> import jsonschema
        >>> jsonschema.validate(
            {'hostconfig': {'host': 'localhost', 'port': 80},
             'logconfig': {'log_level': 'debug'}},
            MyConfig.serialize())
        >>> jsonschema.validate(
            {'hostconfig': {'host': 'localhost', 'port': -1},
             'logconfig': {'log_level': 'debug'}},
            MyConfig.serialize())
        Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 478, in validate
            cls(schema, *args, **kwargs).validate(instance)
        File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 123, in validate
            raise error
        jsonschema.exceptions.ValidationError: -1 is less than the minimum of 0

        Failed validating 'minimum' in schema['properties']['hostconfig']['properties']['port']:
            {'default': 80,
            'description': 'The port number',
            'inclusiveMinimum': False,
            'maximum': 65535,
            'minimum': 0,
            'type': 'number'}

        On instance['hostconfig']['port']:
            -1
        >>>

    If however, you just want to use the configuration blocks for readability
    and do not desire the nested dictionaries serialization, you can pass
    ``flatten=True`` when defining a configuration section as a configuration
    subclass attribute:

    .. code-block:: python

        class MyConfig(Schema):

            title = 'My Config'
            description = 'This my configuration'

            hostconfig = HostConfig(flatten=True)
            logconfig = LoggingConfig(flatten=True)


    The JSON Schema string version of the above is:

    .. code-block:: python

        >>> print(salt.utils.json.dumps(MyConfig, indent=4))
        {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "title": "My Config",
            "description": "This my configuration",
            "type": "object",
            "properties": {
                "host": {
                    "minimum": 1,
                    "type": "string",
                    "description": "The looong host description",
                    "title": "Host"
                },
                "port": {
                    "description": "The port number",
                    "default": 80,
                    "inclusiveMinimum": false,
                    "maximum": 65535,
                    "minimum": 0,
                    "type": "number"
                },
                "log_level": {
                    "default": "debug",
                    "minimum": 1,
                    "type": "string",
                    "description": "The logging level",
                    "title": "Logging Level"
                }
            },
            "x-ordering": [
                "host",
                "port",
                "log_level"
            ],
            "additionalProperties": false
        }
�N��OrderedDictz*https://non-existing.saltstack.com/schemas�Pc@seZdZdZdd�ZeZdS)�NullSentinelzt
    A class which instance represents a null value.
    Allows specifying fields with a default value of null.
    cCsdS)NF���selfrr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/schema.py�__bool__TszNullSentinel.__bool__N)�__name__�
__module__�__qualname__�__doc__r
Z__nonzero__rrrr	rNsrcOstd��)Nz*Can't create another NullSentinel instance)�	TypeError)�args�kwargsrrr	�_failing_newbsrc@s*eZdZedd��Zdd�Zd	dd�ZdS)
�
SchemaMetacC�t�S�Nr��mcs�name�basesrrr	�__prepare__k�zSchemaMeta.__prepare__cCs$d|d<d|d<d|d<i}i}g}t|�D]#}t|d�r#|�|j�t|d�r.|�|j�t|d�r9|�|j�q|��D]?\}}	d}
t|	d	�sOt|	d�sOq>t|	d	�rjt|	d
�ra|	jdura||	_|	j	pe|}
|	||
<t|	d�rx|	j
ps|}
|	||
<|�|
�q>||d<||d<||d<t�
||||�S)NTZ
__config__F�__flatten__�__config_name__�_items�	_sections�_order�__item__�title)�reversed�hasattr�updaterr�extendr �itemsr"�
__item_name__r�append�type�__new__)rrr�attrsr'Zsections�order�base�key�valueZ
entry_namerrr	r+os>


�



zSchemaMeta.__new__FcKsHt�|�}|�dd�|_|durd|_|durd|_|jdi|��|S)NrTr)�objectr+�poprr�__allow_additional_items__�__init__)�cls�flattenZallow_additional_itemsr�instancerrr	�__call__�s
zSchemaMeta.__call__N)FF)rrr
�classmethodrr+r8rrrr	rjs

*rc@s,eZdZdZedd��Zdd�Zdd�ZdS)	�BaseSchemaItemMetazJ
    Config item metaclass to "tag" the class as a configuration item
    cCrrrrrrr	r�rzBaseSchemaItemMeta.__prepare__c	Cs�d|d<d|d<g}t|�D]9}z.t|dg�}|r|�|�tjj�|j�jD]}|dks1||vr2q'|dkr7q'|�|�q'Wqt	yGYqw||d<t
�||||�S)NTr!r(�_attributesrr)r#�getattrr&�salt�utilsrZget_function_argspecr4r)rr*r+)rrrr,Z
attributesr.Zbase_attributes�argnamerrr	r+�s(
��zBaseSchemaItemMeta.__new__cOs�t�|�}|rtd��|��D]}|dkr|�|�|_q||jvr'|j�|�q|j|i|��t	t
�|��D]}t|dd�}|rN|j
jj|jurN|�
|�q7|�
�|S)NzRPlease pass all arguments as named arguments. Un-named arguments are not supportedr�__validate_attributes__)r1r+�RuntimeError�copyr2r(r;r)r4r#�inspectZgetmror<r@�__func__�__code__)r5rrr7r/r.Zvalidate_attributesrrr	r8�s.
�
��
�zBaseSchemaItemMeta.__call__N)rrr
rr9rr+r8rrrr	r:�s
r:c@sReZdZdZdZdZdZZZdZ	dZ
ed
dd��Zedd��Z
edd	��ZdS)�Schemaz(
    Configuration definition class
    NFcCsvt�}|durt�d|�d�|d<nd|d<|jdur |j|d<|jdur;|j|jkr6t�|j���|d<n|j|d<g}g}d|d	<t�}g|_|j	D]�}d
}d}||j
vr�|j
|}	|	�|	jduredn|�}
|	jdur�|�
|
d�d
|
vr|�|
d
�d|
vr�|�|
d�t|	d�r�|j�|	j�d}n|
||<||jvr�|j|}|jp�|}|jdur�|��}|j�|�d}n|��||<|jr�|�|�|d
ur�|dur�||vr�|�|�qL||vr�|�|�qL|r�||d<|j�r&i}
|jD]$}|��D]\}}||
v�rt|
|t��r|
|�|�q�||
|<q�q�|
�r&|
�
|�|
}|�r-||d<|�r4||d
<|j|d<|S)N�/z.json#�idz'http://json-schema.org/draft-04/schema#z$schemar"�descriptionr1r*FT�
propertiesz
x-ordering�required�after_items_update�additionalProperties)r�BASE_SCHEMA_URLr"rIr�textwrap�dedent�striprLr r�	serializerr%r&r$rr(r)rKr'�
isinstance�listr3)r5�id_�
serializedrKZorderingrJrZ
skip_orderZ	item_name�sectionZserialized_section�configZserialized_configrL�entry�datarrr	rR�s�






�







�
�

�
�

zSchema.serializecCsx|��}i}|d��D]-\}}d|vr|d||<qd|vr9|d��D]\}}d|vr7|d|�|i�|<q%qq|S)NrJ�default)rRr'�
setdefault)r5rV�defaultsr�detailsZsnameZsdetailsrrr	r]^s��zSchema.defaultscCs>|��}|�dg�}|dD]}||vr|�|�qt|d�S)NrKrJ)�requirements)rR�getr)�RequirementsItem)r5Zserialized_schemarKrrrr	�as_requirements_itemms
�
zSchema.as_requirements_itemr)rrr
rr"rIrrr rr3r9rRr]rbrrrr	rF�s`
rF)�	metaclassc@sJeZdZdZdZdZdZdZdZdZ	ddd�Z
dd�Zdd	�Zd
d�Z
dS)
�
SchemaItem�R
    Base configuration items class.

    All configurations must subclass it
    NFcKs|dur||_||_dS)z`
        :param required: If the configuration item is required. Defaults to ``False``.
        N)rK�extra)rrKrfrrr	r4�s
zSchemaItem.__init__cCs|jdvr	td��dS)a
        Run any validation check you need the instance attributes.

        ATTENTION:

        Don't call the parent class when overriding this
        method because it will just duplicate the executions. This class'es
        metaclass will take care of that.
        )TFz!'required' can only be True/FalseN)rKrArrrr	r@�s

�z"SchemaItem.__validate_attributes__cCstt|d|�d�d�}|durt|�r|�}|durt||d�}|dur-t|d|�d�d�}|dur8|j�|d�}|S)zP
        Return the argname value looking up on all possible attributes
        Z__get_�__N)r<�callablerfr`)rr?�argvaluerrr	�_get_argname_value�szSchemaItem._get_argname_valuecCst�)�C
        Return a serializable form of the config instance
        )�NotImplementedErrorrrrr	rR�szSchemaItem.serializer)rrr
r�__type__�
__format__r;r�__serialize_attr_aliases__rKr4r@rjrRrrrr	rd�s

rdcsXeZdZdZdZdZdZdZdZ					d�fdd�	Z	dd�Z
dd�Zd	d
�Z�Z
S)�BaseSchemaItemreNc�\|dur||_|dur||_|dur||_|dur||_|dur#||_t�jdi|��dS)aA
        :param required:
            If the configuration item is required. Defaults to ``False``.
        :param title:
            A short explanation about the purpose of the data described by this item.
        :param description:
            A detailed explanation about the purpose of the data described by this item.
        :param default:
            The default value for this configuration item. May be :data:`.Null` (a special value
            to set the default value to null).
        :param enum:
            A list(list, tuple, set) of valid choices.
        Nr)r"rIr[�enum�	enumNames�superr4)rr"rIr[rrrsr��	__class__rr	r4�szBaseSchemaItem.__init__cCs�|jdurt|jtttf�std��t|jt�st|j�|_|jdurLt|jtttf�s0td��t|j�t|j�kr>td��t|jt�sNt|j�|_dSdSdS)NzLOnly the 'list', 'tuple' and 'set' python types can be used to define 'enum'zQOnly the 'list', 'tuple' and 'set' python types can be used to define 'enumNames'z5The size of 'enumNames' must match the size of 'enum')rrrSrT�tuple�setrArs�lenrrrr	r@�s(
�
���
z&BaseSchemaItem.__validate_attributes__cCsdd|ji}|jD]'}|dkrq|�|�}|dur/|turd}|jr+||jvr+|j|}|||<q|S)rkr*rKN)rmr;rj�Nullro)rrVr?rirrr	rRs


�

�zBaseSchemaItem.serializecCs0|jdur|j|jkrt�|j���S|jSdSr)rIrrOrPrQrrrr	�__get_description__,s

�z"BaseSchemaItem.__get_description__�NNNNN)rrr
rrIr"r[rrrsr4r@rRr{�
__classcell__rrrur	rp�s �"rpc@�eZdZdZdS)�NullItem�nullN�rrr
rmrrrr	rR�rc@r~)�BooleanItemZbooleanNr�rrrr	r�W�r�csPeZdZdZdZddd�ZdZdZdZdZ					d�fdd�	Z
d	d
�Z�ZS)�
StringItemz&
    A string configuration field
    �stringZ	minLengthZ	maxLength)�
min_length�
max_lengthNcsN|dur||_|dur||_|dur||_|dur||_t�jdi|��dS)a�
        :param required:
            If the configuration item is required. Defaults to ``False``.
        :param title:
            A short explanation about the purpose of the data described by this item.
        :param description:
            A detailed explanation about the purpose of the data described by this item.
        :param default:
            The default value for this configuration item. May be :data:`.Null` (a special value
            to set the default value to null).
        :param enum:
            A list(list, tuple, set) of valid choices.
        :param format:
            A semantic format of the string (for example, ``"date-time"``, ``"email"``, or ``"uri"``).
        :param pattern:
            A regular expression (ECMA 262) that a string value must match.
        :param min_length:
            The minimum length
        :param max_length:
            The maximum length
        Nr)�format�patternr�r�rtr4)rr�r�r�r�rrurr	r4iszStringItem.__init__cCs(|jdur|jdur|j|_dSdSdSr)r�rnrrrr	r@�s�z"StringItem.__validate_attributes__)NNNN)
rrr
rrmror�r�r�r�r4r@r}rrrur	r�[s
�'r�c@�eZdZdZdZdS)�	EMailItemzt
    An internet email address, see `RFC 5322, section 3.4.1`__.

    .. __: http://tools.ietf.org/html/rfc5322
    �emailN�rrr
rrnrrrr	r���r�c@r�)�IPv4Itemz�
    An IPv4 address configuration field, according to dotted-quad ABNF syntax as defined in
    `RFC 2673, section 3.2`__.

    .. __: http://tools.ietf.org/html/rfc2673
    Zipv4Nr�rrrr	r��sr�c@r�)�IPv6Itemz�
    An IPv6 address configuration field, as defined in `RFC 2373, section 2.2`__.

    .. __: http://tools.ietf.org/html/rfc2373
    Zipv6Nr�rrrr	r��r�r�c@r�)�HostnameItemz�
    An Internet host name configuration field, see `RFC 1034, section 3.1`__.

    .. __: http://tools.ietf.org/html/rfc1034
    �hostnameNr�rrrr	r��r�r�c@r�)�DateTimeItemz�
    An ISO 8601 formatted date-time configuration field, as defined by `RFC 3339, section 5.6`__.

    .. __: http://tools.ietf.org/html/rfc3339
    z	date-timeNr�rrrr	r��r�r�c@r�)�UriItemz�
    A universal resource identifier (URI) configuration field, according to `RFC3986`__.

    .. __: http://tools.ietf.org/html/rfc3986
    ZuriNr�rrrr	r��r�r�c@r�)�
SecretItemza
    A string configuration field containing a secret, for example, passwords, API keys, etc
    ZsecretNr�rrrr	r��sr�csLeZdZdZdddd�ZdZdZdZdZdZ						d	�fdd�	Z
�ZS)
�
NumberItem�numberZ
multipleOfZexclusiveMinimumZexclusiveMaximum)�multiple_of�exclusive_minimum�exclusive_maximumNcrq)a�
        :param required:
            If the configuration item is required. Defaults to ``False``.
        :param title:
            A short explanation about the purpose of the data described by this item.
        :param description:
            A detailed explanation about the purpose of the data described by this item.
        :param default:
            The default value for this configuration item. May be :data:`.Null` (a special value
            to set the default value to null).
        :param enum:
            A list(list, tuple, set) of valid choices.
        :param multiple_of:
            A value must be a multiple of this factor.
        :param minimum:
            The minimum allowed value
        :param exclusive_minimum:
            Whether a value is allowed to be exactly equal to the minimum
        :param maximum:
            The maximum allowed value
        :param exclusive_maximum:
            Whether a value is allowed to be exactly equal to the maximum
        Nr)r��minimumr��maximumr�rtr4)rr�r�r�r�r�rrurr	r4�s zNumberItem.__init__r|)rrr
rmror�r�r�r�r�r4r}rrrur	r��s"��r�c@r~)�IntegerItem�integerNr�rrrr	r�r�r�cs^eZdZdZddddd�ZdZdZdZdZdZ						d�fdd	�	Z
d
d�Zdd
�Z�Z
S)�	ArrayItem�arrayZminItemsZmaxItemsZuniqueItemsZadditionalItems)�	min_items�	max_items�unique_items�additional_itemsNcrq)a�
        :param required:
            If the configuration item is required. Defaults to ``False``.
        :param title:
            A short explanation about the purpose of the data described by this item.
        :param description:
            A detailed explanation about the purpose of the data described by this item.
        :param default:
            The default value for this configuration item. May be :data:`.Null` (a special value
            to set the default value to null).
        :param enum:
            A list(list, tuple, set) of valid choices.
        :param items:
            Either of the following:
                * :class:`BaseSchemaItem` -- all items of the array must match the field schema;
                * a list or a tuple of :class:`fields <.BaseSchemaItem>` -- all items of the array must be
                  valid according to the field schema at the corresponding index (tuple typing);
        :param min_items:
            Minimum length of the array
        :param max_items:
            Maximum length of the array
        :param unique_items:
            Whether all the values in the array must be distinct.
        :param additional_items:
            If the value of ``items`` is a list or a tuple, and the array length is larger than
            the number of fields in ``items``, then the additional items are described
            by the :class:`.BaseField` passed using this argument.
        :type additional_items: bool or :class:`.BaseSchemaItem`
        Nr)r'r�r�r�r�rtr4)rr'r�r�r�r�rrurr	r4+s&zArrayItem.__init__cCs�|js
|js
td��|jdurAt|jttf�r/|jD]}t|ttf�s,td�t	|����qdSt|jttf�sCtd�t	|j����dSdS)Nz0One of items or additional_items must be passed.zsAll items passed in the item argument tuple/list must be a subclass of Schema, SchemaItem or BaseSchemaItem, not {}z\The items argument passed must be a subclass of Schema, SchemaItem or BaseSchemaItem, not {})
r'r�rArSrTrwrFrdr�r*�r�itemrrr	r@]s&


�����	z!ArrayItem.__validate_attributes__cCsPt|jttf�r
|j��St|jttf�r&g}|jD]	}|�|���q|SdSr)rSr'rFrdrRrwrTr))rr'r�rrr	�
__get_items__ps

�zArrayItem.__get_items__r|)rrr
rmror'r�r�r�r�r4r@r�r}rrrur	r�s(��2r�cs�eZdZdZddddd�ZdZdZdZdZdZ						d�fdd	�	Z
d
d�Zdd
�Zdd�Z
dd�Zddd�Z�fdd�Z�ZS)�DictItemr1Z
minPropertiesZ
maxPropertiesZpatternPropertiesrM)�min_properties�max_properties�pattern_properties�additional_propertiesNcrq)a~
        :param required:
            If the configuration item is required. Defaults to ``False``.
        :type required:
            boolean
        :param title:
            A short explanation about the purpose of the data described by this item.
        :type title:
            str
        :param description:
            A detailed explanation about the purpose of the data described by this item.
        :param default:
            The default value for this configuration item. May be :data:`.Null` (a special value
            to set the default value to null).
        :param enum:
            A list(list, tuple, set) of valid choices.
        :param properties:
            A dictionary containing fields
        :param pattern_properties:
            A dictionary whose keys are regular expressions (ECMA 262).
            Properties match against these regular expressions, and for any that match,
            the property is described by the corresponding field schema.
        :type pattern_properties: dict[str -> :class:`.Schema` or
                                       :class:`.SchemaItem` or :class:`.BaseSchemaItem`]
        :param additional_properties:
            Describes properties that are not described by the ``properties`` or ``pattern_properties``.
        :type additional_properties: bool or :class:`.Schema` or :class:`.SchemaItem`
                                     or :class:`.BaseSchemaItem`
        :param min_properties:
            A minimum number of properties.
        :type min_properties: int
        :param max_properties:
            A maximum number of properties
        :type max_properties: int
        Nr)rJr�r�r�r�rtr4)rrJr�r�r�r�rrurr	r4�s,zDictItem.__init__cCs"|js
|js
|js
td��|jdurEt|jttf�s$td�t|j����t|jt�sE|j�	�D]\}}t|tt
f�sDtd�|t|����q/|jdurut|jt�sZtd�t|j����|j�	�D]\}}t|tt
f�sttd�|t|����q_|jdur�t|jttt
f�s�td�t|j����dSdS)NzMOne of properties, pattern_properties or additional_properties must be passedzDThe passed properties must be passed as a dict or  a Schema not '{}'zdThe passed property who's key is '{}' must be of type Schema, SchemaItem or BaseSchemaItem, not '{}'z?The passed pattern_properties must be passed as a dict not '{}'zlThe passed pattern_property who's key is '{}' must be of type Schema, SchemaItem or BaseSchemaItem, not '{}'zeThe passed additional_properties must be of type bool, Schema, SchemaItem or BaseSchemaItem, not '{}')rJr�r�rArSrF�dictr�r*r'rd�bool)rr/�proprrr	r@�s\����
���
���
���z DictItem.__validate_attributes__cCsR|jdurdSt|jt�r|j��dSt�}|j��D]
\}}|��||<q|S)NrJ)rJrSrFrRrr')rrJr/r�rrr	�__get_properties__�s
zDictItem.__get_properties__cCs8|jdurdSt�}|j��D]
\}}|��||<q|Sr)r�rr'rR)rr�r/r�rrr	�__get_pattern_properties__�s
z#DictItem.__get_pattern_properties__cCs*|jdurdSt|jt�r|jS|j��Sr)r�rSr�rRrrrr	�__get_additional_properties__s


z&DictItem.__get_additional_properties__FcC�
||_|Sr�r�rr6rrr	r8�zDictItem.__call__cszt���}g}|jdur5t|jt�r#|j��}d|vr"|�|d�n|j��D]\}}|jr4|�|�q(|r;||d<|S�NrK)	rtrRrJrSrFr&r'rKr))r�resultrKrVr/r�rurr	rRs


�
�zDictItem.serializer|�F)rrr
rmrorJr�r�r�r�r4r@r�r�r�r8rRr}rrrur	r�|s0��8.

r�c�6eZdZdZdZd	�fdd�	Zdd�Zdd�Z�ZS)
rar1Nc�|dur||_t���dSr)r_rtr4)rr_rurr	r4&�zRequirementsItem.__init__cCs�|jdur	td��t|jttttf�std�|j���t|jt�sIt|jt�s-t|j�|_t|j�D]\}}t|t	ftf�sHtd�|t
|����q2dSdS)Nz)The passed requirements must not be emptyzcThe passed requirements must be passed as a list, tuple, set SchemaItem or BaseSchemaItem, not '{}'zRThe passed requirement at the {} index must be of type str or SchemaItem, not '{}')r_rArSrdrTrwrxr��	enumerate�strr*�r�idxr�rrr	r@+s&
����z(RequirementsItem.__validate_attributes__cCsZt|jt�r|j��}d|iSg}|jD]}t|t�r#|�|���q|�|�qd|iSr�)rSr_rdrRr))rr_Zrequirementrrr	rR?s
�

zRequirementsItem.serializer)	rrr
rmr_r4r@rRr}rrrur	ra!sracs@eZdZdZdZd�fdd�	Zdd�Zd
dd	�Zd
d�Z�Z	S)�	OneOfItemZoneOfNcs |dur||_t�j|d�dS)N�rK)r'rtr4)rr'rKrurr	r4RszOneOfItem.__init__cCs�|jstd��t|jttf�std�t|j����t|j�D]\}}t|tt	f�s3td�|t|����qt|jt�sBt|j�|_dSdS)Nz"The passed items must not be emptyz8The passed items must be passed as a list/tuple not '{}'z^The passed item at the {} index must be of type Schema, SchemaItem or BaseSchemaItem, not '{}')
r'rArSrTrwr�r*r�rFrdr�rrr	r@Ws$�����z!OneOfItem.__validate_attributes__FcCr�rr�r�rrr	r8jr�zOneOfItem.__call__cCs|jdd�|jD�iS)NcSsg|]}|���qSr)rR)�.0�irrr	�
<listcomp>osz'OneOfItem.serialize.<locals>.<listcomp>)rmr'rrrr	rRnszOneOfItem.serialize�NNr�)
rrr
rmr'r4r@r8rRr}rrrur	r�Ls
r�c@r~)�	AnyOfItemZanyOfNr�rrrr	r�rr�r�c@r~)�	AllOfItemZallOfNr�rrrr	r�wr�r�cr�)
�NotItem�notNcr�r)r�rtr4r�rurr	r4�r�zNotItem.__init__cCs6|jstd��t|jttf�std�t|j����dS)NzAn item must be passedzIThe passed item be of type Schema, SchemaItem or BaseSchemaItem, not '{}')r�rArSrFrdr�r*rrrr	r@�s��zNotItem.__validate_attributes__cCs|j|j��iSr)rmr�rRrrrr	rR�szNotItem.serializer)	rrr
rmr�r4r@rRr}rrrur	r�|s	r�c@r�)�PortItemri��N)rrr
r�r�rrrr	r��sr�csZeZdZdZgZdZd�fdd�	Zdd�Zedd��Z	d	d
�Z
�fdd�Zd
d�Z�Z
S)�ComplexSchemaItemz>
    .. versionadded:: 2016.11.0

    Complex Schema Item
    Ncs2t�j|d�d|_|r|n|jj|_|��dS)Nr�r1)rtr4rmrvr�_definition_name�_add_missing_schema_attributes)r�definition_namerKrurr	r4�s
�zComplexSchemaItem.__init__cCsLdd�t|�D�D]}t||�}tt||�t�r#||jvr#|j�|�q	dS)z�
        Adds any missed schema attributes to the _attributes list

        The attributes can be class attributes and they won't be
        included in the _attributes list automatically
        cSsg|]	}|�d�s|�qS)rg)�
startswith)r��attrrrr	r��szDComplexSchemaItem._add_missing_schema_attributes.<locals>.<listcomp>N)�dirr<rSrdr;r))rr�Zattr_valrrr	r��s
�
��z0ComplexSchemaItem._add_missing_schema_attributescCs|jSr)r�rrrr	r��rz!ComplexSchemaItem.definition_namecCsdd|j��iS)zc
        The serialization of the complex item is a pointer to the item
        definition
        z$refz#/definitions/)r�rrrr	rR�szComplexSchemaItem.serializecs�t���}|d=|j|d<i}g}|jD]&}t||�}|r:t|t�r:||=|��||<|j||d<|jr:|�	|�q|�
d�durFi|d<|d�|�|rS||d<|S)z*Returns the definition of the complex itemr�r"r*rJNrK)rtrRr�r;r<rSrprmrKr)r`r%)rrVrJZrequired_attr_names�	attr_namer�rurr	�get_definition�s(




�z ComplexSchemaItem.get_definitioncs�fdd��jD�S)z.Returns a dictionary of the complex attributescs&g|]}tt�|�t�rt�|��qSr)rSr<r�)r�r�rrr	r��s��z7ComplexSchemaItem.get_complex_attrs.<locals>.<listcomp>)r;rrrr	�get_complex_attrs�s
�z#ComplexSchemaItem.get_complex_attrsr�)rrr
rr;r�r4r��propertyr�rRr�r�r}rrrur	r��s

r�cs&eZdZdZed�fdd�	�Z�ZS)�DefinitionsSchemaa
    .. versionadded:: 2016.11.0

    JSON schema class that supports ComplexSchemaItem objects by adding
    a definitions section to the JSON schema, containing the item definitions.

    All references to ComplexSchemaItems are built using schema inline
    dereferencing.
    Ncs�t��|�}g}|j��}t|�}|rb|�d�}t|t�r)|�|�|�	|�
��t|t�r5|�	|j�n+t|t
�rA|�|j�nt|t�r`|jrQ|�	|j���|jr`t|jt�r`|�|j�|st�}|D]}t|t�ru|��||j<qg||d<|S)Nr�definitions)rtrRr�valuesrTr2rSr�r)r&r�r�r'r�r�rJr�rdrr�r�)r5rUrVZ
complex_itemsZ	aux_itemsr�r�rXrurr	rR�s8






��
�zDefinitionsSchema.serializer)rrr
rr9rRr}rrrur	r��s
r�)*rrCrOZsalt.utils.argsr=Zsalt.utils.odictrrNZ#RENDER_COMMENT_YAML_MAX_LINE_LENGTHrrzr�staticmethodr+r*rr:rFrdrprr�r�r�r�r�r�r�r�r�r�r�r�r�rar�r�r�r�r�r�r�rrrr	�<module>sZC
@G@:




=a&+&W