def _valid_states(self, states: Union[State, Sequence[State]]): if states is not None: if not is_iterable(states): states = (states, ) return tuple( map(lambda st: st if isinstance(st, State) else st(), states)) return None,
def parse_new_line_sep(cls, line: str) -> Union[str, None]: if is_iterable(line): for ln in cls._new_line_sep_map: if ln in line: return ln try: if line in cls._str_new_line_sep_map: return cls._str_new_line_sep_map[line] except TypeError: return None return None
def __call__(self, sequence: Sequence, task_name=None) -> "ProgressBase": if not is_iterable(sequence): raise ValueError("Send a sequence.") self.update_max_value(len(sequence)) self.sequence = sequence if task_name is not None: self.console.set_prefix(f"{self.name}({task_name})") if self._with_context and task_name is None: self.console.set_prefix(f"{self.name}(iter-{self.__task_count})") self.started_time = time.time() self.__task_count += 1 return self
def normalize_data(cls, data: Any, *args, **kwargs) -> Union[List[str], Any]: if not data: return data if isinstance(data, bytes): return [data] if isinstance(data, str): data = data.splitlines() elif isinstance(data, int): data = [data] if is_iterable(data): return [ str(line).replace(CRLF, '').replace(CR, '').replace(LF, '') for line in data ] raise ValueError(f"{data} Invalid value. Send other ")
def __init__(self, data: Optional[Sequence] = ()): assert is_iterable(data), "Isn't iterable." self._elements_size = None super().__init__(data)
def test_is_iterable(self): self.assertFalse(is_iterable(1)) self.assertTrue(is_iterable('hi')) self.assertTrue(is_iterable([]))