ó Ú_e[c @s3ddlZddlmZddddddd d d g Zd efd „ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZ defd„ƒYZ defd„ƒYZ d efd„ƒYZ defd„ƒYZ d e fd„ƒYZd e fd„ƒYZdS(iÿÿÿÿN(terrortSingleValueConstrainttContainedSubtypeConstrainttValueRangeConstrainttValueSizeConstrainttPermittedAlphabetConstrainttInnerTypeConstrainttConstraintsExclusiontConstraintsIntersectiontConstraintsUniontAbstractConstraintcBsºeZd„Zdd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z e j d d kryd „Zn d „Zd „Zd„Zd„Zd„Zd„Zd„ZRS(cGs;tƒ|_|j|ƒt|jj|jfƒ|_dS(N(tsett _valueMapt _setValuesthasht __class__t__name__t_valuest_AbstractConstraint__hash(tselftvalues((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__init__s  cCs_|js dSy|j||ƒWn7tjk rZtjd|tjƒdfƒ‚nXdS(Ns%s failed at: %ri(Rt _testValueRtValueConstraintErrortsystexc_info(Rtvaluetidx((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__call__s cCscd|jjt|ƒf}|jr[|ddjg|jD]}t|ƒ^q;ƒ7}nd|S(Ns%s object at 0x%xs consts %ss, s<%s>(RRtidRtjointrepr(Rtrepresentationtx((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__repr__'s 6cCs||krtp|j|kS(N(tTrueR(Rtother((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__eq__/scCs |j|kS(N(R(RR$((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__ne__2scCs |j|kS(N(R(RR$((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__lt__5scCs |j|kS(N(R(RR$((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__le__8scCs |j|kS(N(R(RR$((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__gt__;scCs |j|kS(N(R(RR$((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__ge__>siicCs|jrtptS(N(RR#tFalse(R((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt __nonzero__BscCs|jrtptS(N(RR#R+(R((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__bool__EscCs|jS(N(R(R((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__hash__HscCs ||_dS(N(R(RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR KscCstj|ƒ‚dS(N(RR(RRR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRNscCs|jS(N(R (R((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt getValueMapRscCs2||kp1|j p1||kp1||jƒkS(N(RR/(RtotherConstraint((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt isSuperTypeOfUs   cCs,||kp+| p+||kp+||jkS(N(R (RR0((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt isSubTypeOf\s  N(Rt __module__RtNoneRR"R%R&R'R(R)R*Rt version_infoR,R-R.R RR/R1R2(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR s$               cBs eZdZd„Zd„ZRS(sCreate a SingleValueConstraint object. The SingleValueConstraint satisfies any value that is present in the set of permitted values. The SingleValueConstraint object can be applied to any ASN.1 type. Parameters ---------- \*values: :class:`int` Full set of values permitted by this constraint object. Examples -------- .. code-block:: python class DivisorOfSix(Integer): ''' ASN.1 specification: Divisor-Of-6 ::= INTEGER (1 | 2 | 3 | 6) ''' subtypeSpec = SingleValueConstraint(1, 2, 3, 6) # this will succeed divisor_of_six = DivisorOfSix(1) # this will raise ValueConstraintError divisor_of_six = DivisorOfSix(7) cCs||_t|ƒ|_dS(N(RR t_set(RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR ƒs cCs%||jkr!tj|ƒ‚ndS(N(R6RR(RRR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR‡s(RR3t__doc__R R(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRcs cBseZdZd„ZRS(sÂCreate a ContainedSubtypeConstraint object. The ContainedSubtypeConstraint satisfies any value that is present in the set of permitted values and also satisfies included constraints. The ContainedSubtypeConstraint object can be applied to any ASN.1 type. Parameters ---------- \*values: Full set of values and constraint objects permitted by this constraint object. Examples -------- .. code-block:: python class DivisorOfEighteen(Integer): ''' ASN.1 specification: Divisors-of-18 ::= INTEGER (INCLUDES Divisors-of-6 | 9 | 18) ''' subtypeSpec = ContainedSubtypeConstraint( SingleValueConstraint(1, 2, 3, 6), 9, 18 ) # this will succeed divisor_of_eighteen = DivisorOfEighteen(9) # this will raise ValueConstraintError divisor_of_eighteen = DivisorOfEighteen(10) cCsXxQ|jD]F}t|tƒr/|||ƒq ||jkr tj|ƒ‚q q WdS(N(Rt isinstanceR R6RR(RRRt constraint((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR°s (RR3R7R(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRŒs#cBs eZdZd„Zd„ZRS(s{Create a ValueRangeConstraint object. The ValueRangeConstraint satisfies any value that falls in the range of permitted values. The ValueRangeConstraint object can only be applied to :class:`~pyasn1.type.univ.Integer` and :class:`~pyasn1.type.univ.Real` types. Parameters ---------- start: :class:`int` Minimum permitted value in the range (inclusive) end: :class:`int` Maximum permitted value in the range (inclusive) Examples -------- .. code-block:: python class TeenAgeYears(Integer): ''' ASN.1 specification: TeenAgeYears ::= INTEGER (13 .. 19) ''' subtypeSpec = ValueRangeConstraint(13, 19) # this will succeed teen_year = TeenAgeYears(18) # this will raise ValueConstraintError teen_year = TeenAgeYears(20) cCs4||jks||jkr0tj|ƒ‚ndS(N(tstarttstopRR(RRR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRÜscCs”t|ƒdkr1tjd|jjfƒ‚n|\|_|_|j|jkr€tjd|jj|j|jfƒ‚ntj||ƒdS(Nis%s: bad constraint valuess5%s: screwed constraint values (start > stop): %s > %s( tlenRt PyAsn1ErrorRRR:R;R R (RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR às (RR3R7RR (((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR¸s# cBseZdZd„ZRS(sCreate a ValueSizeConstraint object. The ValueSizeConstraint satisfies any value for as long as its size falls within the range of permitted sizes. The ValueSizeConstraint object can be applied to :class:`~pyasn1.type.univ.BitString`, :class:`~pyasn1.type.univ.OctetString` (including all :ref:`character ASN.1 types `), :class:`~pyasn1.type.univ.SequenceOf` and :class:`~pyasn1.type.univ.SetOf` types. Parameters ---------- minimum: :class:`int` Minimum permitted size of the value (inclusive) maximum: :class:`int` Maximum permitted size of the value (inclusive) Examples -------- .. code-block:: python class BaseballTeamRoster(SetOf): ''' ASN.1 specification: BaseballTeamRoster ::= SET SIZE (1..25) OF PlayerNames ''' componentType = PlayerNames() subtypeSpec = ValueSizeConstraint(1, 25) # this will succeed team = BaseballTeamRoster() team.extend(['Jan', 'Matej']) encode(team) # this will raise ValueConstraintError team = BaseballTeamRoster() team.extend(['Jan'] * 26) encode(team) Note ---- Whenever ValueSizeConstraint is applied to mutable types (e.g. :class:`~pyasn1.type.univ.SequenceOf`, :class:`~pyasn1.type.univ.SetOf`), constraint validation only happens at the serialisation phase rather than schema instantiation phase (as it is with immutable types). cCs@t|ƒ}||jks*||jkr<tj|ƒ‚ndS(N(R<R:R;RR(RRRt valueSize((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR&s (RR3R7R(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRğs5cBs eZdZd„Zd„ZRS(sÇCreate a PermittedAlphabetConstraint object. The PermittedAlphabetConstraint satisfies any character string for as long as all its characters are present in the set of permitted characters. The PermittedAlphabetConstraint object can only be applied to the :ref:`character ASN.1 types ` such as :class:`~pyasn1.type.char.IA5String`. Parameters ---------- \*alphabet: :class:`str` Full set of characters permitted by this constraint object. Examples -------- .. code-block:: python class BooleanValue(IA5String): ''' ASN.1 specification: BooleanValue ::= IA5String (FROM ('T' | 'F')) ''' subtypeSpec = PermittedAlphabetConstraint('T', 'F') # this will succeed truth = BooleanValue('T') truth = BooleanValue('TF') # this will raise ValueConstraintError garbage = BooleanValue('TAF') cCs||_t|ƒ|_dS(N(RR R6(RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR Os cCs(|jj|ƒs$tj|ƒ‚ndS(N(R6t issupersetRR(RRR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRSs(RR3R7R R(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR,s" cBs eZdZd„Zd„ZRS(s4Value must satisfy the type and presence constraintscCs…|jr|j|ƒnh|jr||jkrCtj|ƒ‚n|j|\}}|dkrttj|ƒ‚n||ƒndS(NtABSENT(t*_InnerTypeConstraint__singleTypeConstraintt,_InnerTypeConstraint__multipleTypeConstraintRR(RRRR9tstatus((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR\s   cCsqi|_d|_xH|D]@}t|tƒrP|d|df|j|deZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs |j|S(N(R(RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt __getitem__¯scCs t|jƒS(N(titerR(R((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__iter__²scCs|j|j|fŒS(N(RR(RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__add__µscCs|j|f|jŒS(N(RR(RR((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__radd__¸scCs t|jƒS(N(R<R(R((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt__len__»scCsM||_x=|D]5}|r|jj|ƒ|jj|jƒƒqqWdS(N(RR taddtupdateR/(RRR9((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR Às   (RR3RGRIRJRKRLR (((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRF­s      cBseZdZd„ZRS(s8Create a ConstraintsIntersection logic operator object. The ConstraintsIntersection logic operator only succeeds if *all* its operands succeed. The ConstraintsIntersection object can be applied to any constraint and logic operator objects. The ConstraintsIntersection object duck-types the immutable container object like Python :py:class:`tuple`. Parameters ---------- \*constraints: Constraint or logic operator objects. Examples -------- .. code-block:: python class CapitalAndSmall(IA5String): ''' ASN.1 specification: CapitalAndSmall ::= IA5String (FROM ("A".."Z"|"a".."z")) ''' subtypeSpec = ConstraintsIntersection( PermittedAlphabetConstraint('A', 'Z'), PermittedAlphabetConstraint('a', 'z') ) # this will succeed capital_and_small = CapitalAndSmall('Hello') # this will raise ValueConstraintError capital_and_small = CapitalAndSmall('hello') cCs%x|jD]}|||ƒq WdS(N(R(RRRR9((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRïs(RR3R7R(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRÈs&cBseZdZd„ZRS(s+Create a ConstraintsUnion logic operator object. The ConstraintsUnion logic operator only succeeds if *at least a single* operand succeeds. The ConstraintsUnion object can be applied to any constraint and logic operator objects. The ConstraintsUnion object duck-types the immutable container object like Python :py:class:`tuple`. Parameters ---------- \*constraints: Constraint or logic operator objects. Examples -------- .. code-block:: python class CapitalOrSmall(IA5String): ''' ASN.1 specification: CapitalOrSmall ::= IA5String (FROM ("A".."Z") | FROM ("a".."z")) ''' subtypeSpec = ConstraintsIntersection( PermittedAlphabetConstraint('A', 'Z'), PermittedAlphabetConstraint('a', 'z') ) # this will succeed capital_or_small = CapitalAndSmall('Hello') # this will raise ValueConstraintError capital_or_small = CapitalOrSmall('hello!') cCs`x=|jD]2}y|||ƒWntjk r7q XdSq Wtjd|j|fƒ‚dS(Nsall of %s failed for "%s"(RRR(RRRR9((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyRs(RR3R7R(((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyR ôs&(Rt pyasn1.typeRt__all__tobjectR RRRRRRRRFRR (((s8/tmp/pip-install-KP2Jbq/pyasn1/pyasn1/type/constraint.pyt s"  O),8<-9,