diff options
author | elie <elie> | 2015-09-08 19:30:39 +0000 |
---|---|---|
committer | elie <elie> | 2015-09-08 19:30:39 +0000 |
commit | 3796e0b2b2678be1ad9b40ed0c06c6e19800ce66 (patch) | |
tree | fcb28a8bd17033864f6d0b08e8fcb996c5f25e1f | |
parent | 3493071f885fac10a7ac43308e26bcf6be81ccd7 (diff) | |
download | pyasn1-3796e0b2b2678be1ad9b40ed0c06c6e19800ce66.tar.gz |
example on MIN/MAX added
-rw-r--r-- | doc/constraints.html | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/doc/constraints.html b/doc/constraints.html index 53da1ad..072377d 100644 --- a/doc/constraints.html +++ b/doc/constraints.html @@ -146,9 +146,51 @@ pyasn1.type.error.ValueConstraintError: </td></tr></table> <p> -Value range constraint usually applies numeric types. +Value range constraint usually applies to numeric types. </p> +<p> +ASN.1 MIN and MAX operands can be substituted with floating +point infinity values. +</p> + +<table bgcolor="lightgray" border=0 width=100%><TR><TD> +<pre> +NegativeInt ::= INTEGER (MIN..-1) +PositiveInt ::= INTEGER (1..MAX) +</pre> +</td></tr></table> + +<p> +And in pyasn1 terms: +</p> + +<table bgcolor="lightgray" border=0 width=100%><TR><TD> +<pre> +>>> from pyasn1.type import univ, constraint +>>> class NegativeInt(univ.Integer): +... subtypeSpec = constraint.ValueRangeConstraint(float('-inf'), -1) +>>> NegativeInt(-1) +NegativeInt(-1) +>>> NegativeInt(0) +Traceback (most recent call last): +... +pyasn1.type.error.ValueConstraintError: + ValueConstraintError: ValueRangeConstraint() failed at: "0" at NegativeInt +>>> class PositiveInt(univ.Integer): +... subtypeSpec = constraint.ValueRangeConstraint(1, float('inf')) +>> PositiveInt(1) +PositiveInt(1) +>> PositiveInt(4) +PositiveInt(4) +>> PositiveInt(-1) +Traceback (most recent call last): +... +pyasn1.type.error.ValueConstraintError: + ValueConstraintError: ValueRangeConstraint() failed at: "-1" at PositiveInt +</pre> +</td></tr></table> + <a name="1.4.3"></a> <h4> 1.4.3 Size constraint |