def get_response_properties(response, default_key=None): """ Return a dictionary with available properties from response. Keyword arguments: response -- Response from debugger engine. default_key -- Index key to use when property has no name. """ properties = H.new_dictionary() # Walk through elements in response for child in response: # Read property elements if child.tag == dbgp.ELEMENT_PROPERTY or child.tag == dbgp.ELEMENT_PATH_PROPERTY: # Get property attribute values property_name_short = child.get(dbgp.PROPERTY_NAME) property_name = child.get(dbgp.PROPERTY_FULLNAME, property_name_short) property_type = child.get(dbgp.PROPERTY_TYPE) property_children = child.get(dbgp.PROPERTY_CHILDREN) property_numchildren = child.get(dbgp.PROPERTY_NUMCHILDREN) property_classname = child.get(dbgp.PROPERTY_CLASSNAME) property_encoding = child.get(dbgp.PROPERTY_ENCODING) property_value = None # Set property value if child.text: property_value = child.text # Try to decode property value when encoded with base64 if property_encoding is not None and property_encoding == 'base64': try: property_value = H.base64_decode(child.text) except: pass if property_name is not None and len(property_name) > 0: property_key = property_name # Ignore following properties if property_name == "::": continue # Avoid nasty static functions/variables from turning in an infinitive loop if property_name.count("::") > 1: continue # Filter password values if get_value(S.KEY_HIDE_PASSWORD, True) and property_name.lower().find('password') != -1 and property_value is not None: property_value = '******' else: property_key = default_key # Store property if property_key: properties[property_key] = { 'name': property_name, 'type': property_type, 'value': property_value, 'numchildren': property_numchildren, 'children' : None } # Get values for children if property_children: properties[property_key]['children'] = get_response_properties(child, default_key) # Set classname, if available, as type for object if property_classname and property_type == 'object': properties[property_key]['type'] = property_classname # Handle error elements elif child.tag == dbgp.ELEMENT_ERROR or child.tag == dbgp.ELEMENT_PATH_ERROR: message = 'error' for step_child in child: if step_child.tag == dbgp.ELEMENT_MESSAGE or step_child.tag == dbgp.ELEMENT_PATH_MESSAGE and step_child.text: message = step_child.text break if default_key: properties[default_key] = { 'name': None, 'type': message, 'value': None, 'numchildren': None, 'children': None } return properties