def parse_path_factory(str_split): """ Create a function that will properly split and format a path. Parameters ---------- str_split : callable The output of the *parse_string_factory* function. Returns ------- func : callable A function that accepts a string or path-like object and splits it into its path components, then passes each component to *str_split* and returns the result as a nested tuple. Can be used as the *string_func* argument to *natsort_key*. See Also -------- natsort_key parse_string_factory """ return lambda x: tuple(py23_map(str_split, path_splitter(x)))
def func(x): original = x x = pre(x) # Apply pre-splitting function x = splitter(x) # Split the string on numbers x = py23_filter(None, x) # Remove empty strings. x = py23_map(post, x) # Apply post-splitting function x = _sep_inserter(x, sep) # Insert empty strings between numbers return after(x, original) # Apply final manipulation
def func(x, original_func=input_transform if orig_after_xfrm else _no_op): # Apply string input transformation function and return to x. # Original function is usually a no-op, but some algorithms require it # to also be the transformation function. x, original = input_transform(x), original_func(x) x = splitter(x) # Split string into components. x = py23_filter(None, x) # Remove empty strings. x = py23_map(component_transform, x) # Apply transform on components. x = _sep_inserter(x, sep) # Insert '' between numbers. return final_transform(x, original) # Apply the final transform.
def func(x): # Apply string input transformation function and return to x. # Original function is usually a no-op, but some algorithms require it # to also be the transformation function. x = normalize_input(x) x, original = input_transform(x), original_func(x) x = splitter(x) # Split string into components. x = py23_filter(None, x) # Remove empty strings. x = py23_map(component_transform, x) # Apply transform on components. x = sep_inserter(x, sep) # Insert '' between numbers. return final_transform(x, original) # Apply the final transform.
def _parse_path_factory(str_split): """Create a function that will properly split and format a path.""" return lambda x: tuple(py23_map(str_split, _path_splitter(x)))