From 52da1c4ee4e0bb6c6e9865466f40effff1e61deb Mon Sep 17 00:00:00 2001 From: Samuel Gauthier Date: Wed, 7 Feb 2024 13:59:19 +0100 Subject: [PATCH] Revert "schema: use Pattern class for patterns method" This reverts commit a6c7164b743d83041cb0db5363b0863f9a311be1. It actually breaks compatibility, remove this. Signed-off-by: Samuel Gauthier --- libyang/schema.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libyang/schema.py b/libyang/schema.py index d49c39a7..deec466d 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -681,8 +681,20 @@ def all_lengths(self) -> Iterator[str]: yield length def patterns(self) -> Iterator[Tuple[str, bool]]: - for pattern in self.pattern_details(): - yield pattern.expression(), pattern.inverted() + if not self.cdata_parsed or self.cdata.basetype != self.STRING: + return + if self.cdata_parsed.patterns == ffi.NULL: + return + for p in ly_array_iter(self.cdata_parsed.patterns): + if not p: + continue + # in case of pattern restriction, the first byte has a special meaning: + # 0x06 (ACK) for regular match and 0x15 (NACK) for invert-match + invert_match = p.arg.str[0] == b"\x15" + # yield tuples like: + # ('[a-zA-Z_][a-zA-Z0-9\-_.]*', False) + # ('[xX][mM][lL].*', True) + yield c2str(p.arg.str + 1), invert_match def all_patterns(self) -> Iterator[Tuple[str, bool]]: if self.cdata.basetype == lib.LY_TYPE_UNION: