Skip to content

Commit 52da1c4

Browse files
Revert "schema: use Pattern class for patterns method"
This reverts commit a6c7164. It actually breaks compatibility, remove this. Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 6e94f1b commit 52da1c4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

libyang/schema.py

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

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

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

0 commit comments

Comments
 (0)