(xml_string, key_list, start_node=None, uniq=None)
return (seq, status, d)
Gets all key/value pairs from XML
Gets all key/value pairs from XML
Gets all key / value pairs from XML
def parse_reply_orig(xml_string, key_list, start_node=None, uniq=None):
	"""Gets all key/value pairs from XML"""
	ROOT_NODES = ['seq', 'status', 'contents']
	if not xml_string:
		return (0, 'Not a valid string', {})

	# Parse xml
	try:
		xml = ET.fromstring(xml_string)
	except ET.ExpatError:
		return (0, 'Cannot parse XML', {})

	# Make sure it looks like what we expect it to be
	if [t.tag for t in xml.getchildren()] != ROOT_NODES:
		return (0, 'XML not formatted correctly', {})

	# Get seq and status
	seq = xml.findtext('seq')
	status = xml.findtext('status')

	# If start node was given, append it to contents node
	if start_node:
		start_node = 'contents/%s' % start_node
	else:
		start_node = 'contents'
	if not xml.find(start_node):
		return (seq, 'start_node not found', {})

	# If a unique value was given, make sure it is a valid tag
	if uniq:
		found = False
		for x in xml.find(start_node).getiterator():
			if x.tag == uniq:
				found = True
				break
		if not found:
			return (seq, 'uniq not a valid tag', {})

	# Parse keys from contents
	d = {}
	for x in xml.find(start_node).getiterator():
		if uniq:
			# If tag is a unique field, start a new dict
			if x.tag == uniq:
				d[x.text] = {}
				k = x.text

			# Store key/value pair if tag is in key list
			if x.tag in key_list:
				# If the tag has the word time and the value is a UNIX timestamp, convert it
				if 'time' in x.tag and re_unix_timestamp.search(x.text):
					d[k][x.tag] = convert_date(x.text)
				else:
					d[k][x.tag] = x.text

		else:
			# Store key/value pair if tag is in key list
			if x.tag in key_list:
				# If the tag has the word time and the value is a UNIX timestamp, convert it
				if 'time' in x.tag and re_unix_timestamp.search(x.text):
					d[x.tag] = convert_date(x.text)
				else:
					d[x.tag] = x.text
	return (seq, status, d)
def parse_reply_orig ( xml_string , key_list , start_node = None , uniq = None ) : ROOT_NODES = [ 'seq' , 'status' , 'contents' ] if not xml_string : return ( 0 , 'Not a valid string' , { } ) # Parse xml try : xml = ET . fromstring ( xml_string ) except ET . ExpatError : return ( 0 , 'Cannot parse XML' , { } ) # Make sure it looks like what we expect it to be if [ t . tag for t in xml . getchildren ( ) ] != ROOT_NODES : return ( 0 , 'XML not formatted correctly' , { } ) # Get seq and status seq = xml . findtext ( 'seq' ) status = xml . findtext ( 'status' ) # If start node was given, append it to contents node if start_node : start_node = 'contents/%s' % start_node else : start_node = 'contents' if not xml . find ( start_node ) : return ( seq , 'start_node not found' , { } ) # If a unique value was given, make sure it is a valid tag if uniq : found = False for x in xml . find ( start_node ) . getiterator ( ) : if x . tag == uniq : found = True break if not found : return ( seq , 'uniq not a valid tag' , { } ) # Parse keys from contents d = { } for x in xml . find ( start_node ) . getiterator ( ) : if uniq : # If tag is a unique field, start a new dict if x . tag == uniq : d [ x . text ] = { } k = x . text # Store key/value pair if tag is in key list if x . tag in key_list : # If the tag has the word time and the value is a UNIX timestamp, convert it if 'time' in x . tag and re_unix_timestamp . search ( x . text ) : d [ k ] [ x . tag ] = convert_date ( x . text ) else : d [ k ] [ x . tag ] = x . text else : # Store key/value pair if tag is in key list if x . tag in key_list : # If the tag has the word time and the value is a UNIX timestamp, convert it if 'time' in x . tag and re_unix_timestamp . search ( x . text ) : d [ x . tag ] = convert_date ( x . text ) else : d [ x . tag ] = x . text return ( seq , status , d )