Your IP : 216.73.216.52


Current Path : /usr/lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/landscape/lib/__pycache__/schema.cpython-38.pyc

U

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@s eZdZdZdd�Zdd�ZdS)�Constantz1Something that must be equal to a constant value.cCs
||_dS�N)�value��selfrr
r
r�__init__szConstant.__init__cCs ||jkrtd||jf��|S)Nz%r != %r)rrrr
r
r�coerces
zConstant.coerceN�rrrr	rrr
r
r
rr
src@s eZdZdZdd�Zdd�ZdS)�AnyzsSomething which must apply to any of a number of different schemas.

    @param schemas: Other schema objects.
    cGs
||_dSr
)�schemas)rrr
r
rrszAny.__init__c	CsH|jD]*}z|�|�WStk
r.YqXqtd||jf��dS)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 %sN)rrr)rr�schemar
r
rrs
�z
Any.coerceNrr
r
r
rrsrc@seZdZdZdd�ZdS)�Boolz!Something that must be a C{bool}.cCst|t�std|f��|S)Nz%r is not a bool)�
isinstance�boolrrr
r
rr-s
zBool.coerceN�rrrr	rr
r
r
rr+src@seZdZdZdd�ZdS)�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.coerceNrr
r
r
rr3src@seZdZdZdd�ZdS)�Floatz7Something that must be an C{int}, C{long}, or C{float}.cCs"t|tttf�std|f��|S)Nz%r isn't a float)rrr�floatrrr
r
rr=szFloat.coerceNrr
r
r
rr;src@seZdZdZdd�ZdS)�ByteszA binary string.cCst|t�std|f��|S)Nz%r isn't a bytestring)r�bytesrrr
r
rrEs
zBytes.coerceNrr
r
r
rrCsrc@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-8cCs
||_dSr
)�encoding)rr#r
r
rrSszUnicode.__init__c
Csnt|t�rRz|�|j�}Wn6tk
rP}ztd|t|�f��W5d}~XYnXt|t�sjtd|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@s eZdZdZdd�Zdd�ZdS)�ListznSomething which must be a C{list}.

    @param schema: The schema that all values of the list must match.
    cCs
||_dSr
�r�rrr
r
rrfsz
List.__init__cCs�t|t�std|f��t|�}t|�D]T\}}z|j�|�||<Wq(tk
rz}ztd||j|f��W5d}~XYq(Xq(|S)Nz%r is not a listz%r could not coerce with %s: %s)r�listr�	enumeraterr)rrZnew_list�iZsubvaluer'r
r
rris

��zList.coerceNrr
r
r
rr(asr(c@s eZdZdZdd�Zdd�ZdS)�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.
    cGs
||_dSr
r)r*r
r
rr~szTuple.__init__cCsxt|t�std|f��t|�t|j�krFtdt|j�t|�|f��g}t|j|�D]\}}|�|�|��qVt|�S)Nz%r is not a tuplezNeed %s items, got %s in %r)r�tupler�lenr�zip�appendr)rrZ	new_valuerr
r
rr�s
�zTuple.coerceNrr
r
r
rr.wsr.c@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 |dkrg}t|�|_||_dSr
)�set�optionalr)rrr5r
r
rr�s
zKeyDict.__init__c	Cs�i}t|t�std|f��t|�D]z\}}||jkrHtd||jf��z|j|�|�||<Wq$tk
r�}ztd|||j||f��W5d}~XYq$Xq$t|���}t|j���|j}||}|r�td|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�dictrrrrr4�keysr5)	rr�new_dict�k�vr'Znew_keysZ
required_keysZmissingr
r
rr�s,

���zKeyDict.coerce)Nrr
r
r
rr3�s
r3c@s eZdZdZdd�Zdd�ZdS)�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)rr=r>r
r
rr�sz
Dict.__init__cCsJt|t�std|f��i}|��D] \}}|j�|�||j�|�<q$|S)Nr6)rr7r�itemsr>rr=)rrr9r:r;r
r
rr�s
zDict.coerceNrr
r
r
rr<�sr<N)r	Ztwisted.python.compatrrr�	Exceptionr�objectrrrrrrr!r(r.r3r<r
r
r
r�<module>s$