Skip to content

Commit a6c7164

Browse files
schema: use Pattern class for patterns method
Now that we have the Pattern class, use it for the patterns() method. Fixes: #92 Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 0f43838 commit a6c7164

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

libyang/schema.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -677,20 +677,8 @@ def all_lengths(self) -> Iterator[str]:
677677
yield length
678678

679679
def patterns(self) -> Iterator[Tuple[str, bool]]:
680-
if not self.cdata_parsed or self.cdata.basetype != self.STRING:
681-
return
682-
if self.cdata_parsed.patterns == ffi.NULL:
683-
return
684-
for p in ly_array_iter(self.cdata_parsed.patterns):
685-
if not p:
686-
continue
687-
# in case of pattern restriction, the first byte has a special meaning:
688-
# 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match
689-
invert_match = p.arg.str[0] == b"\x15"
690-
# yield tuples like:
691-
# ('[a-zA-Z_][a-zA-Z0-9\-_.]*', False)
692-
# ('[xX][mM][lL].*', True)
693-
yield c2str(p.arg.str + 1), invert_match
680+
for pattern in self.pattern_details():
681+
yield pattern.expression(), pattern.inverted()
694682

695683
def all_patterns(self) -> Iterator[Tuple[str, bool]]:
696684
if self.cdata.basetype == lib.LY_TYPE_UNION:

0 commit comments

Comments
 (0)