mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-20 13:32:04 +08:00
SegmentRange: more explicit slice matching (#31451)
* more explicit * fix it * use non capturing group * only needed for regex101 * make test_logreader.py executable * fix * stash * passes test * none * type anotate * test * fix * nice for syntax highlighting
This commit is contained in:
@@ -15,7 +15,7 @@ class RE:
|
||||
|
||||
INDEX = r'-?[0-9]+'
|
||||
SLICE = r'(?P<start>{})?:?(?P<end>{})?:?(?P<step>{})?'.format(INDEX, INDEX, INDEX)
|
||||
SEGMENT_RANGE = r'{}(?:--|/)?(?P<slice>({}))?/?(?P<selector>([qras]))?'.format(ROUTE_NAME, SLICE)
|
||||
SEGMENT_RANGE = r'{}(?:(--|/)(?P<slice>({})))?(?:/(?P<selector>([qras])))?'.format(ROUTE_NAME, SLICE)
|
||||
|
||||
BOOTLOG_NAME = ROUTE_NAME
|
||||
|
||||
|
||||
+5
-5
@@ -265,7 +265,11 @@ class SegmentRange:
|
||||
|
||||
@property
|
||||
def _slice(self) -> str:
|
||||
return self.m.group("slice")
|
||||
return self.m.group("slice") or ""
|
||||
|
||||
@property
|
||||
def selector(self) -> str | None:
|
||||
return self.m.group("selector")
|
||||
|
||||
@property
|
||||
def seg_idxs(self) -> list[int]:
|
||||
@@ -286,10 +290,6 @@ class SegmentRange:
|
||||
else:
|
||||
return list(range(end + 1))[s]
|
||||
|
||||
@property
|
||||
def selector(self) -> str:
|
||||
return self.m.group("selector")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.dongle_id}/{self.timestamp}" + (f"/{self._slice}" if self._slice else "") + (f"/{self.selector}" if self.selector else "")
|
||||
|
||||
|
||||
Regular → Executable
+4
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
import shutil
|
||||
import tempfile
|
||||
import os
|
||||
@@ -83,6 +84,9 @@ class TestLogReader(unittest.TestCase):
|
||||
(f"{TEST_ROUTE}/j",),
|
||||
(f"{TEST_ROUTE}/0:1:2:3",),
|
||||
(f"{TEST_ROUTE}/:::3",),
|
||||
(f"{TEST_ROUTE}3",),
|
||||
(f"{TEST_ROUTE}-3",),
|
||||
(f"{TEST_ROUTE}--3a",),
|
||||
])
|
||||
def test_bad_ranges(self, segment_range):
|
||||
with self.assertRaises(AssertionError):
|
||||
|
||||
Reference in New Issue
Block a user