Returns |ASN.1| type component by index. Equivalent to Python sequence subscription operation (e.g. `[]`). Parameters ---------- idx: :class:`int` Component index (zero-based). Must either refer to an existing component or (if *componentType*
(self, idx, default=noValue, instantiate=True)
| 2426 | ) |
| 2427 | |
| 2428 | def getComponentByPosition(self, idx, default=noValue, instantiate=True): |
| 2429 | """Returns |ASN.1| type component by index. |
| 2430 | |
| 2431 | Equivalent to Python sequence subscription operation (e.g. `[]`). |
| 2432 | |
| 2433 | Parameters |
| 2434 | ---------- |
| 2435 | idx: :class:`int` |
| 2436 | Component index (zero-based). Must either refer to an existing |
| 2437 | component or (if *componentType* is set) new ASN.1 schema object gets |
| 2438 | instantiated. |
| 2439 | |
| 2440 | Keyword Args |
| 2441 | ------------ |
| 2442 | default: :class:`object` |
| 2443 | If set and requested component is a schema object, return the `default` |
| 2444 | object instead of the requested component. |
| 2445 | |
| 2446 | instantiate: :class:`bool` |
| 2447 | If :obj:`True` (default), inner component will be automatically |
| 2448 | instantiated. |
| 2449 | If :obj:`False` either existing component or the :class:`NoValue` |
| 2450 | object will be returned. |
| 2451 | |
| 2452 | Returns |
| 2453 | ------- |
| 2454 | : :py:class:`~pyasn1.type.base.PyAsn1Item` |
| 2455 | a PyASN1 object |
| 2456 | |
| 2457 | Examples |
| 2458 | -------- |
| 2459 | |
| 2460 | .. code-block:: python |
| 2461 | |
| 2462 | # can also be Set |
| 2463 | class MySequence(Sequence): |
| 2464 | componentType = NamedTypes( |
| 2465 | NamedType('id', OctetString()) |
| 2466 | ) |
| 2467 | |
| 2468 | s = MySequence() |
| 2469 | |
| 2470 | # returns component #0 with `.isValue` property False |
| 2471 | s.getComponentByPosition(0) |
| 2472 | |
| 2473 | # returns None |
| 2474 | s.getComponentByPosition(0, default=None) |
| 2475 | |
| 2476 | s.clear() |
| 2477 | |
| 2478 | # returns noValue |
| 2479 | s.getComponentByPosition(0, instantiate=False) |
| 2480 | |
| 2481 | # sets component #0 to OctetString() ASN.1 schema |
| 2482 | # object and returns it |
| 2483 | s.getComponentByPosition(0, instantiate=True) |
| 2484 | |
| 2485 | # sets component #0 to ASN.1 value object |
no test coverage detected