def convert_dict_to_wbxml(indict, default_page_num=None):
	wb = wbxmldocument()
	wb.encoding = "utf-8"
	wb.version = "1.3"
	wb.schema = "activesync"
	assert len(indict) == 1 # must be only one root element
	#print "Root",indict.keys()[0]
	if default_page_num != None:
		root = wbxmlelement(indict.keys()[0], page_num=default_page_num)
	else:
		root = wbxmlelement(indict.keys()[0])
	wb.addchild(root)
	convert_array_to_children(root, indict.values()[0])
	return wb
def convert_dict_to_wbxml(indict, default_page_num=None):
	wb = wbxmldocument()
	wb.encoding = "utf-8"
	wb.version = "1.3"
	wb.schema = "activesync"
	assert len(indict) == 1 # must be only one root element
	#print "Root",indict.keys()[0]
	if default_page_num != None:
		root = wbxmlelement(indict.keys()[0], page_num=default_page_num)
	else:
		root = wbxmlelement(indict.keys()[0])
	wb.addchild(root)
	convert_array_to_children(root, indict.values()[0])
	return wb
def convert_array_to_children(in_elem, in_val):
	if isinstance(in_val, list):
		for v in in_val:
			if len(v) > 2:
				add_elem = wbxmlelement(v[0], page_num=v[2])
			else:
				add_elem = wbxmlelement(v[0], page_num=in_elem.page_num)
			in_elem.addchild(add_elem)
			convert_array_to_children(add_elem, v[1])
	elif isinstance(in_val, dict):
		print "FOUND OPAQUE THING",in_val
		in_elem.addchild(wbxmlstring(struct.pack(in_val["fmt"],in_val["val"]), opaque=True))
		print "OPAQUE PRODUCED",in_elem
	elif in_val != None:
		in_elem.addchild(wbxmlstring(in_val))
def convert_array_to_children(in_elem, in_val):
	if isinstance(in_val, list):
		for v in in_val:
			if len(v) > 2:
				add_elem = wbxmlelement(v[0], page_num=v[2])
			else:
				add_elem = wbxmlelement(v[0], page_num=in_elem.page_num)
			in_elem.addchild(add_elem)
			convert_array_to_children(add_elem, v[1])
	elif isinstance(in_val, dict):
		print "FOUND OPAQUE THING",in_val
		in_elem.addchild(wbxmlstring(struct.pack(in_val["fmt"],in_val["val"]), opaque=True))
		print "OPAQUE PRODUCED",in_elem
	elif in_val != None:
		in_elem.addchild(wbxmlstring(in_val))