@@ -137,8 +137,12 @@ def get_module_from_prefix(self, prefix: str) -> Optional["Module"]:
137
137
def __iter__ (self ) -> Iterator ["SNode" ]:
138
138
return self .children ()
139
139
140
- def children (self , types : Optional [Tuple [int , ...]] = None ) -> Iterator ["SNode" ]:
141
- return iter_children (self .context , self .cdata , types = types )
140
+ def children (
141
+ self , types : Optional [Tuple [int , ...]] = None , with_choice : bool = False
142
+ ) -> Iterator ["SNode" ]:
143
+ return iter_children (
144
+ self .context , self .cdata , types = types , with_choice = with_choice
145
+ )
142
146
143
147
def __str__ (self ) -> str :
144
148
return self .name ()
@@ -1401,8 +1405,12 @@ def presence(self) -> Optional[str]:
1401
1405
def __iter__ (self ) -> Iterator [SNode ]:
1402
1406
return self .children ()
1403
1407
1404
- def children (self , types : Optional [Tuple [int , ...]] = None ) -> Iterator [SNode ]:
1405
- return iter_children (self .context , self .cdata , types = types )
1408
+ def children (
1409
+ self , types : Optional [Tuple [int , ...]] = None , with_choice : bool = False
1410
+ ) -> Iterator [SNode ]:
1411
+ return iter_children (
1412
+ self .context , self .cdata , types = types , with_choice = with_choice
1413
+ )
1406
1414
1407
1415
1408
1416
# -------------------------------------------------------------------------------------
@@ -1411,8 +1419,10 @@ class SChoice(SNode):
1411
1419
def __iter__ (self ) -> Iterator [SNode ]:
1412
1420
return self .children ()
1413
1421
1414
- def children (self , types : Optional [Tuple [int , ...]] = None ) -> Iterator [SNode ]:
1415
- return iter_children (self .context , self .cdata , types = types )
1422
+ def children (
1423
+ self , types : Optional [Tuple [int , ...]] = None , with_case : bool = False
1424
+ ) -> Iterator [SNode ]:
1425
+ return iter_children (self .context , self .cdata , types = types , with_case = with_case )
1416
1426
1417
1427
1418
1428
# -------------------------------------------------------------------------------------
@@ -1421,8 +1431,12 @@ class SCase(SNode):
1421
1431
def __iter__ (self ) -> Iterator [SNode ]:
1422
1432
return self .children ()
1423
1433
1424
- def children (self , types : Optional [Tuple [int , ...]] = None ) -> Iterator [SNode ]:
1425
- return iter_children (self .context , self .cdata , types = types )
1434
+ def children (
1435
+ self , types : Optional [Tuple [int , ...]] = None , with_choice : bool = False
1436
+ ) -> Iterator [SNode ]:
1437
+ return iter_children (
1438
+ self .context , self .cdata , types = types , with_choice = with_choice
1439
+ )
1426
1440
1427
1441
1428
1442
# -------------------------------------------------------------------------------------
@@ -1442,9 +1456,18 @@ def __iter__(self) -> Iterator[SNode]:
1442
1456
return self .children ()
1443
1457
1444
1458
def children (
1445
- self , skip_keys : bool = False , types : Optional [Tuple [int , ...]] = None
1459
+ self ,
1460
+ skip_keys : bool = False ,
1461
+ types : Optional [Tuple [int , ...]] = None ,
1462
+ with_choice : bool = False ,
1446
1463
) -> Iterator [SNode ]:
1447
- return iter_children (self .context , self .cdata , skip_keys = skip_keys , types = types )
1464
+ return iter_children (
1465
+ self .context ,
1466
+ self .cdata ,
1467
+ skip_keys = skip_keys ,
1468
+ types = types ,
1469
+ with_choice = with_choice ,
1470
+ )
1448
1471
1449
1472
def keys (self ) -> Iterator [SNode ]:
1450
1473
node = lib .lysc_node_child (self .cdata )
@@ -1512,9 +1535,7 @@ def children(self, types: Optional[Tuple[int, ...]] = None) -> Iterator[SNode]:
1512
1535
yield from iter_children (self .context , self .cdata , types = types )
1513
1536
# With libyang2, you can get only input or output
1514
1537
# To keep behavior, we iter 2 times witt output options
1515
- yield from iter_children (
1516
- self .context , self .cdata , types = types , options = lib .LYS_GETNEXT_OUTPUT
1517
- )
1538
+ yield from iter_children (self .context , self .cdata , types = types , output = True )
1518
1539
1519
1540
1520
1541
# -------------------------------------------------------------------------------------
@@ -1539,13 +1560,43 @@ class SAnydata(SNode):
1539
1560
pass
1540
1561
1541
1562
1563
+ # -------------------------------------------------------------------------------------
1564
+ def iter_children_options (
1565
+ with_choice : bool = False ,
1566
+ no_choice : bool = False ,
1567
+ with_case : bool = False ,
1568
+ into_non_presence_container : bool = False ,
1569
+ output : bool = False ,
1570
+ with_schema_mount : bool = False ,
1571
+ ) -> int :
1572
+ options = 0
1573
+ if with_choice :
1574
+ options |= lib .LYS_GETNEXT_WITHCHOICE
1575
+ if no_choice :
1576
+ options |= lib .LYS_GETNEXT_NOCHOICE
1577
+ if with_case :
1578
+ options |= lib .LYS_GETNEXT_WITHCASE
1579
+ if into_non_presence_container :
1580
+ options |= lib .LYS_GETNEXT_INTONPCONT
1581
+ if output :
1582
+ options |= lib .LYS_GETNEXT_OUTPUT
1583
+ if with_schema_mount :
1584
+ options |= lib .LYS_GETNEXT_WITHSCHEMAMOUNT
1585
+ return options
1586
+
1587
+
1542
1588
# -------------------------------------------------------------------------------------
1543
1589
def iter_children (
1544
1590
context : "libyang.Context" ,
1545
1591
parent , # C type: Union["struct lys_module *", "struct lys_node *"]
1546
1592
skip_keys : bool = False ,
1547
1593
types : Optional [Tuple [int , ...]] = None ,
1548
- options : int = 0 ,
1594
+ with_choice : bool = False ,
1595
+ no_choice : bool = False ,
1596
+ with_case : bool = False ,
1597
+ into_non_presence_container : bool = False ,
1598
+ output : bool = False ,
1599
+ with_schema_mount : bool = False ,
1549
1600
) -> Iterator [SNode ]:
1550
1601
if types is None :
1551
1602
types = (
@@ -1556,6 +1607,8 @@ def iter_children(
1556
1607
lib .LYS_LEAF ,
1557
1608
lib .LYS_LEAFLIST ,
1558
1609
lib .LYS_NOTIF ,
1610
+ lib .LYS_CHOICE ,
1611
+ lib .LYS_CASE ,
1559
1612
)
1560
1613
1561
1614
def _skip (node ) -> bool :
@@ -1576,6 +1629,14 @@ def _skip(node) -> bool:
1576
1629
else :
1577
1630
module = ffi .NULL
1578
1631
1632
+ options = iter_children_options (
1633
+ with_choice = with_choice ,
1634
+ no_choice = no_choice ,
1635
+ with_case = with_case ,
1636
+ into_non_presence_container = into_non_presence_container ,
1637
+ output = output ,
1638
+ with_schema_mount = with_schema_mount ,
1639
+ )
1579
1640
child = lib .lys_getnext (ffi .NULL , parent , module , options )
1580
1641
while child :
1581
1642
if not _skip (child ):
0 commit comments