ettoreleandrotognoli / python-ami

Python AMI Client
BSD 3-Clause "New" or "Revised" License
107 stars 66 forks source link

Compatibility issue with Python3.7 and re._pattern_type #37

Closed peak-load closed 4 years ago

peak-load commented 5 years ago

Error:

./event.py 
Traceback (most recent call last):
  File "./event.py", line 18, in <module>
    event_listener, white_list=['Registry','PeerStatus']
  File "/usr/local/lib/python3.7/site-packages/asterisk/ami/client.py", line 241, in add_event_listener
    event_listener = EventListener(on_event=on_event, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/asterisk/ami/event.py", line 89, in __init__
    self.white_list = [white_list] if isinstance(white_list, (basestring, re._pattern_type)) else white_list
AttributeError: module 're' has no attribute '_pattern_type'

Source code:

#!/usr/local/bin/python3

import os
import time
from settings import login, connection

from asterisk.ami import AMIClient

def event_listener(event,**kwargs):
    print(event)

client = AMIClient(**connection)
future = client.login(**login)
if future.response.is_error():
    raise Exception(str(future.response))

client.add_event_listener(
    event_listener, white_list=['Registry','PeerStatus']
)

try:
    while True:
        time.sleep(10)
except (KeyboardInterrupt, SystemExit):
    client.logoff()
/usr/local/bin/python3 -V
Python 3.7.3
/usr/local/bin/python3 /usr/bin/pip show asterisk-ami
Name: asterisk-ami
Version: 0.1.5
Summary: Python AMI Client
Home-page: https://github.com/ettoreleandrotognoli/python-ami/
Author: Éttore Leandro Tognoli
Author-email: ettore.leandro.tognoli@gmail.com
License: BSD
Location: /usr/local/lib/python3.7/site-packages
Requires: 
Required-by: 

Looks like _pattern_type was removed in 3.7. here's what it is in 3.6 https://github.com/python/cpython/blob/3.6/Lib/re.py#L283

mauriciomagalhaes commented 5 years ago

Change all "re._pattern_type" to "re.Pattern" in file asterisk/ami/event.py

johndiego commented 4 years ago

This is same problem!

File "/usr/local/lib/python3.7/site-packages/asterisk/ami/client.py", line 241, in add_event_listener
    event_listener = EventListener(on_event=on_event, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/asterisk/ami/event.py", line 89, in __init__
    self.white_list = [white_list] if isinstance(white_list, (basestring, re._pattern_type)) else white_list
AttributeError: module 're' has no attribute '_pattern_type'
ettoreleandrotognoli commented 4 years ago

39