@@ -160,9 +160,8 @@ def classify(self, objref: Value) -> list[Category]:
160160
161161 _T = TypeVar ('_T' )
162162
163- @abstractmethod
164163 def sort (self , data : Iterable [_T ], key : Callable [[_T ], Category ]) -> list [_T ]:
165- raise NotImplementedError
164+ return sorted ( data , key = lambda x : key ( x ). _sort_key )
166165
167166 @abstractmethod
168167 def anchor (self , refval : str ) -> str :
@@ -178,11 +177,6 @@ def classify(self, objref: Value) -> list[Category]:
178177 entries .append (Category (main = v ))
179178 return entries
180179
181- def sort (
182- self , data : Iterable [Indexer ._T ], key : Callable [[Indexer ._T ], Category ]
183- ) -> list [Indexer ._T ]:
184- return sorted (data , key = lambda x : key (x )._sort_key )
185-
186180 def anchor (self , refval : str ) -> str :
187181 return refval
188182
@@ -303,6 +297,27 @@ def anchor(self, refval: str) -> str:
303297 return ''
304298
305299
300+ class PathIndexer (Indexer ):
301+ name = 'path'
302+
303+ def __init__ (self , sep : str , maxsplit : Literal [1 , 2 ]):
304+ self .sep = sep
305+ self .maxsplit = maxsplit
306+
307+ def classify (self , objref : Value ) -> list [Category ]:
308+ entries = []
309+ for v in objref .as_list ():
310+ comps = v .split (self .sep , maxsplit = self .maxsplit )
311+ category = Category (main = comps [0 ], extra = v )
312+ if self .maxsplit == 2 :
313+ category .sub = v [1 ] if len (comps ) > 1 else None
314+ entries .append (category )
315+ return entries
316+
317+ def anchor (self , refval : str ) -> str :
318+ return refval .split (self .sep , maxsplit = self .maxsplit )[0 ]
319+
320+
306321@dataclasses .dataclass (frozen = True )
307322class Object (object ):
308323 objtype : str
0 commit comments