def handle_request(self, request): request_data = request.get_post_data_as_dictionary() request_data.update(request.get_query_string_as_dictionary()) requesturi = request.get_path() nodeuri = requesturi[len(self.path):] if '%' in nodeuri: nodeuri = urllib.unquote(nodeuri) response = Response(request) if request_data: node = self.nodespace.as_node(nodeuri) generator = IBroadways(node) if request_data.has_key('dumps'): return response.send(generator.dumps()) elif request_data.has_key('loads'): snippet = urllib.unquote(request_data['snippet'][0]) generator.loads(snippet) document = HTMLgen.SimpleDocument() dumpform = HTMLgen.Form(requesturi) dumpform.submit.name = 'dumps' dumpform.submit.value = 'Get configuration' loadform = HTMLgen.Form(requesturi) loadinput = HTMLgen.Textarea('', name='snippet') loadform.append(loadinput) loadform.submit.name = 'loads' loadform.submit.value = 'Load configuration' document.append(dumpform) document.append(loadform) return response.send(str(document))
<property name='conversion' value='int'/> </config> <node name='value' node_id='515' module='mpx.lib.node.simple_value.SimpleValue' config_builder='' inherant='false' description='Configurable Value'> <config> <property name='__type__' value='point'/> <property name='debug' value='0'/> <property name='value' value='2'/> <property name='conversion' value='int'/> </config> </node> </node> """ virtuals = IConfigurableNode(as_node('/interfaces/virtuals')) vconfig = IBroadways(virtuals) print vconfig.dumps() vconfig.loads(snippet) """ import StringIO datastream = StringIO.StringIO() from mpx.lib.configure._xml_handler import _encode_xml as encode_xml from mpx.lib.configure import parse_xml from mpx.lib.configure import Iterator from mpx.system.system import _load as load_node datastream.write(snippet) datastream.seek(0) xmlroot = parse_xml(datastream) xmlroot <mpx.lib.configure._configuration.Configuration instance at 0x4061ec44>