From 8bd68106b08ecf033a6d15219b68fe71ad4652e7 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Wed, 10 May 2023 04:53:47 +0000 Subject: automatic import of python-pycstruct --- python-pycstruct.spec | 669 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 669 insertions(+) create mode 100644 python-pycstruct.spec (limited to 'python-pycstruct.spec') diff --git a/python-pycstruct.spec b/python-pycstruct.spec new file mode 100644 index 0000000..bf766bb --- /dev/null +++ b/python-pycstruct.spec @@ -0,0 +1,669 @@ +%global _empty_manifest_terminate_build 0 +Name: python-pycstruct +Version: 0.12.1 +Release: 1 +Summary: Binary data handling in Python using dictionaries +License: MIT +URL: http://github.com/midstar/pycstruct +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/4a/d5/f2a6ecbc57e0155445b060e8b095df522198a8394916af32add0cdc7db22/pycstruct-0.12.1.tar.gz +BuildArch: noarch + + +%description +# pycstruct + +[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/midstar/pycstruct?svg=true)](https://ci.appveyor.com/api/projects/status/github/midstar/pycstruct) +[![Coverage Status](https://coveralls.io/repos/github/midstar/pycstruct/badge.svg?branch=HEAD)](https://coveralls.io/github/midstar/pycstruct?branch=HEAD) +[![Documentation](https://readthedocs.org/projects/pycstruct/badge/?version=latest)](https://pycstruct.readthedocs.io/en/latest/?badge=latest) + +pycstruct is a python library for converting binary data to and from ordinary +python dictionaries or specific instance objects. + +Data is defined similar to what is done in C language structs, unions, +bitfields and enums. + +Typical usage of this library is read/write binary files or binary data +transmitted over a network. + +Following complex C types are supported: + +- Structs +- Unions +- Bitfields +- Enums + +These types may consist of any traditional data types (integer, unsigned integer, +boolean and float) between 1 to 8 bytes large, arrays (lists), and strings (ASCII/UTF-8). + +Structs, unions, bitfields and enums can be embedded inside other structs/unions +in any level. + +Individual elements can be stored / read in any byte order and alignment. + +pycstruct also supports parsing of existing C language source code to +automatically generate the pycstruct definitions / instances. + +Checkout the full documentation [here](https://pycstruct.readthedocs.io/en/latest/). + +## Installation + +Simply install the package using pip: + + python3 -m pip install pycstruct + +## Example + +Following C has a structure (person) with a set of elements +that are written to a binary file. + +```c +#include +#include +#include + +#pragma pack(1) // To secure no padding is added in struct + +struct person +{ + char name[50]; + unsigned int age; + float height; + bool is_male; + unsigned int nbr_of_children; + unsigned int child_ages[10]; +}; + + +void main(void) { + struct person p; + memset(&p, 0, sizeof(struct person)); + + strcpy(p.name, "Foo Bar"); + p.age = 42; + p.height = 1.75; // m + p.is_male = true; + p.nbr_of_children = 2; + p.child_ages[0] = 7; + p.child_ages[1] = 9; + + FILE *f = fopen("simple_example.dat", "w"); + fwrite(&p, sizeof(struct person), 1, f); + fclose(f); +} +``` + +To read the binary file using pycstruct following code +required. + +```python +import pycstruct + +person = pycstruct.StructDef() +person.add('utf-8', 'name', length=50) +person.add('uint32', 'age') +person.add('float32','height') +person.add('bool8', 'is_male') +person.add('uint32', 'nbr_of_children') +person.add('uint32', 'child_ages', length=10) + +with open('simple_example.dat', 'rb') as f: + inbytes = f.read() + +# Dictionary representation +result = person.deserialize(inbytes) +print('Dictionary object:') +print(str(result)) + +# Alternative, Instance representation +instance = person.instance(inbytes) +print('\nInstance object:') +print(f'name: {instance.name}') +print(f'nbr_of_children: {instance.nbr_of_children}') +print(f'child_ages[1]: {instance.child_ages[1]}') +``` + +The produced output will be:: + + {'name': 'Foo Bar', 'is_male': True, 'nbr_of_children': 2, + 'age': 42, 'child_ages': [7, 9, 0, 0, 0, 0, 0, 0, 0, 0], + 'height': 1.75} + + Instance object: + name: Foo Bar + nbr_of_children: 2 + child_ages[1]: 9 + +To write a binary file from python using the same structure +using pycstruct following code is required. + +```python +import pycstruct + +person = pycstruct.StructDef() +person.add('utf-8', 'name', length=50) +person.add('uint32', 'age') +person.add('float32','height') +person.add('bool8', 'is_male') +person.add('uint32', 'nbr_of_children') +person.add('uint32', 'child_ages', length=10) + +# Dictionary representation +mrGreen = {} +mrGreen['name'] = "MR Green" +mrGreen['age'] = 50 +mrGreen['height'] = 1.93 +mrGreen['is_male'] = True +mrGreen['nbr_of_children'] = 3 +mrGreen['child_ages'] = [13,24,12] +buffer = person.serialize(mrGreen) + +# Alternative, Instance representation +mrGreen = person.instance() +mrGreen.name = "MR Green" +mrGreen.age = 50 +mrGreen.height = 1.93 +mrGreen.is_male = True +mrGreen.nbr_of_children = 3 +mrGreen.child_ages[0] = 13 +mrGreen.child_ages[1] = 24 +mrGreen.child_ages[2] = 12 +buffer = bytes(mrGreen) + +# Write to file +f = open('simple_example_mr_green.dat','wb') +f.write(buffer) +f.close() +``` + +## Parsing source files + +pycstruct also supports parsing C source code defined in external +files or defined in strings. + +Assume the C code listed in the first example is named +simple_example.c. Then you could parse the source +code instead of manually creating the definitions: + +```python +import pycstruct + +definitions = pycstruct.parse_file('simple_example.c') + +with open('simple_example.dat', 'rb') as f: + inbytes = f.read() + +# Dictionary representation +result = definitions['person'].deserialize(inbytes) +print(str(result)) + +# Alternative, Instance representation +instance = definitions['person'].instance(inbytes) +``` + +The produced output will be the same as in the first example (the dictionary). + +## Full documentation + +Checkout the full documentation [here](https://pycstruct.readthedocs.io/en/latest/). + +## Author and license + +This application is written by Joel Midstjärna and is licensed under the MIT License. + + +%package -n python3-pycstruct +Summary: Binary data handling in Python using dictionaries +Provides: python-pycstruct +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-pycstruct +# pycstruct + +[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/midstar/pycstruct?svg=true)](https://ci.appveyor.com/api/projects/status/github/midstar/pycstruct) +[![Coverage Status](https://coveralls.io/repos/github/midstar/pycstruct/badge.svg?branch=HEAD)](https://coveralls.io/github/midstar/pycstruct?branch=HEAD) +[![Documentation](https://readthedocs.org/projects/pycstruct/badge/?version=latest)](https://pycstruct.readthedocs.io/en/latest/?badge=latest) + +pycstruct is a python library for converting binary data to and from ordinary +python dictionaries or specific instance objects. + +Data is defined similar to what is done in C language structs, unions, +bitfields and enums. + +Typical usage of this library is read/write binary files or binary data +transmitted over a network. + +Following complex C types are supported: + +- Structs +- Unions +- Bitfields +- Enums + +These types may consist of any traditional data types (integer, unsigned integer, +boolean and float) between 1 to 8 bytes large, arrays (lists), and strings (ASCII/UTF-8). + +Structs, unions, bitfields and enums can be embedded inside other structs/unions +in any level. + +Individual elements can be stored / read in any byte order and alignment. + +pycstruct also supports parsing of existing C language source code to +automatically generate the pycstruct definitions / instances. + +Checkout the full documentation [here](https://pycstruct.readthedocs.io/en/latest/). + +## Installation + +Simply install the package using pip: + + python3 -m pip install pycstruct + +## Example + +Following C has a structure (person) with a set of elements +that are written to a binary file. + +```c +#include +#include +#include + +#pragma pack(1) // To secure no padding is added in struct + +struct person +{ + char name[50]; + unsigned int age; + float height; + bool is_male; + unsigned int nbr_of_children; + unsigned int child_ages[10]; +}; + + +void main(void) { + struct person p; + memset(&p, 0, sizeof(struct person)); + + strcpy(p.name, "Foo Bar"); + p.age = 42; + p.height = 1.75; // m + p.is_male = true; + p.nbr_of_children = 2; + p.child_ages[0] = 7; + p.child_ages[1] = 9; + + FILE *f = fopen("simple_example.dat", "w"); + fwrite(&p, sizeof(struct person), 1, f); + fclose(f); +} +``` + +To read the binary file using pycstruct following code +required. + +```python +import pycstruct + +person = pycstruct.StructDef() +person.add('utf-8', 'name', length=50) +person.add('uint32', 'age') +person.add('float32','height') +person.add('bool8', 'is_male') +person.add('uint32', 'nbr_of_children') +person.add('uint32', 'child_ages', length=10) + +with open('simple_example.dat', 'rb') as f: + inbytes = f.read() + +# Dictionary representation +result = person.deserialize(inbytes) +print('Dictionary object:') +print(str(result)) + +# Alternative, Instance representation +instance = person.instance(inbytes) +print('\nInstance object:') +print(f'name: {instance.name}') +print(f'nbr_of_children: {instance.nbr_of_children}') +print(f'child_ages[1]: {instance.child_ages[1]}') +``` + +The produced output will be:: + + {'name': 'Foo Bar', 'is_male': True, 'nbr_of_children': 2, + 'age': 42, 'child_ages': [7, 9, 0, 0, 0, 0, 0, 0, 0, 0], + 'height': 1.75} + + Instance object: + name: Foo Bar + nbr_of_children: 2 + child_ages[1]: 9 + +To write a binary file from python using the same structure +using pycstruct following code is required. + +```python +import pycstruct + +person = pycstruct.StructDef() +person.add('utf-8', 'name', length=50) +person.add('uint32', 'age') +person.add('float32','height') +person.add('bool8', 'is_male') +person.add('uint32', 'nbr_of_children') +person.add('uint32', 'child_ages', length=10) + +# Dictionary representation +mrGreen = {} +mrGreen['name'] = "MR Green" +mrGreen['age'] = 50 +mrGreen['height'] = 1.93 +mrGreen['is_male'] = True +mrGreen['nbr_of_children'] = 3 +mrGreen['child_ages'] = [13,24,12] +buffer = person.serialize(mrGreen) + +# Alternative, Instance representation +mrGreen = person.instance() +mrGreen.name = "MR Green" +mrGreen.age = 50 +mrGreen.height = 1.93 +mrGreen.is_male = True +mrGreen.nbr_of_children = 3 +mrGreen.child_ages[0] = 13 +mrGreen.child_ages[1] = 24 +mrGreen.child_ages[2] = 12 +buffer = bytes(mrGreen) + +# Write to file +f = open('simple_example_mr_green.dat','wb') +f.write(buffer) +f.close() +``` + +## Parsing source files + +pycstruct also supports parsing C source code defined in external +files or defined in strings. + +Assume the C code listed in the first example is named +simple_example.c. Then you could parse the source +code instead of manually creating the definitions: + +```python +import pycstruct + +definitions = pycstruct.parse_file('simple_example.c') + +with open('simple_example.dat', 'rb') as f: + inbytes = f.read() + +# Dictionary representation +result = definitions['person'].deserialize(inbytes) +print(str(result)) + +# Alternative, Instance representation +instance = definitions['person'].instance(inbytes) +``` + +The produced output will be the same as in the first example (the dictionary). + +## Full documentation + +Checkout the full documentation [here](https://pycstruct.readthedocs.io/en/latest/). + +## Author and license + +This application is written by Joel Midstjärna and is licensed under the MIT License. + + +%package help +Summary: Development documents and examples for pycstruct +Provides: python3-pycstruct-doc +%description help +# pycstruct + +[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/midstar/pycstruct?svg=true)](https://ci.appveyor.com/api/projects/status/github/midstar/pycstruct) +[![Coverage Status](https://coveralls.io/repos/github/midstar/pycstruct/badge.svg?branch=HEAD)](https://coveralls.io/github/midstar/pycstruct?branch=HEAD) +[![Documentation](https://readthedocs.org/projects/pycstruct/badge/?version=latest)](https://pycstruct.readthedocs.io/en/latest/?badge=latest) + +pycstruct is a python library for converting binary data to and from ordinary +python dictionaries or specific instance objects. + +Data is defined similar to what is done in C language structs, unions, +bitfields and enums. + +Typical usage of this library is read/write binary files or binary data +transmitted over a network. + +Following complex C types are supported: + +- Structs +- Unions +- Bitfields +- Enums + +These types may consist of any traditional data types (integer, unsigned integer, +boolean and float) between 1 to 8 bytes large, arrays (lists), and strings (ASCII/UTF-8). + +Structs, unions, bitfields and enums can be embedded inside other structs/unions +in any level. + +Individual elements can be stored / read in any byte order and alignment. + +pycstruct also supports parsing of existing C language source code to +automatically generate the pycstruct definitions / instances. + +Checkout the full documentation [here](https://pycstruct.readthedocs.io/en/latest/). + +## Installation + +Simply install the package using pip: + + python3 -m pip install pycstruct + +## Example + +Following C has a structure (person) with a set of elements +that are written to a binary file. + +```c +#include +#include +#include + +#pragma pack(1) // To secure no padding is added in struct + +struct person +{ + char name[50]; + unsigned int age; + float height; + bool is_male; + unsigned int nbr_of_children; + unsigned int child_ages[10]; +}; + + +void main(void) { + struct person p; + memset(&p, 0, sizeof(struct person)); + + strcpy(p.name, "Foo Bar"); + p.age = 42; + p.height = 1.75; // m + p.is_male = true; + p.nbr_of_children = 2; + p.child_ages[0] = 7; + p.child_ages[1] = 9; + + FILE *f = fopen("simple_example.dat", "w"); + fwrite(&p, sizeof(struct person), 1, f); + fclose(f); +} +``` + +To read the binary file using pycstruct following code +required. + +```python +import pycstruct + +person = pycstruct.StructDef() +person.add('utf-8', 'name', length=50) +person.add('uint32', 'age') +person.add('float32','height') +person.add('bool8', 'is_male') +person.add('uint32', 'nbr_of_children') +person.add('uint32', 'child_ages', length=10) + +with open('simple_example.dat', 'rb') as f: + inbytes = f.read() + +# Dictionary representation +result = person.deserialize(inbytes) +print('Dictionary object:') +print(str(result)) + +# Alternative, Instance representation +instance = person.instance(inbytes) +print('\nInstance object:') +print(f'name: {instance.name}') +print(f'nbr_of_children: {instance.nbr_of_children}') +print(f'child_ages[1]: {instance.child_ages[1]}') +``` + +The produced output will be:: + + {'name': 'Foo Bar', 'is_male': True, 'nbr_of_children': 2, + 'age': 42, 'child_ages': [7, 9, 0, 0, 0, 0, 0, 0, 0, 0], + 'height': 1.75} + + Instance object: + name: Foo Bar + nbr_of_children: 2 + child_ages[1]: 9 + +To write a binary file from python using the same structure +using pycstruct following code is required. + +```python +import pycstruct + +person = pycstruct.StructDef() +person.add('utf-8', 'name', length=50) +person.add('uint32', 'age') +person.add('float32','height') +person.add('bool8', 'is_male') +person.add('uint32', 'nbr_of_children') +person.add('uint32', 'child_ages', length=10) + +# Dictionary representation +mrGreen = {} +mrGreen['name'] = "MR Green" +mrGreen['age'] = 50 +mrGreen['height'] = 1.93 +mrGreen['is_male'] = True +mrGreen['nbr_of_children'] = 3 +mrGreen['child_ages'] = [13,24,12] +buffer = person.serialize(mrGreen) + +# Alternative, Instance representation +mrGreen = person.instance() +mrGreen.name = "MR Green" +mrGreen.age = 50 +mrGreen.height = 1.93 +mrGreen.is_male = True +mrGreen.nbr_of_children = 3 +mrGreen.child_ages[0] = 13 +mrGreen.child_ages[1] = 24 +mrGreen.child_ages[2] = 12 +buffer = bytes(mrGreen) + +# Write to file +f = open('simple_example_mr_green.dat','wb') +f.write(buffer) +f.close() +``` + +## Parsing source files + +pycstruct also supports parsing C source code defined in external +files or defined in strings. + +Assume the C code listed in the first example is named +simple_example.c. Then you could parse the source +code instead of manually creating the definitions: + +```python +import pycstruct + +definitions = pycstruct.parse_file('simple_example.c') + +with open('simple_example.dat', 'rb') as f: + inbytes = f.read() + +# Dictionary representation +result = definitions['person'].deserialize(inbytes) +print(str(result)) + +# Alternative, Instance representation +instance = definitions['person'].instance(inbytes) +``` + +The produced output will be the same as in the first example (the dictionary). + +## Full documentation + +Checkout the full documentation [here](https://pycstruct.readthedocs.io/en/latest/). + +## Author and license + +This application is written by Joel Midstjärna and is licensed under the MIT License. + + +%prep +%autosetup -n pycstruct-0.12.1 + +%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-pycstruct -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 10 2023 Python_Bot - 0.12.1-1 +- Package Spec generated -- cgit v1.2.3