Compare commits

..

5 Commits

Author SHA1 Message Date
S Groesz 49ef87f8c9 add bit_len to Bytes 2021-04-17 05:01:32 +00:00
S Groesz ecc1b3bd8d update source code location 2021-04-14 23:34:23 +00:00
S Groesz 55ae3544d5 add dev notes 2021-04-14 03:27:53 +00:00
S Groesz de7c42fe8f fix typo 2021-04-14 03:17:42 +00:00
S Groesz 34fa1b4502 update readme 2021-04-14 03:06:08 +00:00
4 changed files with 40 additions and 5 deletions

View File

@ -8,6 +8,20 @@ Intended to be compatible with Python 3.6+. Written and tested against Python
If something doesn't work in Python 3.6, it's a bug. Please report any such
bugs if they are encountered.
# PyPI
View on PyPI at [https://pypi.org/project/binary-bits/](https://pypi.org/project/binary-bits/)
Install from PyPI:
python3 -m pip install binary-bits --upgrade
Use in your project:
```python
import bits
my_bytes = bits.Bytes(bytes.fromhex('deadbeef'))
```
# Similar projects
## [py-flags](https://pypi.org/project/py-flags/)

15
dev.md Normal file
View File

@ -0,0 +1,15 @@
Steps to publish to PyPI:
1) run `make test`
2) update version in setup.py
3) Tag the current release in git to match the version in setup.py
git tag -a 1.2.0 -m 'Release 1.2.0'
4) commit any pending changes to git
git add .
git commit -m 'commit changes'
git push origin 1.2.0
5) test publish
./publish.sh test
6) publish to PyPI
./publish.sh pypi

View File

@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="binary-bits",
version="1.1.0",
version="1.1.1",
author="S Groesz",
description="Provide additional methods for working with binary data",
long_description=long_description,
@ -28,6 +28,6 @@ setuptools.setup(
'test': ['coverage'],
},
project_urls={
'Source': 'http://git.groesz.org/wp/bits/',
'Source': 'http://git.groesz.org/Groesz.org/bits/',
},
)

View File

@ -930,12 +930,12 @@ class Bits:
class Bytes:
"""
A colletion of Bits with convenient properties for working with binary data
A collection of Bits with convenience methods for working with binary data
"""
import sys
def __init__(self, var=None, byteorder="big"):
def __init__(self, var=None, byteorder="big", bits=None):
"""
var: a supported variant (object)
byteorder: notimplemented, mostly ignored
@ -943,11 +943,17 @@ class Bytes:
self.__raw = bytearray(b'')
self.__small = False
self.__iter = None
self.__list_len = None
self.__bit_len = None
if byteorder.lower() in ["small", "little"]:
self.__small = True
if var is not None:
self.__raw = self.__to_bytearray(var)
if bits is None:
self.__bit_len = len(self.__raw)
else:
if not isinstance(bits, (int, Bytes, Bit)):
raise TypeError(f"bits argument must be int, not {type(bits)}")
self.__bit_len = int(bits)
def __bytes__(self):
"""