[mythtv-commits] Ticket #13619: Python services-api enhancements

MythTV noreply at mythtv.org
Wed May 20 17:39:58 UTC 2020


#13619: Python services-api enhancements
-----------------------------------+--------------------------
     Reporter:  rcrdnalor          |      Owner:  Bill Meek
         Type:  Patch - Feature    |     Status:  new
     Priority:  minor              |  Milestone:  needs_triage
    Component:  Bindings - Python  |    Version:  Master Head
     Severity:  medium             |   Keywords:  services-api
Ticket locked:  0                  |
-----------------------------------+--------------------------
 1) Python's lxml module works best if fed with raw data from a
 'Request.session.get' response.

 A new option provided by this patch allows returning data
 as raw data i.e.: returning the recieved 'response.content'.
 This can be easily handled by the lxml.etree.fromstring()
 method.

 An example how to use this feature:
 {{{
 $ python3
 >>> from MythTV.services_api import send as API
 >>> from lxml import etree
 >>> host = "localhost"
 >>> mythrequest = API.Send(host)
 >>> endpoint = "/Dvr/GetRecordedList"
 >>> restdata = "Descending=True&Count=3"
 >>> opts     = {'rawxml': True}                ### < --- new option
 >>> response = mythrequest.send(endpoint=endpoint, rest=restdata,
 opts=opts)
 >>> eroot = etree.fromstring(response)
 >>> print(etree.tostring(eroot, pretty_print=True, encoding='unicode'))
 }}}

 Verified also with python2.

 Attached a patch adding this additional option.


 2) The mythservices-api requires the 'post' data to be passed as
 dictionary.
 For classes derived from dictionary (dict), it is not mandatory to provide
 an attribute 'keys', but the methods 'keys()', 'values()', 'items()'
 must always be implemented.

 Using the latter methods, allows logging
 of a 'post' operation for those classes derived from 'dict'.

 Otherwise, on get a traceback showing an 'AttributeError' or a 'KeyError'.
 The class 'OrdDict' from the python bindings is such an example.

 Attached a patch that improves logging for 'post' operations.

-- 
Ticket URL: <https://code.mythtv.org/trac/ticket/13619>
MythTV <http://www.mythtv.org>
MythTV Media Center


More information about the mythtv-commits mailing list