Ejemplo n.º 1
0
 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,
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 def normalize_data(cls, data: Any, *args, **kwargs) -> Union[List[str], Any]:
     if not data:
         return data
     if is_iterable(data) or isinstance(data, int):
         if is_sequence(data) and not isinstance(data, int):
             data = [str(line).replace(CRLF, '').replace(CR, '').replace(LF, '') for line in data]
         elif isinstance(data, str):
             data = data.splitlines()
         elif isinstance(data, int):
             data = str(data)
         return data
     else:
         raise ValueError(f"{data} Invalid value. Send other ")
Ejemplo n.º 5
0
 def __init__(self, data: Optional[Sequence] = ()):
     assert is_iterable(data), "Isn't iterable."
     self._elements_size = None
     super().__init__(data)
Ejemplo n.º 6
0
 def test_is_iterable(self):
     self.assertFalse(is_iterable(1))
     self.assertTrue(is_iterable('hi'))
     self.assertTrue(is_iterable([]))