Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Libraries

    mimerender 0.5.1

    Download button

    No screenshots available
    Downloads: 411  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Martin Blech | More programs
    MIT/X Consortium Lic... / FREE
    August 29th, 2012, 00:08 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    mimerender description

    Python module for RESTful resource variant rendering using MIME Media-Types

    mimerender is a Python module that allows, with the use of python decorators, to transparently select a render function for an HTTP request handler's result. It uses mimeparse to parse the HTTP Accept header and select the best available representation.

    Currently it only supports (web.py), but other web frameworks can be considered.

    Code example:

    import web
    import json
    from mimerender import mimerender

    render_xml = lambda message: '%s'%message
    render_json = lambda **args: json.dumps(args)
    render_html = lambda message: '%s'%message
    render_txt = lambda message: message

    urls = (
     '/(.*)', 'greet'
    )
    app = web.application(urls, globals())

    class greet:
     @mimerender(
     default = 'html',
     html = render_html,
     xml = render_xml,
     json = render_json,
     txt = render_txt
     )
     def GET(self, name):
     if not name:
     name = 'world'
     return {'message': 'Hello, ' + name + '!'}

    if __name__ == "__main__":
     app.run()


    Then you can do:

    $ curl -H "Accept: application/html" localhost:8080/x
    < html >< body >Hello, x!< /body >< /html >

    $ curl -H "Accept: application/xml" localhost:8080/x
    < message >Hello, x!< /message >

    $ curl -H "Accept: application/json" localhost:8080/x
    {'message':'Hello, x!'}

    $ curl -H "Accept: text/plain" localhost:8080/x
    Hello, x!



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    MIME Media-Types | resource variant | Perl module | RESTful | Perl | resource

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM