easybits 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
easybits/__init__.py CHANGED
@@ -17,6 +17,8 @@ class Bits(bitarray):
17
17
  - Integers are always signed.
18
18
  """
19
19
 
20
+ default_text_encoding = 'ascii'
21
+
20
22
  @classmethod
21
23
  def zeros(cls, length):
22
24
  return Bits(zeros(length))
@@ -25,7 +27,7 @@ class Bits(bitarray):
25
27
  def ones(cls, length):
26
28
  return Bits(ones(length))
27
29
 
28
- def __new__(cls, value=None, length=None, encoding='ascii'):
30
+ def __new__(cls, value=None, length=None, encoding=None):
29
31
  if value is None:
30
32
  bits = bitarray(length or 0)
31
33
  elif isinstance(value, bytes):
@@ -38,11 +40,14 @@ class Bits(bitarray):
38
40
  raise IntegersRequireLength()
39
41
  bits = int2ba(value, length=length, signed=True)
40
42
  elif isinstance(value, str):
41
- if is_bit_string(value):
43
+ if encoding:
44
+ bits = bitarray()
45
+ bits.frombytes(value.encode(encoding))
46
+ elif is_bit_string(value):
42
47
  bits = bitarray(value)
43
48
  else:
44
49
  bits = bitarray()
45
- bits.frombytes(value.encode(encoding))
50
+ bits.frombytes(value.encode(cls.default_text_encoding))
46
51
  elif isinstance(value, list):
47
52
  bits = bitarray(value)
48
53
  elif isinstance(value, bitarray):
@@ -96,7 +101,7 @@ class Bits(bitarray):
96
101
  return result
97
102
 
98
103
  def __sub__(self, other):
99
- """Performs bitwise addition on `self` and `other`. Does not
104
+ """Performs bitwise subtraction on `self` and `other`. Does not
100
105
  check for overflow.
101
106
  """
102
107
  a, b = self, Bits(other)
easybits/util.py CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  def is_bit_string(value):
3
3
  bit_chars = {'1', '0', ' '}
4
- return not (set(value) - bit_chars)
4
+ return value.strip() and not (set(value) - bit_chars)
5
5
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: easybits
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A friendly interface for exploring bits.
5
5
  Author: Chris Proctor
6
6
  Author-email: chris@chrisproctor.net
@@ -9,6 +9,8 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
12
14
  Requires-Dist: bitarray (>=3.0.0,<4.0.0)
13
15
  Description-Content-Type: text/markdown
14
16
 
@@ -0,0 +1,6 @@
1
+ easybits/__init__.py,sha256=na58npOKL8pdkPpaG06rTvv8EX1BQaNYx_K0tisschA,3456
2
+ easybits/errors.py,sha256=MPQGCYUave-PCKP4IkfIS2NJzL2j2KH2W3rlPofsigo,478
3
+ easybits/util.py,sha256=mPo6AyWfZrfz5m31sFylHsEdMQt0OixEgpN-U-ZPIuU,118
4
+ easybits-0.1.4.dist-info/METADATA,sha256=ZSqDCyY0XWhgZREZ_lMaTKSJiglvwBUdc9_3Qhq-pxI,627
5
+ easybits-0.1.4.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
6
+ easybits-0.1.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.5.1
2
+ Generator: poetry-core 2.0.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- easybits/__init__.py,sha256=Hbz2irQzF8juhojdybx3S_jBX272Mgd_L1VCQIfpx6E,3286
2
- easybits/errors.py,sha256=MPQGCYUave-PCKP4IkfIS2NJzL2j2KH2W3rlPofsigo,478
3
- easybits/util.py,sha256=GYlFDgqk1sBkFidKsoo9xaO7QZ8_v7KFavP2KnV0mZ8,100
4
- easybits-0.1.2.dist-info/METADATA,sha256=1prbZ3ZJEKyIh799B88gVfRJq9Og2I4aEytHsqw0Rhc,525
5
- easybits-0.1.2.dist-info/WHEEL,sha256=kLuE8m1WYU0Ig0_YEGrXyTtiJvKPpLpDEiChiNyei5Y,88
6
- easybits-0.1.2.dist-info/RECORD,,