From df684c64c28007ed8695e4acd368e1232ceaf2ae Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 16 Nov 2025 10:51:49 +0100 Subject: [PATCH] Remove unuse parameter in split_esc --- glances/globals.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/glances/globals.py b/glances/globals.py index b9062d78..977c50f3 100644 --- a/glances/globals.py +++ b/glances/globals.py @@ -633,13 +633,13 @@ def exit_after(seconds, default=None): return decorator -def split_esc(string, /, sep=None, maxsplit=-1, esc='\\'): +def split_esc(input_string, sep=None, maxsplit=-1, esc='\\'): """ - Return a list of the substrings in the string, using sep as the separator string + Return a list of the substrings in the input_string, using sep as the separator char and esc as the escape character. sep - The separator used to split the string. + The separator used to split the input_string. When set to None (the default value), will split on any whitespace character (including \n \r \t \f and spaces) unless the character is escaped @@ -653,59 +653,59 @@ def split_esc(string, /, sep=None, maxsplit=-1, esc='\\'): When set to None, this behaves equivalently to `str.split`. Defaults to '\\\\' i.e. backslash. - Splitting starts at the front of the string and works to the end. + Splitting starts at the front of the input_string and works to the end. Note: escape characters in the substrings returned are removed. However, if maxsplit is reached, escape characters in the remaining, unprocessed substring are not removed, which allows split_esc to be called on it again. """ # Input validation - if not isinstance(string, str): - raise TypeError(f'must be str, not {string.__class__.__name__}') + if not isinstance(input_string, str): + raise TypeError(f'must be str, not {input_string.__class__.__name__}') str.split('', sep=sep, maxsplit=maxsplit) # Use str.split to validate sep and maxsplit if esc is None: - return string.split( + return input_string.split( sep=sep, maxsplit=maxsplit ) # Short circuit to default implementation if the escape character is None - elif not isinstance(esc, str): + if not isinstance(esc, str): raise TypeError(f'must be str or None, not {esc.__class__.__name__}') - elif len(esc) == 0: + if len(esc) == 0: raise ValueError('empty escape character') - elif len(esc) > 1: + if len(esc) > 1: raise ValueError('escape must be a single character') # Set up a simple state machine keeping track of whether we have seen an escape character ret, esc_seen, i = [''], False, 0 - while i < len(string) and len(ret) - 1 != maxsplit: + while i < len(input_string) and len(ret) - 1 != maxsplit: if not esc_seen: - if string[i] == esc: + if input_string[i] == esc: # Consume the escape character and transition state esc_seen = True i += 1 - elif sep is None and string[i].isspace(): + elif sep is None and input_string[i].isspace(): # Consume as much whitespace as possible n = 1 - while i + n + 1 < len(string) and string[i + n : i + n + 1].isspace(): + while i + n + 1 < len(input_string) and input_string[i + n : i + n + 1].isspace(): n += 1 ret.append('') i += n - elif sep is not None and string[i : i + len(sep)] == sep: + elif sep is not None and input_string[i : i + len(sep)] == sep: # Consume the separator ret.append('') i += len(sep) else: # Otherwise just add the current char - ret[-1] += string[i] + ret[-1] += input_string[i] i += 1 else: # Add the current char and transition state back - ret[-1] += string[i] + ret[-1] += input_string[i] esc_seen = False i += 1 # Append any remaining string if we broke early because of maxsplit - if i < len(string): - ret[-1] += string[i:] + if i < len(input_string): + ret[-1] += input_string[i:] # If splitting on whitespace, discard empty strings from result if sep is None: