Wednesday, March 21, 2012

Port of web2py to Bottle, Flask, Pyramid, Tornado, wsgiref and other frameworks

mdipierro/gluino · GitHub


JSONP with the framework Bottle

# Author: Samat Jain <>
# License: MIT (same as Bottle)

import bottle

from bottle import request, response, route
from bottle import install, uninstall

from json import dumps as json_dumps

class JSONAPIPlugin(object):
    name = 'jsonapi'
    api = 1

    def __init__(self, json_dumps=json_dumps):
        self.json_dumps = json_dumps

    def apply(self, callback, context):
        dumps = self.json_dumps
        if not dumps: return callback
        def wrapper(*a, **ka):
            r = callback(*a, **ka)

            # Attempt to serialize, raises exception on failure
            json_response = dumps(r)

            # Set content type only if serialization succesful
            response.content_type = 'application/json'

            # Wrap in callback function for JSONP
            callback_function = request.GET.get('callback')
            if callback_function:
                json_response = ''.join([callback_function, '(', json_response, ')'])

            return json_response
        return wrapper


def hello():
    r = [{'hello': 'world'}]
    r.append({1: 2})
    return r

if __name__ == '__main__':
    from bottle import run

JSONP with jQuery, MooTools, and Dojo


jquery-jsonp - JSONP for jQuery - Google Project Hosting


Small experimental RPC API using bottle web framework and jQuery

foxbunny/HTTPy-RPC · GitHub



Geat article

Monday, March 19, 2012

Webservice + WSDL in Python with

Quote from Site

(...)Optio's soaplib makes it really straightforward to write SOAP web service views by using a decorator to specify types. Plus it's the only Python library, as of today, which is able to generate WSDL documents for your web service.(...)

import web 
from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers import primitive as soap_types

urls = ("/hello", "HelloService",
        "/hello.wsdl", "HelloService",
render = web.template.Template("$def with (var)\n$:var")

class SoapService(SimpleWSGISoapApp):
    """Class for webservice """

    #__tns__ = ''

    def hello(self,message):
        """ Method for webservice"""
        return "Hello world "+message

class HelloService(SoapService):
    """Class for """
    def start_response(self,status, headers):
        web.ctx.status = status
        for header, value in headers:
            web.header(header, value)

    def GET(self):
        response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response)
        return render("\n".join(response))

    def POST(self):
        response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response)
        return render("\n".join(response))

app=web.application(urls, globals())

if __name__ == "__main__":