EvoluxBR / greenswitch

Battle proven FreeSWITCH Event Socket Protocol client implementation with Gevent
Other
126 stars 50 forks source link

Implementation of Mapping protocol for ESLEvent #44

Closed Otoru closed 5 years ago

Otoru commented 5 years ago

The implementation of the Mapping protocol for ESLEvent may seem like a sugar code, but it can make it easier to handle events when working with a handler.

The implemented methods serve only as interface for accessing self.headers, so this change does not imply any backward compatibility.

Example of use:

>>> import greenswitch
>>> fs = greenswitch.InboundESL(host='127.0.0.1', port=8021, password='ClueCon')
>>> fs.connect()
>>> r = fs.send('api list_users')
>>> print r.data
>>> r.headers
{'Content-Type': 'api/response', 'Content-Length': '103'}
>>> r['Content-Type']
'api/response'
>>> r.data
'userid|context|domain|group|contact|callgroup|effective_caller_id_name|effective_caller_id_number\n\n+OK\n'

I believe that this adaptation makes the code more pytonic, because if the object behaves like a mapping and is used as a mapping, then it must be a mapping.