HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/landscape/lib/__pycache__/schema.cpython-310.pyc
o

y)�]��@s�dZddlmZmZmZGdd�de�ZGdd�de�ZGdd�de�Z	Gd	d
�d
e�Z
Gdd�de�ZGd
d�de�ZGdd�de�Z
Gdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)z"A schema system. Yes. Another one!�)�	iteritems�unicode�longc@seZdZdZdS)�InvalidErrorz&Raised when invalid input is received.N)�__name__�
__module__�__qualname__�__doc__�r
r
�6/usr/lib/python3/dist-packages/landscape/lib/schema.pyrsrc@� eZdZdZdd�Zdd�ZdS)�Constantz1Something that must be equal to a constant value.cC�
||_dS�N)�value��selfrr
r
r�__init__�
zConstant.__init__cCs ||jkrtd||jf��|S)Nz%r != %r)rrrr
r
r�coerces
zConstant.coerceN�rrrr	rrr
r
r
rr

sr
c@r)�AnyzsSomething which must apply to any of a number of different schemas.

    @param schemas: Other schema objects.
    cGrr)�schemas)rrr
r
rrrzAny.__init__c	Cs@|jD]}z|�|�WStyYqwtd||jf��)z�
        The result of the first schema which doesn't raise
        L{InvalidError} from its C{coerce} method will be returned.
        z!%r did not match any schema in %s)rrr)rr�schemar
r
rrs
��z
Any.coerceNrr
r
r
rr�rc@�eZdZdZdd�ZdS)�Boolz!Something that must be a C{bool}.cC�t|t�std|f��|S)Nz%r is not a bool)�
isinstance�boolrrr
r
rr-�
zBool.coerceN�rrrr	rr
r
r
rr+�rc@r)�Intz,Something that must be an C{int} or C{long}.cCs t|ttf�std|f��|S)Nz%r isn't an int or long)r�intrrrr
r
rr5sz
Int.coerceNr!r
r
r
rr#3r"r#c@r)�Floatz7Something that must be an C{int}, C{long}, or C{float}.cCs"t|tttf�std|f��|S)Nz%r isn't a float)rr$r�floatrrr
r
rr=szFloat.coerceNr!r
r
r
rr%;r"r%c@r)�ByteszA binary string.cCr)Nz%r isn't a bytestring)r�bytesrrr
r
rrEr zBytes.coerceNr!r
r
r
rr'Cr"r'c@s"eZdZdZddd�Zdd�ZdS)	�Unicodez�Something that must be a C{unicode}.

    If the value is a C{str}, it will automatically be decoded.

    @param encoding: The encoding to automatically decode C{str}s with.
    �utf-8cCrr)�encoding)rr+r
r
rrSrzUnicode.__init__c
Csdt|t�r$z|�|j�}Wnty#}z
td|t|�f��d}~wwt|t�s0td|f��|S)Nz%r can't be decoded: %sz%r isn't a unicode)rr(�decoder+�UnicodeDecodeErrorr�strr)rr�er
r
rrVs
��
zUnicode.coerceN)r*rr
r
r
rr)Ks
r)c@r)�ListznSomething which must be a C{list}.

    @param schema: The schema that all values of the list must match.
    cCrr�r�rrr
r
rrfrz
List.__init__cCsvt|t�std|f��t|�}t|�D]$\}}z
|j�|�||<Wqty8}z
td||j|f��d}~ww|S)Nz%r is not a listz%r could not coerce with %s: %s)r�listr�	enumeraterr)rr�new_list�i�subvaluer/r
r
rris

����zList.coerceNrr
r
r
rr0arr0c@r)�Tuplez�Something which must be a fixed-length tuple.

    @param schema: A sequence of schemas, which will be applied to
        each value in the tuple respectively.
    cGrrr1r2r
r
rr~rzTuple.__init__cCsxt|t�std|f��t|�t|j�kr#tdt|j�t|�|f��g}t|j|�D]\}}|�|�|��q+t|�S)Nz%r is not a tuplezNeed %s items, got %s in %r)r�tupler�lenr�zip�appendr)rr�	new_valuerr
r
rr�s
�zTuple.coerceNrr
r
r
rr8wsr8c@s"eZdZdZddd�Zdd�ZdS)�KeyDictz�Something which must be a C{dict} with defined keys.

    The keys must be constant and the values must match a per-key schema.

    @param schema: A dict mapping keys to schemas that the values of those
        keys must match.
    NcCs |durg}t|�|_||_dSr)�set�optionalr)rrr@r
r
rr�s

zKeyDict.__init__c	Cs�i}t|t�std|f��t|�D]7\}}||jvr$td||jf��z|j|�|�||<WqtyI}z
td|||j||f��d}~wwt|���}t|j���|j}||}|rgtd|f��|S)N�%r is not a dict.z%r is not a valid key as per %rz7Value of %r key of dict %r could not coerce with %s: %szMissing keys %s)	r�dictrrrrr?�keysr@)	rr�new_dict�k�vr/�new_keys�
required_keys�missingr
r
rr�s0

�����zKeyDict.coercerrr
r
r
rr>�s
r>c@r)�Dictz�Something which must be a C{dict} with arbitrary keys.

    @param key_schema: The schema that keys must match.
    @param value_schema: The schema that values must match.
    cCs||_||_dSr)�
key_schema�value_schema)rrKrLr
r
rr�s
z
Dict.__init__cCsJt|t�std|f��i}|��D]\}}|j�|�||j�|�<q|S)NrA)rrBr�itemsrLrrK)rrrDrErFr
r
rr�s
zDict.coerceNrr
r
r
rrJ�srJN)r	�twisted.python.compatrrr�	Exceptionr�objectr
rrr#r%r'r)r0r8r>rJr
r
r
r�<module>s$