File: test_app.py

package info (click to toggle)
tornado-pyvows 0.6.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 128 kB
  • sloc: python: 522; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# tornado-pyvows extensions
# https://github.com/rafaelcaricio/tornado-pyvows

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com rafael@caricio.com

import json

import tornado.web
from tornado.web import RequestHandler

class MainPageHandler(RequestHandler):
    def head(self):
        self.set_status(204)

    def get(self):
        self.write("Hello, world")

    def post(self):
        result = {}
        for arg, value in self.request.arguments.iteritems():
            result[arg] = value.pop()

        for field_name, list_of_files in self.request.files.iteritems():
            file_dict = list_of_files.pop()
            result[field_name] = file_dict 

        self.write(json.dumps(result))