Skip to content

Commit

Permalink
Revert "schema: use Pattern class for patterns method"
Browse files Browse the repository at this point in the history
This reverts commit a6c7164.

It actually breaks compatibility, remove this.

Signed-off-by: Samuel Gauthier <[email protected]>
  • Loading branch information
samuel-gauthier committed Feb 7, 2024
1 parent 6e94f1b commit 52da1c4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 52da1c4

Please sign in to comment.