diff options
author | CoprDistGit <infra@openeuler.org> | 2023-06-20 09:28:27 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-06-20 09:28:27 +0000 |
commit | 37e21f5b9f25a1f6552823ed61df89091b9293c9 (patch) | |
tree | bd5d50d51bcacae9ff7341667dbd5dea82f4fce0 | |
parent | e144fa3d6b6c0a84d9322410d27025f2314402ff (diff) |
automatic import of python-ordered-demuxeropeneuler20.03
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-ordered-demuxer.spec | 334 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 336 insertions, 0 deletions
@@ -0,0 +1 @@ +/ordered_demuxer-0.1.0.tar.gz diff --git a/python-ordered-demuxer.spec b/python-ordered-demuxer.spec new file mode 100644 index 0000000..6a83f62 --- /dev/null +++ b/python-ordered-demuxer.spec @@ -0,0 +1,334 @@ +%global _empty_manifest_terminate_build 0 +Name: python-ordered-demuxer +Version: 0.1.0 +Release: 1 +Summary: Break iterators into ordered chunks +License: MIT +URL: https://github.com/lissahyacinth/ordered_demuxer +Source0: https://mirrors.aliyun.com/pypi/web/packages/ac/41/5fc2f384a904b4c4b65ca44078baa880d164daff9d6888fcbe1892d4b156/ordered_demuxer-0.1.0.tar.gz +BuildArch: noarch + +Requires: python3-pytest + +%description +# Ordered Demultiplexer in Python +Single pass approach to Demultiplexing/Demuxing + +Break an iterator into multiple iterators based on a set of filters. + +Typical demuxers will place elements into different iterators, +such as splitting [0,1,2,3] into ([0,2], [1,3]) based on odd or +even elements. Ordered Demuxers focus on breaking iterators into +contiguous blocks that are meant to be immediately worked upon, +without having to iterate over the list more than once. + +This makes them appropriate to use with iterators where the contents +cannot be fully held in memory, such as retrieving data online. + +### Example +With any iterable input such as +```python +x = iter([ (_, 0), (_, 1), (MessageEnd, 2), (_, 3), (_, 4), (MessageEnd, 5) ]) +``` + + +This can be broken into; +```python +Iterator [ + Iterator [(_, 0), (_, 1), (MessageEnd, 2)], + Iterator [(_, 3), (_, 4), (MessageEnd, 5)] +] +``` + +Without passing over each element of data multiple times. This allows for methods like; + +```python +for data_stream in demuxed_stream: + for element in data_stream: + function(element) +``` + +Or more interestingly; + +```python +def foo(x: Iterator[T]): + ... + +for data_stream in demuxed_stream: + foo(data_stream) +``` + +`foo` will consume part of the original iterator, up until the next break point, but still behave identically to passing it an iterator of just the data required. + +Due to the way the filters are available within the Demuxer, it's also possible to send these partial iterators to functions according to the relevant filter, i.e. + +```python +conditions = [ + FilterCondition(lambda x: x[0] == 'MessageEnd', 'SuccessfulMessageStream'), + FilterCondition(lambda x: x[0] == 'MessageFailed', 'FailedMessageStream') +] + +for data_stream in demuxed_stream: + if demuxed_stream.condition_met is not None: + match demuxed_stream.condition_met.name: + case 'SuccessfulMessageStream': + foo(data_stream) + case 'FailedMessageStream': + foo2(data_stream) + else: + foo3(data_stream) +``` + +Although it requires the consumption of each iterator entirely to make this possible. + +## Installation +```bash +python -m pip install ordered-demuxer +``` + +## Usage +```python +>>> from ordered_demuxer import FilterCondition, OrderedDemuxer +>>> x = [1, 2, 3, 4] +>>> y = FilterCondition(lambda x: x == 2) +>>> splt = OrderedDemuxer(data_source=iter(x), filter=y, split_after=True) +>>> x_iter = splt.__next__() +>>> print(list(x_iter)) + [1, 2] +``` + + + + +%package -n python3-ordered-demuxer +Summary: Break iterators into ordered chunks +Provides: python-ordered-demuxer +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-ordered-demuxer +# Ordered Demultiplexer in Python +Single pass approach to Demultiplexing/Demuxing + +Break an iterator into multiple iterators based on a set of filters. + +Typical demuxers will place elements into different iterators, +such as splitting [0,1,2,3] into ([0,2], [1,3]) based on odd or +even elements. Ordered Demuxers focus on breaking iterators into +contiguous blocks that are meant to be immediately worked upon, +without having to iterate over the list more than once. + +This makes them appropriate to use with iterators where the contents +cannot be fully held in memory, such as retrieving data online. + +### Example +With any iterable input such as +```python +x = iter([ (_, 0), (_, 1), (MessageEnd, 2), (_, 3), (_, 4), (MessageEnd, 5) ]) +``` + + +This can be broken into; +```python +Iterator [ + Iterator [(_, 0), (_, 1), (MessageEnd, 2)], + Iterator [(_, 3), (_, 4), (MessageEnd, 5)] +] +``` + +Without passing over each element of data multiple times. This allows for methods like; + +```python +for data_stream in demuxed_stream: + for element in data_stream: + function(element) +``` + +Or more interestingly; + +```python +def foo(x: Iterator[T]): + ... + +for data_stream in demuxed_stream: + foo(data_stream) +``` + +`foo` will consume part of the original iterator, up until the next break point, but still behave identically to passing it an iterator of just the data required. + +Due to the way the filters are available within the Demuxer, it's also possible to send these partial iterators to functions according to the relevant filter, i.e. + +```python +conditions = [ + FilterCondition(lambda x: x[0] == 'MessageEnd', 'SuccessfulMessageStream'), + FilterCondition(lambda x: x[0] == 'MessageFailed', 'FailedMessageStream') +] + +for data_stream in demuxed_stream: + if demuxed_stream.condition_met is not None: + match demuxed_stream.condition_met.name: + case 'SuccessfulMessageStream': + foo(data_stream) + case 'FailedMessageStream': + foo2(data_stream) + else: + foo3(data_stream) +``` + +Although it requires the consumption of each iterator entirely to make this possible. + +## Installation +```bash +python -m pip install ordered-demuxer +``` + +## Usage +```python +>>> from ordered_demuxer import FilterCondition, OrderedDemuxer +>>> x = [1, 2, 3, 4] +>>> y = FilterCondition(lambda x: x == 2) +>>> splt = OrderedDemuxer(data_source=iter(x), filter=y, split_after=True) +>>> x_iter = splt.__next__() +>>> print(list(x_iter)) + [1, 2] +``` + + + + +%package help +Summary: Development documents and examples for ordered-demuxer +Provides: python3-ordered-demuxer-doc +%description help +# Ordered Demultiplexer in Python +Single pass approach to Demultiplexing/Demuxing + +Break an iterator into multiple iterators based on a set of filters. + +Typical demuxers will place elements into different iterators, +such as splitting [0,1,2,3] into ([0,2], [1,3]) based on odd or +even elements. Ordered Demuxers focus on breaking iterators into +contiguous blocks that are meant to be immediately worked upon, +without having to iterate over the list more than once. + +This makes them appropriate to use with iterators where the contents +cannot be fully held in memory, such as retrieving data online. + +### Example +With any iterable input such as +```python +x = iter([ (_, 0), (_, 1), (MessageEnd, 2), (_, 3), (_, 4), (MessageEnd, 5) ]) +``` + + +This can be broken into; +```python +Iterator [ + Iterator [(_, 0), (_, 1), (MessageEnd, 2)], + Iterator [(_, 3), (_, 4), (MessageEnd, 5)] +] +``` + +Without passing over each element of data multiple times. This allows for methods like; + +```python +for data_stream in demuxed_stream: + for element in data_stream: + function(element) +``` + +Or more interestingly; + +```python +def foo(x: Iterator[T]): + ... + +for data_stream in demuxed_stream: + foo(data_stream) +``` + +`foo` will consume part of the original iterator, up until the next break point, but still behave identically to passing it an iterator of just the data required. + +Due to the way the filters are available within the Demuxer, it's also possible to send these partial iterators to functions according to the relevant filter, i.e. + +```python +conditions = [ + FilterCondition(lambda x: x[0] == 'MessageEnd', 'SuccessfulMessageStream'), + FilterCondition(lambda x: x[0] == 'MessageFailed', 'FailedMessageStream') +] + +for data_stream in demuxed_stream: + if demuxed_stream.condition_met is not None: + match demuxed_stream.condition_met.name: + case 'SuccessfulMessageStream': + foo(data_stream) + case 'FailedMessageStream': + foo2(data_stream) + else: + foo3(data_stream) +``` + +Although it requires the consumption of each iterator entirely to make this possible. + +## Installation +```bash +python -m pip install ordered-demuxer +``` + +## Usage +```python +>>> from ordered_demuxer import FilterCondition, OrderedDemuxer +>>> x = [1, 2, 3, 4] +>>> y = FilterCondition(lambda x: x == 2) +>>> splt = OrderedDemuxer(data_source=iter(x), filter=y, split_after=True) +>>> x_iter = splt.__next__() +>>> print(list(x_iter)) + [1, 2] +``` + + + + +%prep +%autosetup -n ordered_demuxer-0.1.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-ordered-demuxer -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.0-1 +- Package Spec generated @@ -0,0 +1 @@ +04c37f9ac83d220610a25999175b0af9 ordered_demuxer-0.1.0.tar.gz |