greatscottgadgets / libgreat

a library to help you do Great things
BSD 3-Clause "New" or "Revised" License
31 stars 25 forks source link

re.match with Python 3.5 #7

Closed agkunkle closed 5 years ago

agkunkle commented 5 years ago

I am attempting to use a GreatFET ONE with the Facedancer project on Ubuntu 16.04.06 LTS using Python 3.5. Trying to run any of the facedancer-XX.py examples results in the following exception:

GreatDancer initialized
GreatDancer connected device USB keyboard device
-- Reset requested! --
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 772, in execute_command
    result = self.unpack(out_format, raw_result)
  File "/usr/local/lib/python3.5/dist-packages/backports/functools_lru_cache.py", line 137, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 609, in unpack
    bytes_consumed, raw_bytes = cls._split_off_bytes_for_format(subformat, raw_bytes)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 417, in _split_off_bytes_for_format
    num_bytes_consumed = cls._get_bytes_consumed_by_format(format_string, raw_bytes)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 391, in _get_bytes_consumed_by_format
    if match[1] is None:
TypeError: '_sre.SRE_Match' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./facedancer-keyboard.py", line 14, in <module>
    d.run()
  File ".../Facedancer/facedancer/USBDevice.py", line 166, in run
    self.scheduler.run()
  File ".../Facedancer/facedancer/core.py", line 512, in run
    task()
  File ".../Facedancer/facedancer/USBDevice.py", line 84, in <lambda>
    self.scheduler.add_task(lambda : self.maxusb_app.service_irqs())
  File ".../Facedancer/facedancer/backends/GreatDancerApp.py", line 747, in service_irqs
    self._handle_setup_events()
  File ".../Facedancer/facedancer/backends/GreatDancerApp.py", line 359, in _handle_setup_events
    self._handle_setup_event_on_endpoint(i)
  File ".../Facedancer/facedancer/backends/GreatDancerApp.py", line 374, in _handle_setup_event_on_endpoint
    data = self.api.read_setup(endpoint_number)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 1088, in method
    timeout=timeout, max_response_length=max_response_length, encoding=encoding, *arguments)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 1243, in execute_command
    out_format, *arguments, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 779, in execute_command
    future_utils.raise_with_traceback(outer_exception, sys.exc_info()[2])
  File "/usr/local/lib/python3.5/dist-packages/future/utils/__init__.py", line 421, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 772, in execute_command
    result = self.unpack(out_format, raw_result)
  File "/usr/local/lib/python3.5/dist-packages/backports/functools_lru_cache.py", line 137, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 609, in unpack
    bytes_consumed, raw_bytes = cls._split_off_bytes_for_format(subformat, raw_bytes)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 417, in _split_off_bytes_for_format
    num_bytes_consumed = cls._get_bytes_consumed_by_format(format_string, raw_bytes)
  File "/usr/local/lib/python3.5/dist-packages/pygreat/comms.py", line 391, in _get_bytes_consumed_by_format
    if match[1] is None:
TypeError: unexpected return RPC `read_setup`; innner message: '_sre.SRE_Match' object is not subscriptable; format: <8X

I believe this is due to how Python changed the behavior of re.match() in Python 3.6. Just wanted you to be aware as I don't think the pip-installed greatfet module enforces that version to be used.

I just made a local fix by updating match[1] to match.groups(1) and all seems to be working fine now.

Thanks for supporting such a cool project!

ktemkin commented 5 years ago

Good catch! I've seen someone run into this one before during a training; but I didn't manage to capture it in GitHub before it slipped my mind entirely.

Your assessment of the issue is correct -- and your local fix is a good solution. I don't see any reason not to use match.groups(1) in the codebase -- feel free to submit a PR with that change so it can be credited properly. :)

agkunkle commented 5 years ago

All done, thanks for taking a look so quickly.

--AK

On Wed, Aug 14, 2019 at 2:44 AM Kate Temkin notifications@github.com wrote:

Good catch! I've seen someone run into this one before during a training; but I didn't manage to capture it in GitHub before it slipped my mind entirely.

Your assessment of the issue is correct -- and your local fix is a good solution. I don't see any reason not to use match.groups(1) in the codebase -- feel free to submit a PR with that change so it can be credited properly. :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/greatscottgadgets/libgreat/issues/7?email_source=notifications&email_token=AALC6RHUH6Z7YKHCRRPCBM3QEOSVTA5CNFSM4ILMMMY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4H3G6I#issuecomment-521122681, or mute the thread https://github.com/notifications/unsubscribe-auth/AALC6RAJ5UG6C2L7EOFRJP3QEOSVTANCNFSM4ILMMMYQ .