mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-09-09 18:29:55 +00:00
Compare commits
16 Commits
59162ba45f
...
5c5d64bb25
Author | SHA1 | Date | |
---|---|---|---|
5c5d64bb25 | |||
5a3b3bad41 | |||
7a8a97ca58 | |||
0d2758aaf8 | |||
2f866d779a | |||
304ec64fa2 | |||
0630a0eaa6 | |||
73c111ef3f | |||
3a26a322b7 | |||
f1de5b3e4e | |||
1c79322166 | |||
b2eb86bd5a | |||
eb4b7db8a1 | |||
89c439355d | |||
0b43d37229 | |||
beb997fd58 |
@ -448,7 +448,6 @@ disable=raw-checker-failed,
|
|||||||
too-many-arguments,
|
too-many-arguments,
|
||||||
duplicate-code,
|
duplicate-code,
|
||||||
cyclic-import,
|
cyclic-import,
|
||||||
too-many-positional-arguments,
|
|
||||||
|
|
||||||
# Enable the message, report, category or checker with the given id(s). You can
|
# Enable the message, report, category or checker with the given id(s). You can
|
||||||
# either give multiple identifier separated by comma (,) or put this option
|
# either give multiple identifier separated by comma (,) or put this option
|
||||||
|
@ -165,35 +165,26 @@ class PkgbuildParser(shlex.shlex):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _is_escaped(self) -> bool:
|
def _is_quoted(self) -> bool:
|
||||||
"""
|
"""
|
||||||
check if the last element was quoted. ``shlex.shlex`` parser doesn't provide information about was the token
|
check if the last element was quoted. ``shlex.shlex`` parser doesn't provide information about was the token
|
||||||
quoted or not, thus there is no difference between "'#'" (diez in quotes) and "#" (diez without quotes). This
|
quoted or not, thus there is no difference between "'#'" (diez in quotes) and "#" (diez without quotes). This
|
||||||
method simply rolls back to the last non-space character and check if it is a quotation mark
|
method simply rolls back to the last non-space character and check if it is a quotation mark
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: ``True`` if the previous element of the stream is a quote or escaped and ``False`` otherwise
|
bool: ``True`` if the previous element of the stream is a quote and ``False`` otherwise
|
||||||
"""
|
"""
|
||||||
current_position = self._io.tell()
|
current_position = self._io.tell()
|
||||||
|
|
||||||
last_char = penultimate_char = None
|
last_char = None
|
||||||
for index in range(current_position - 1, -1, -1):
|
for index in range(current_position - 1, -1, -1):
|
||||||
self._io.seek(index)
|
self._io.seek(index)
|
||||||
last_char = self._io.read(1)
|
last_char = self._io.read(1)
|
||||||
if last_char.isspace():
|
if not last_char.isspace():
|
||||||
continue
|
break
|
||||||
|
|
||||||
if index >= 0:
|
|
||||||
self._io.seek(index - 1)
|
|
||||||
penultimate_char = self._io.read(1)
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
self._io.seek(current_position) # reset position of the stream
|
self._io.seek(current_position) # reset position of the stream
|
||||||
is_quoted = last_char is not None and last_char in self.quotes
|
return last_char is not None and last_char in self.quotes
|
||||||
is_escaped = penultimate_char is not None and penultimate_char in self.escape
|
|
||||||
|
|
||||||
return is_quoted or is_escaped
|
|
||||||
|
|
||||||
def _parse_array(self) -> list[str]:
|
def _parse_array(self) -> list[str]:
|
||||||
"""
|
"""
|
||||||
@ -209,7 +200,7 @@ class PkgbuildParser(shlex.shlex):
|
|||||||
def extract() -> Generator[str, None, None]:
|
def extract() -> Generator[str, None, None]:
|
||||||
while token := self.get_token():
|
while token := self.get_token():
|
||||||
match token:
|
match token:
|
||||||
case _ if self._is_escaped():
|
case _ if self._is_quoted():
|
||||||
pass
|
pass
|
||||||
case PkgbuildToken.ArrayEnds:
|
case PkgbuildToken.ArrayEnds:
|
||||||
break
|
break
|
||||||
@ -238,9 +229,9 @@ class PkgbuildParser(shlex.shlex):
|
|||||||
# find start and end positions
|
# find start and end positions
|
||||||
start_position = end_position = -1
|
start_position = end_position = -1
|
||||||
counter = 0 # simple processing of the inner "{" and "}"
|
counter = 0 # simple processing of the inner "{" and "}"
|
||||||
for token in self:
|
while token := self.get_token():
|
||||||
match token:
|
match token:
|
||||||
case _ if self._is_escaped():
|
case _ if self._is_quoted():
|
||||||
continue
|
continue
|
||||||
case PkgbuildToken.FunctionStarts:
|
case PkgbuildToken.FunctionStarts:
|
||||||
if counter == 0:
|
if counter == 0:
|
||||||
|
@ -68,7 +68,7 @@ def test_parse_array_comment() -> None:
|
|||||||
])]
|
])]
|
||||||
|
|
||||||
|
|
||||||
def test_parse_array_escaped() -> None:
|
def test_parse_array_quotes() -> None:
|
||||||
"""
|
"""
|
||||||
must correctly process quoted brackets
|
must correctly process quoted brackets
|
||||||
"""
|
"""
|
||||||
@ -81,9 +81,6 @@ def test_parse_array_escaped() -> None:
|
|||||||
parser = PkgbuildParser(StringIO("""var=(first ')' second)"""))
|
parser = PkgbuildParser(StringIO("""var=(first ')' second)"""))
|
||||||
assert list(parser.parse()) == [PkgbuildPatch("var", ["first", ")", "second"])]
|
assert list(parser.parse()) == [PkgbuildPatch("var", ["first", ")", "second"])]
|
||||||
|
|
||||||
parser = PkgbuildParser(StringIO("""var=(first \\) second)"""))
|
|
||||||
assert list(parser.parse()) == [PkgbuildPatch("var", ["first", ")", "second"])]
|
|
||||||
|
|
||||||
|
|
||||||
def test_parse_array_exception() -> None:
|
def test_parse_array_exception() -> None:
|
||||||
"""
|
"""
|
||||||
@ -126,7 +123,7 @@ def test_parse_function_inner_shell() -> None:
|
|||||||
assert list(parser.parse()) == [PkgbuildPatch("var()", "{ { echo hello world } }")]
|
assert list(parser.parse()) == [PkgbuildPatch("var()", "{ { echo hello world } }")]
|
||||||
|
|
||||||
|
|
||||||
def test_parse_function_escaped() -> None:
|
def test_parse_function_quotes() -> None:
|
||||||
"""
|
"""
|
||||||
must parse function with bracket in quotes
|
must parse function with bracket in quotes
|
||||||
"""
|
"""
|
||||||
@ -145,9 +142,6 @@ def test_parse_function_escaped() -> None:
|
|||||||
parser = PkgbuildParser(StringIO("""var ( ) { echo hello world '}' } """))
|
parser = PkgbuildParser(StringIO("""var ( ) { echo hello world '}' } """))
|
||||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo hello world '}' }""")]
|
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo hello world '}' }""")]
|
||||||
|
|
||||||
parser = PkgbuildParser(StringIO("""var ( ) { echo hello world \\} } """))
|
|
||||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo hello world \\} }""")]
|
|
||||||
|
|
||||||
|
|
||||||
def test_parse_function_exception() -> None:
|
def test_parse_function_exception() -> None:
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user