From 3796e0b2b2678be1ad9b40ed0c06c6e19800ce66 Mon Sep 17 00:00:00 2001 From: elie Date: Tue, 8 Sep 2015 19:30:39 +0000 Subject: example on MIN/MAX added --- doc/constraints.html | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) 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:

-Value range constraint usually applies numeric types. +Value range constraint usually applies to numeric types.

+

+ASN.1 MIN and MAX operands can be substituted with floating +point infinity values. +

+ +
+
+NegativeInt ::= INTEGER (MIN..-1)
+PositiveInt ::= INTEGER (1..MAX)
+
+
+ +

+And in pyasn1 terms: +

+ +
+
+>>> 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
+
+
+

1.4.3 Size constraint -- cgit v1.2.1