From a3bde4e19f9867f7d297f80b7792a291e69a4f50 Mon Sep 17 00:00:00 2001 From: "Jorge L. Williams" Date: Fri, 15 Apr 2011 05:46:28 -0500 Subject: Initial echo service. --- echo/echo.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ echo/samples/echo.json | 11 ++++++++++ echo/samples/echo.xml | 8 ++++++++ 3 files changed, 73 insertions(+) create mode 100644 echo/echo.py create mode 100644 echo/samples/echo.json create mode 100644 echo/samples/echo.xml (limited to 'echo') diff --git a/echo/echo.py b/echo/echo.py new file mode 100644 index 00000000..c3fba48a --- /dev/null +++ b/echo/echo.py @@ -0,0 +1,54 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from eventlet import wsgi +from lxml import etree +import simplejson as json +import eventlet + +class EchoApp: + def __init__(self, environ, start_response): + self.environ = environ + self.start = start_response + self.method = environ["REQUEST_METHOD"] + self.pathInfo = environ["PATH_INFO"] + self.queryString = environ["QUERY_STRING"] + self.contentType = environ["CONTENT_TYPE"] + self.content = "" + + inReq = environ["wsgi.input"] + for line in inReq: + self.content = self.content + line + + def __iter__(self): + return self.toXML() + + def toJSON(self): + self.start('200 OK', [('Content-Type', 'application/json')]) + yield "{'echo' : {}}" + + def toXML(self): + echo = etree.Element("{http://docs.openstack.org/echo/api/v1.0}echo", + method=self.method, + pathInfo=self.pathInfo, + queryString=self.queryString) + content = etree.Element("{http://docs.openstack.org/echo/api/v1.0}content") + content.set ("type", self.contentType) + content.text = self.content + echo.append (content) + self.start('200 OK', [('Content-Type', 'application/xml')]) + yield etree.tostring (echo, pretty_print=True) + +wsgi.server(eventlet.listen(('', 8090)), EchoApp) diff --git a/echo/samples/echo.json b/echo/samples/echo.json new file mode 100644 index 00000000..61a8847a --- /dev/null +++ b/echo/samples/echo.json @@ -0,0 +1,11 @@ +{ + "echo" : { + "method" : "GET", + "pathInfo" : "/bla/bla", + "queryString" : "hello=true", + "content" : { + "type" : "application/xml", + "value" : "This is some content." + } + } +} diff --git a/echo/samples/echo.xml b/echo/samples/echo.xml new file mode 100644 index 00000000..8cf4b984 --- /dev/null +++ b/echo/samples/echo.xml @@ -0,0 +1,8 @@ + + + + + This is some content. + + -- cgit