Support both 0.4 and 0.5 style APIs. substrateFun API has changed in 0.5 for use with streaming decoders. To stay backwards compatible, we first try if we received a streaming user callback. If that fails,we assume we've received a non-streaming v0.4
(asn1Object, substrate, length, options=None)
| 2097 | origSubstrateFun = options["substrateFun"] |
| 2098 | |
| 2099 | def substrateFunWrapper(asn1Object, substrate, length, options=None): |
| 2100 | """Support both 0.4 and 0.5 style APIs. |
| 2101 | |
| 2102 | substrateFun API has changed in 0.5 for use with streaming decoders. To stay backwards compatible, |
| 2103 | we first try if we received a streaming user callback. If that fails,we assume we've received a |
| 2104 | non-streaming v0.4 user callback and convert it for streaming on the fly |
| 2105 | """ |
| 2106 | try: |
| 2107 | substrate_gen = origSubstrateFun(asn1Object, substrate, length, options) |
| 2108 | except TypeError as _value: |
| 2109 | if _value.__traceback__.tb_next: |
| 2110 | # Traceback depth > 1 means TypeError from inside user provided function |
| 2111 | raise |
| 2112 | # invariant maintained at Decoder.__call__ entry |
| 2113 | assert isinstance(substrate, io.BytesIO) # nosec assert_used |
| 2114 | substrate_gen = Decoder._callSubstrateFunV4asV5(origSubstrateFun, asn1Object, substrate, length) |
| 2115 | for value in substrate_gen: |
| 2116 | yield value |
| 2117 | |
| 2118 | options["substrateFun"] = substrateFunWrapper |
| 2119 |
nothing calls this directly
no test coverage detected