Exemplo n.º 1
0
 def __init__(
         self,
         data,
         name=AUTO, check=True,
         count=None, less_than=None,
         value_stream_type: Union[StreamType, str] = None,
         source=None, context=None,
         max_items_in_memory=AUTO,
         tmp_files=AUTO,
 ):
     super().__init__(
         data,
         name=name, check=check,
         count=count, less_than=less_than,
         source=source, context=context,
         max_items_in_memory=max_items_in_memory,
         tmp_files=tmp_files,
     )
     if value_stream_type is None:
         self.value_stream_type = StreamType.AnyStream
     else:
         try:
             value_stream_type = StreamType(value_stream_type)
         except ValueError:
             value_stream_type = StreamType(value_stream_type.value)
         self.value_stream_type = value_stream_type or StreamType.AnyStream
Exemplo n.º 2
0
 def stream(self,
            data: Iterable,
            stream_type: AutoStreamType = AUTO,
            ex: OptionalArguments = None,
            save_name: bool = True,
            save_count: bool = True,
            **kwargs) -> Stream:
     if arg.is_defined(stream_type):
         if isinstance(stream_type, str):
             stream_class = StreamType(stream_type).get_class()
         else:
             stream_class = stream_type.get_class()
         meta = self.get_compatible_meta(stream_class, ex=ex)
     else:
         stream_class = self.__class__
         meta = self.get_meta()
     if not save_name:
         meta.pop('name')
     if not save_count:
         meta.pop('count')
     meta.update(kwargs)
     if 'context' not in meta:
         meta['context'] = self.get_context()
     stream = stream_class(data, **meta)
     return stream
Exemplo n.º 3
0
 def to_stream(
         self,
         data: Data = AUTO,
         stream_type: AutoStreamType = AUTO,
         ex: OptionalFields = None,
         **kwargs
 ) -> Stream:
     stream_type = arg.delayed_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
     elif isinstance(stream_type, StreamType) or hasattr(stream_type, 'get_class'):
         stream_class = stream_type.get_class()
     else:
         raise TypeError('AnyStream.to_stream(data, stream_type): expected StreamType, got {}'.format(stream_type))
     if not arg.is_defined(data):
         if hasattr(self, 'get_items_of_type'):
             item_type = stream_class.get_item_type()
             data = self.get_items_of_type(item_type)
         else:
             data = self.get_data()
     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()
     stream = stream_class(data, **meta)
     return self._assume_stream(stream)
Exemplo n.º 4
0
def stream(stream_type, *args, **kwargs) -> StreamInterface:
    if is_stream_class(STREAM_CLASSES):
        stream_class = stream_type
    else:
        stream_class = StreamType(stream_type).get_class()
    if 'context' not in kwargs:
        kwargs['context'] = get_context()
    return stream_class(*args, **kwargs)
Exemplo n.º 5
0
 def get_class(cls, other: Stream = None):
     if other is None:
         return cls
     elif isinstance(other, (StreamType, str)):
         return StreamType(other).get_class()
     elif inspect.isclass(other):
         return other
     else:
         raise TypeError(
             '"other" parameter must be class or StreamType (got {})'.
             format(type(other)))
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 def to_stream(self,
               data: Data = AUTO,
               stream_type: AutoStreamType = AUTO,
               ex: OptionalFields = None,
               **kwargs) -> Stream:
     stream_type = arg.delayed_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()
     data = arg.delayed_acquire(data, self.get_data)
     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)
Exemplo n.º 8
0
 def to_stream(self,
               stream_type: Union[StreamType, str, Auto] = AUTO,
               **kwargs) -> Stream:
     stream_class = StreamType(stream_type).get_class()
     return stream_class(self.get_data(), **kwargs)
Exemplo n.º 9
0
 def get_stream(self, to=AUTO, verbose: AutoBool = AUTO) -> Stream:
     to = arg.acquire(to, self.get_stream_type())
     return self.to_stream_class(
         stream_class=StreamType(to).get_class(),
         verbose=verbose,
     )
Exemplo n.º 10
0
def get_class(stream_type):
    return StreamType(stream_type).get_class()