]> Cypherpunks.ru repositories - pyderasn.git/commitdiff
Cython compatibility
authorSergey Matveev <stargrave@stargrave.org>
Sat, 8 Feb 2020 19:44:54 +0000 (22:44 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 9 Feb 2020 09:47:14 +0000 (12:47 +0300)
Module has to be specified for namedtuples for pickling under Cython.

doc/features.rst
doc/news.rst
pyderasn.py

index 1c91feeb9456143799f2a1037b9587545ec4dd40..76d6830d3913f6872ae1a2f25608f5a9d1916515 100644 (file)
@@ -47,7 +47,8 @@ Also there is `asn1crypto <https://github.com/wbond/asn1crypto>`__.
   automatically set required tags)
 * Descriptive errors, like ``pyderasn.DecodeError: UTCTime
   (tbsCertificate:validity:notAfter:utcTime) (at 328) invalid UTCTime format``
-* ``__slots__``, ``copy.copy()``, ``pickle`` friendliness
+* ``__slots__``, ``copy.copy()``, ``pickle``, `Cython <https://cython.org/>`__
+  friendliness
 * Could be significantly faster and have lower memory usage
   For example parsing of CACert.org's CRL (8.48 MiB) on FreeBSD 12.0
   amd64, Intel Core i5-6200U 2.3 GHz machine, Python 3.5.5/2.7.15:
index cbaa344994e316b30e9085433ac3ac5bbf2aa172..50c3408fa70e80100875ef8519184899953e1c53 100644 (file)
@@ -8,6 +8,7 @@ News
 * UTCTime and GeneralizedTime allowed values to have plus sign in them,
   passing int() check successfully. Prohibit that incorrect behaviour
 * UTCTime and GeneralizedTime BER decoding support
+* Workability under Cython
 * Explicitly Check that all ObjectIdentifier arcs are non-negative
 
 .. _release6.0:
index 0d3a6637840115c15fdcf90bc898f095f0c640f7..6c14e4619972a8a31e68fdafd8cefbd48f344659 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 # coding: utf-8
+# cython: language_level=3
 # PyDERASN -- Python ASN.1 DER/BER codec with abstract structures
 # Copyright (C) 2017-2020 Sergey Matveev <stargrave@stargrave.org>
 #
@@ -763,6 +764,7 @@ EOC = b"\x00\x00"
 EOC_LEN = len(EOC)
 LENINDEF = b"\x80"  # length indefinite mark
 LENINDEF_PP_CHAR = "I" if PY2 else "∞"
+NAMEDTUPLE_KWARGS = {} if PY2 else {"module": __name__}
 
 
 ########################################################################
@@ -1479,7 +1481,7 @@ PP = namedtuple("PP", (
     "lenindef",
     "ber_encoded",
     "bered",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 def _pp(
@@ -1739,7 +1741,7 @@ BooleanState = namedtuple("BooleanState", (
     "expl_lenindef",
     "lenindef",
     "ber_encoded",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class Boolean(Obj):
@@ -1983,7 +1985,7 @@ IntegerState = namedtuple("IntegerState", (
     "expl_lenindef",
     "lenindef",
     "ber_encoded",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class Integer(Obj):
@@ -2353,7 +2355,7 @@ BitStringState = namedtuple("BitStringState", (
     "ber_encoded",
     "tag_constructed",
     "defined",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class BitString(Obj):
@@ -2864,7 +2866,7 @@ OctetStringState = namedtuple("OctetStringState", (
     "ber_encoded",
     "tag_constructed",
     "defined",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class OctetString(Obj):
@@ -3252,7 +3254,7 @@ NullState = namedtuple("NullState", (
     "expl_lenindef",
     "lenindef",
     "ber_encoded",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class Null(Obj):
@@ -3422,7 +3424,7 @@ ObjectIdentifierState = namedtuple("ObjectIdentifierState", (
     "lenindef",
     "ber_encoded",
     "defines",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 def pureint(value):
@@ -4009,6 +4011,7 @@ class NumericString(AllowableCharsMixin, CommonString):
 PrintableStringState = namedtuple(
     "PrintableStringState",
     OctetStringState._fields + ("allowable_chars",),
+    **NAMEDTUPLE_KWARGS
 )
 
 
@@ -4154,7 +4157,11 @@ class VisibleString(CommonString):
     asn1_type_name = "VisibleString"
 
 
-UTCTimeState = namedtuple("UTCTimeState", OctetStringState._fields + ("ber_raw",))
+UTCTimeState = namedtuple(
+    "UTCTimeState",
+    OctetStringState._fields + ("ber_raw",),
+    **NAMEDTUPLE_KWARGS
+)
 
 
 class UTCTime(VisibleString):
@@ -4598,7 +4605,7 @@ ChoiceState = namedtuple("ChoiceState", (
     "expl_lenindef",
     "lenindef",
     "ber_encoded",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class Choice(Obj):
@@ -4916,7 +4923,7 @@ AnyState = namedtuple("AnyState", (
     "lenindef",
     "ber_encoded",
     "defined",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class Any(Obj):
@@ -5195,7 +5202,7 @@ SequenceState = namedtuple("SequenceState", (
     "expl_lenindef",
     "lenindef",
     "ber_encoded",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class Sequence(Obj):
@@ -5860,7 +5867,7 @@ SequenceOfState = namedtuple("SequenceOfState", (
     "expl_lenindef",
     "lenindef",
     "ber_encoded",
-))
+), **NAMEDTUPLE_KWARGS)
 
 
 class SequenceOf(Obj):