(host, app_id=None)
Returns the status of the specified app
        or else the current running app.
Returns the status of the specified app
        or else the current running app.
Returns the status of the specified app or else the current running app .
def get_app_status(host, app_id=None):
    """ Returns the status of the specified app
        or else the current running app. """
    # /apps/ will redirect to the active app
    url = (FORMAT_APP_PATH.format(host, app_id) if app_id
           else FORMAT_BASE_URL.format(host) + "/apps/")

    try:
        req = CC_SESSION.get(url)

        if req.status_code == 204:
            return None

        status_el = ET.fromstring(req.text.encode("UTF-8"))
        options = status_el.find(XML_NS_DIAL + "options").attrib

        app_id = _read_xml_element(status_el, XML_NS_DIAL,
                                   "name", "Unknown application")

        state = _read_xml_element(status_el, XML_NS_DIAL,
                                  "state", "unknown")

        service_el = status_el.find(XML_NS_CAST + "servicedata")

        if service_el is not None:
            service_url = _read_xml_element(service_el, XML_NS_CAST,
                                            "connectionSvcURL", None)

            protocols_el = service_el.find(XML_NS_CAST + "protocols")

            if protocols_el is not None:
                protocols = [el.text for el in protocols_el]
            else:
                protocols = []

        else:
            service_url = None
            protocols = []

        activity_el = status_el.find(XML_NS_CAST + "activity-status")

        if activity_el is not None:
            description = _read_xml_element(activity_el, XML_NS_CAST,
                                            "description", app_id)
        else:
            description = app_id

        return AppStatus(app_id, description, state,
                         options, service_url, protocols)

    except (requests.exceptions.RequestException, ET.ParseError):
        return None
def get_app_status ( host , app_id = None ) : # /apps/ will redirect to the active app url = ( FORMAT_APP_PATH . format ( host , app_id ) if app_id else FORMAT_BASE_URL . format ( host ) + "/apps/" ) try : req = CC_SESSION . get ( url ) if req . status_code == 204 : return None status_el = ET . fromstring ( req . text . encode ( "UTF-8" ) ) options = status_el . find ( XML_NS_DIAL + "options" ) . attrib app_id = _read_xml_element ( status_el , XML_NS_DIAL , "name" , "Unknown application" ) state = _read_xml_element ( status_el , XML_NS_DIAL , "state" , "unknown" ) service_el = status_el . find ( XML_NS_CAST + "servicedata" ) if service_el is not None : service_url = _read_xml_element ( service_el , XML_NS_CAST , "connectionSvcURL" , None ) protocols_el = service_el . find ( XML_NS_CAST + "protocols" ) if protocols_el is not None : protocols = [ el . text for el in protocols_el ] else : protocols = [ ] else : service_url = None protocols = [ ] activity_el = status_el . find ( XML_NS_CAST + "activity-status" ) if activity_el is not None : description = _read_xml_element ( activity_el , XML_NS_CAST , "description" , app_id ) else : description = app_id return AppStatus ( app_id , description , state , options , service_url , protocols ) except ( requests . exceptions . RequestException , ET . ParseError ) : return None