Closed lgj2006 closed 3 years ago
I encounter about the same with python 3.8. When running this example from read the docs, https://bitstring.readthedocs.io/en/latest/constbitstream.html#bitstring.ConstBitStream:
from bitstring import ConstBitStream
bs = ConstBitStream('0x123456')
bs.peek('hex:8')
KeyError Traceback (most recent call last)
~\anaconda3\envs\climada_v2\lib\site-packages\bitstring.py in _readtoken(self, name, pos, length)
2097 try:
-> 2098 val = name_to_read[name](self, length, pos)
2099 return val, pos + length
KeyError: 'hex'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-28-18695a3677eb> in <module>
1 from bitstring import ConstBitStream
2 bs = ConstBitStream('0x123456')
----> 3 bs.peek('hex:8')
~\anaconda3\envs\climada_v2\lib\site-packages\bitstring.py in peek(self, fmt)
4013 """
4014 pos_before = self._pos
-> 4015 value = self.read(fmt)
4016 self._pos = pos_before
4017 return value
~\anaconda3\envs\climada_v2\lib\site-packages\bitstring.py in read(self, fmt)
3950 if length is None:
3951 length = self.len - self._pos
-> 3952 value, self._pos = self._readtoken(name, self._pos, length)
3953 return value
3954
~\anaconda3\envs\climada_v2\lib\site-packages\bitstring.py in _readtoken(self, name, pos, length)
2101 if name == 'pad':
2102 return None, pos + length
-> 2103 raise ValueError("Can't parse token {0}:{1}".format(name, length))
2104 except TypeError:
2105 # This is for the 'ue', 'se' and 'bool' tokens. They will also return the new pos.
ValueError: Can't parse token hex:8
Thanks. Not sure yet what's going on here as this should all be covered by the unit tests, but it's clearly broken. I've yanked the 3.1.8 release from PyPI and will look into it properly and prepare a new release. Suggest you pip install bitstring==3.1.7
for the time being...
👍 Thank you!
Should all be fixed in 3.1.9. Strangely the unit tests were all passing for 3.1.8 despite it being obviously broken.
Environment: python 3.6.8
And I find that bitstring.name_to_read is always {}.