Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import binascii if ubinascii not found #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jerryneedell
Copy link

addresses #110
Circuitpython now uses binascii so the "get" command fails trying to import ubinascii.
This PR adds a try/except to import binascii as ubinascii if ubinascii is not present.

@cameronbunce
Copy link

I have no authority here, but issue #110 is something that has been annoying in ampy for some time. I have implemented the above fix locally and confirm that it works and is non-breaking for micropython devices as well.
I would like to see this merged.

@wyattearp
Copy link

For what it's worth, I tested this on an HUZZAH32 V2 running:

  • adafruit-ampy (1.1.0)
  • Adafruit CircuitPython 8.1.0 on 2023-05-22; Adafruit Feather ESP32 V2 with ESP32

I was unable to make this work, it appears that the left over item is now:

# files.py
    def get(self, filename):
        """Retrieve the contents of the specified file and return its contents
        as a byte string.
        """
        # Open the file and read it a few bytes at a time and print out the
        # raw bytes.  Be careful not to overload the UART buffer so only write
        # a few bytes at a time, and don't use print since it adds newlines and
        # expects string data.
        command = """
            import sys
            import binascii
            with open('{0}', 'rb') as infile:
                while True:
                    result = infile.read({1})
                    if result == b'':
                        break
                    # len = sys.stdout.write(ubinascii.hexlify(result))
                    # use actual binascii
                    len = sys.stdout.write(binascii.hexlify(result))

The above patch correct it for me, which I assume is just a missed merge between your changes and the circuit python project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants