def to_stream(self, stream_type: AutoStreamType = AUTO, *args, **kwargs) -> Stream: stream_type = arg.acquire(stream_type, self.get_stream_type()) method_suffix = StreamType.of(stream_type).get_method_suffix() method_name = 'to_{}'.format(method_suffix) stream_method = self.__getattribute__(method_name) return stream_method(stream_type, *args, **kwargs)
def stream(self, data: Iterable, stream_type: Union[StreamType, Stream, arg.Auto] = arg.AUTO, ex: OptionalFields = None, **kwargs) -> Stream: stream_type = arg.acquire(stream_type, self.get_stream_type()) if isinstance(stream_type, str): stream_class = StreamType(stream_type).get_class() elif isclass(stream_type): stream_class = stream_type else: stream_class = stream_type.get_class() meta = self.get_compatible_meta(stream_class, ex=ex) meta.update(kwargs) return StreamType.of(stream_type).stream(data, **meta)
def to_stream(self, data: Optional[Iterable] = None, stream_type: AutoStreamType = AUTO, ex: OptionalFields = None, **kwargs) -> Union[RegularStream, Native]: stream_type = Auto.acquire(stream_type, self.get_stream_type()) if data: stream_class = stream_type.get_class() meta = self.get_compatible_meta(stream_class, ex=ex) meta.update(kwargs) if 'count' not in meta: meta['count'] = self.get_count() if 'source' not in meta: meta['source'] = self.get_source() return stream_class(data, **meta) elif stream_type == StreamType.SqlStream: return self else: method_suffix = StreamType.of(stream_type).get_method_suffix() method_name = 'to_{}'.format(method_suffix) stream_method = self.__getattribute__(method_name) return stream_method()