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

NoneType Object has no Attribute 'auto_match' #137

Closed
Shenport opened this issue Apr 20, 2023 · 2 comments
Closed

NoneType Object has no Attribute 'auto_match' #137

Shenport opened this issue Apr 20, 2023 · 2 comments

Comments

@Shenport
Copy link

Shenport commented Apr 20, 2023

I have been made multiple attempts to install rfcat on multiple machines. I have tried on Debian, Ubuntu, and Windows, with both Python 3.8 and Python 3.11. Rfcat installs successfully on each, and the specan function works. However, when I attempt to use interactive mode, every time I try to type a bracket "()" or "[]", I get the following error:

Unhandled exception in event loop:
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\input\win32.py", line 613, in ready
    callback()
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\application\application.py", line 698, in read_from_input
    self.key_processor.process_keys()
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 272, in process_keys
    self._process_coroutine.send(key_press)
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 170, in _process
    matches = self._get_matches(buffer)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 128, in _get_matches
    return [b for b in self._bindings.get_bindings_for_keys(keys) if b.filter()]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 128, in <listcomp>
    return [b for b in self._bindings.get_bindings_for_keys(keys) if b.filter()]
                                                                     ^^^^^^^^^^
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\filters\base.py", line 134, in __call__
    return all(f() for f in self.filters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\filters\base.py", line 134, in <genexpr>
    return all(f() for f in self.filters)
               ^^^
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\prompt_toolkit\filters\base.py", line 248, in __call__
    return self.func()
           ^^^^^^^^^^^
  File "C:\Users\super\AppData\Local\Programs\Python\Python311\Lib\site-packages\IPython\terminal\shortcuts\filters.py", line 76, in auto_match
    return shell.auto_match
           ^^^^^^^^^^^^^^^^

Exception 'NoneType' object has no attribute 'auto_match'

^ This is from my most recent attempt, which was Windows. Minus some semantics, the error is the same on Debian/Ubuntu.

Am I missing something in the install process?

@Spiro01
Copy link
Contributor

Spiro01 commented Apr 28, 2023

Hi, i had the same problem, from what i understand there is an issue with the new version of IPython, if you want more details you can found it here: greatscottgadgets/greatfet#414.

I fixed it by doing the same changes as mentioned on the pull request mentioned before.

replace the file rflib/__init__.py with this:

remember to run python3 setup.py build and python3 setup.py install

#!/usr/bin/env ipython3 -i --no-banner

from __future__ import print_function
from __future__ import absolute_import

from builtins import str
from builtins import range
from .chipcon_nic import *
import rflib.bits as rfbits

RFCAT_START_SPECAN  = 0x40
RFCAT_STOP_SPECAN   = 0x41

MAX_FREQ = 936e6

class RfCat(FHSSNIC):
    def RFdump(self, msg="Receiving", maxnum=100, timeoutms=1000):
        try:
            for x in range(maxnum):
                y, t = self.RFrecv(timeoutms)
                print("(%5.3f) %s:  %s" % (t, msg, hexlify(y)))
        except ChipconUsbTimeoutException:
            pass

    def scan(self, basefreq=902e6, inc=250e3, count=104, delaysec=2, drate=38400, lowball=1):
        '''
        scan for signal over a range of frequencies
        '''
        self.RFdump("Clearing")
        self.lowball(lowball)
        self.setMdmDRate(drate)
        print("Scanning range:  ")
        while not keystop():
            try:
                print("(press Enter to quit)")
                for freq in range(int(basefreq), int(basefreq+(inc*count)), int(inc)):
                    print("Scanning for frequency %d..." % freq)
                    self.setFreq(freq)
                    self.RFdump(timeoutms=delaysec*1000)
                    if keystop():
                        break
            except KeyboardInterrupt:
                print("Please press <enter> to stop")

        sys.stdin.read(1)
        self.lowballRestore()

    def specan(self, centfreq=915e6, inc=250e3, count=104):
        '''
        Enter Spectrum Analyzer mode.
        this sets the mode of the dongle to send data, and brings up the GUI.

        centfreq is the center frequency
        '''
        freq, delta = self._doSpecAn(centfreq, inc, count)

        import rflib.ccspecan as rfspecan
        rfspecan.ensureQapp()

        fhigh = freq + (delta*(count+1))

        window = rfspecan.Window(self, freq, fhigh, delta, 0)
        window.show()
        rfspecan._qt_app.exec_()

    def _doSpecAn(self, centfreq, inc, count):
        '''
        store radio config and start sending spectrum analysis data

        centfreq = Center Frequency
        '''
        if count>255:
            raise Exception("sorry, only 255 samples per pass... (count)")

        spectrum = (count * inc)
        halfspec = spectrum / 2.0
        basefreq = centfreq - halfspec
        if (count * inc) + basefreq > MAX_FREQ:
            raise Exception("Sorry, %1.3f + (%1.3f * %1.3f) is higher than %1.3f" %
                    (basefreq, count, inc))
        self.getRadioConfig()
        self._specan_backup_radiocfg = self.radiocfg

        self.setFreq(basefreq)
        self.setMdmChanSpc(inc)

        freq, fbytes = self.getFreq()
        delta = self.getMdmChanSpc()

        self.send(APP_NIC, RFCAT_START_SPECAN, b"%c" % (count) )
        return freq, delta

    def _stopSpecAn(self):
        '''
        stop sending rfdata and return radio to original config
        '''
        self.send(APP_NIC, RFCAT_STOP_SPECAN, b'')
        self.radiocfg = self._specan_backup_radiocfg
        self.setRadioConfig()


    def rf_configure(self, *args, **kwargs):
        self.setRFparameters(*args, **kwargs)

    def rf_redirection(self, fdtup, use_rawinput=False, printable=False):
        buf = b''

        if len(fdtup)>1:
            fd0i, fd0o = fdtup
        else:
            fd0i, = fdtup
            fd0o, = fdtup

        fdsock = False      # socket or fileio?
        if hasattr(fd0i, 'recv'):
            fdsock = True

        try:
            while True:
                #if self._pause:
                #    continue

                try:
                    x,y,z = select.select([fd0i ], [], [], .1)
                    if fd0i in x:
                        # FIXME: make this aware of VLEN/FLEN and the proper length
                        if fdsock:
                            data = fd0i.recv(self.max_packet_size)
                        else:
                            data = fd0i.read(self.max_packet_size)

                        if not len(data):       # terminated socket
                            break

                        buf += data
                        pktlen, vlen = self.getPktLEN()
                        if vlen:
                            pktlen = ord(buf[0])

                        #FIXME: probably want to take in a length struct here and then only send when we have that many bytes...
                        data = buf[:pktlen]
                        if use_rawinput:
                            data = eval('"%s"'%data)

                        if len(buf) >= pktlen:
                            self.RFxmit(data)

                except ChipconUsbTimeoutException:
                    pass

                try:
                    data, time = self.RFrecv(1)

                    if printable:
                        data = "\n"+str(time)+": "+repr(data)
                    else:
                        data = struct.pack("<fH", time, len(data)) + data

                    if fdsock:
                        fd0o.sendall(data)
                    else:
                        fd0o.write(data)

                except ChipconUsbTimeoutException:
                    pass

                #special handling of specan dumps...  somewhat set in solid jello
                try:
                    data, time = self.recv(APP_SPECAN, 1, 1)
                    data = struct.pack("<fH", time, len(data)) + data
                    if fdsock:
                        fd0o.sendall(data)
                    else:
                        fd0o.write(data)

                except ChipconUsbTimeoutException:
                    #print "this is a valid exception, run along... %x"% APP_SPECAN
                    pass

        except KeyboardInterrupt:
            self.setModeIDLE()

class InverseCat(RfCat):
    def setMdmSyncWord(self, word, radiocfg=None):
        FHSSNIC.setMdmSyncWord(self, word ^ 0xffff, radiocfg)

    def RFrecv(self, timeout=1000):
        global data
        data,timestamp = RfCat.RFrecv(self, timeout)
        return rfbits.invertBits(data),timestamp

    def RFxmit(self, data):
        return RfCat.RFxmit(self, rfbits.invertBits(data) )

def cleanupInteractiveAtExit():
    try:
        if d.getDebugCodes():
           d.setModeIDLE()
        pass
    except:
        pass

def interactive(idx=0, DongleClass=RfCat, intro='', safemode=False):
    global d
    import rflib.chipcon_nic as rfnic
    import atexit

    d = DongleClass(idx=idx, debug=safemode, safemode=safemode)
    if not safemode:
        d.setModeRX()       # this puts the dongle into receive mode

    atexit.register(cleanupInteractiveAtExit)

    print(intro)
    gbls = globals()
    lcls = locals()
    interact(lcls, gbls)

def interact(lcls, gbls):
    shellexception = None

    try:
        import IPython
        if IPython.core.getipython.get_ipython() is None:
            ipsh = IPython.terminal.embed.InteractiveShellEmbed.instance()
        else:
            ipsh = IPython.terminal.embed.InteractiveShellEmbed()
       
        ipsh.user_global_ns.update(gbls)    
        ipsh.user_global_ns.update(lcls)
        ipsh.autocall = 2       # don't require parenthesis around *everything*.  be smart!
        ipsh.mainloop()
    except ImportError as e:
        shellexception = e

    if shellexception:
        try:
            import IPython.Shell
            ipsh = IPython.Shell.IPShell(argv=[''], user_ns=lcls, user_global_ns=gbls)
            ipsh.mainloop()

        except ImportError as e:
            shellexception = e

    if shellexception:
        try:
            import IPython
            if IPython.core.getipython.get_ipython() is None:
                ipsh = IPython.terminal.embed.InteractiveShellEmbed.instance()
            else:
                ipsh = IPython.terminal.embed.InteractiveShellEmbed()
            ipsh.user_global_ns.update(gbls)
            ipsh.user_global_ns.update(lcls)
            ipsh.autocall = 2       # don't require parenthesis around *everything*.  be smart!

            ipsh.mainloop()
        except ImportError as e:
            shellexception = e

    if shellexception:
        print("falling back to straight Python... (%r)" % shellexception)
        shell = code.InteractiveConsole(gbls)
        shell.interact()


if __name__ == "__main__":
    idx = 0
    if len(sys.argv) > 1:
        idx = int(sys.argv.pop())

    interactive(idx)

let me know if it fixes your problem

@atlas0fd00m
Copy link
Owner

thank you, @Spiro01 . would you like to make a pull request for that change and get your name in the logs of RfCat commits?

@

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

No branches or pull requests

3 participants