# Path: airy/core/conf.py
# class Settings(object):
#     def __init__(self, **entries):
#     def __getattribute__(self, name):
# def _ensure_defaults(dsettings, options, project_root, config_filename):
# def _preconfigure(project_root, config_filename='settings.py', argv=[]):
# 
# Path: airy/core/exceptions.py
# class Http404(Exception):
#     "Requested page does not exist"
#     pass
# 
# Path: airy/core/files/uploadedfile.py
# class SimpleUploadedFile(InMemoryUploadedFile):
#     """
#     A simple representation of a file, which just has content, size, and a name.
#     """
#     def __init__(self, name, content, content_type='text/plain'):
#         content = content or ''
#         super(SimpleUploadedFile, self).__init__(StringIO(content), None, name,
#                                                  content_type, len(content), None)
# 
#     def from_dict(cls, file_dict):
#         """
#         Creates a SimpleUploadedFile object from
#         a dictionary object with the following keys:
#            - filename
#            - content-type
#            - content
#         """
#         return cls(file_dict['filename'],
#                    file_dict['content'],
#                    file_dict.get('content-type', 'text/plain'))
#     from_dict = classmethod(from_dict)
# 
# Path: airy/core/reportbug.py
# def report_on_fail(function):
# 
#     def wrapped(ins, *args, **kwargs):
#         try:
#             return function(ins, *args, **kwargs)
#         except:
#             if settings.debug:
#                 raise
#             ReportBug(ins, args=args, kwargs=kwargs)
# 
#     wrapped.__doc__ = function.__doc__
#     wrapped.__name__ = function.__name__
# 
#     return wrapped
# 
# Path: airy/utils/encoding.py
# def smart_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
#     """
#     Returns a unicode object representing 's'. Treats bytestrings using the
#     'encoding' codec.
# 
#     If strings_only is True, don't convert (some) non-string-like objects.
#     """
#     if isinstance(s, Promise):
#         # The input is the result of a gettext_lazy() call.
#         return s
#     return force_unicode(s, encoding, strings_only, errors)
# 
# Path: airy/utils/functional.py
# def curry(_curried_func, *args, **kwargs):
#     def _curried(*moreargs, **morekwargs):
#         return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
#     return _curried


import calendar
import logging
import base64
from airy.core.conf import settings
from airy.core.exceptions import Http404
from airy.core.files.uploadedfile import SimpleUploadedFile
from airy.core.reportbug import report_on_fail
from airy.utils.encoding import smart_unicode
from airy.utils.functional import curry
from tornado.web import *
from tornado.escape import *
from tornadio2 import TornadioRouter, SocketConnection, event
from urlparse import urlparse, parse_qs
from urllib2 import unquote

    def post(self, *args, **kwargs):
        args = self.get_flat_arguments()
        args['files'] = {}
        for file in self.request.files:
            if len(self.request.files[file]) > 1:
                for content in self.request.files[file]:
                    args['files'][file] = {
                        'content': '%s;%s,%s' % (content['content_type'], 'base64', base64.b64encode(content['body'])),
                        'name': smart_unicode(content['filename'])
                    }
            else:
                content = self.request.files[file][0]
                args['files'][file] = {
                    'content': '%s;%s,%s' % (content['content_type'], 'base64', base64.b64encode(content['body'])),
                    'name': smart_unicode(content['filename'])
                }
        self.write(json_encode(args))
        self.finish()


def utf8(value):
    """Converts a string argument to a byte string.

    If the argument is already a byte string or None, it is returned unchanged.
    Otherwise it must be a unicode string and is encoded as utf8.
    """
    if isinstance(value, _UTF8_TYPES):
        return value
    assert isinstance(value, unicode)

# Path: airy/core/conf.py
# class Settings(object):
#     def __init__(self, **entries):
#     def __getattribute__(self, name):
# def _ensure_defaults(dsettings, options, project_root, config_filename):
# def _preconfigure(project_root, config_filename='settings.py', argv=[]):
# 
# Path: airy/core/exceptions.py
# class Http404(Exception):
#     "Requested page does not exist"
#     pass
# 
# Path: airy/core/files/uploadedfile.py
# class SimpleUploadedFile(InMemoryUploadedFile):
#     """
#     A simple representation of a file, which just has content, size, and a name.
#     """
#     def __init__(self, name, content, content_type='text/plain'):
#         content = content or ''
#         super(SimpleUploadedFile, self).__init__(StringIO(content), None, name,
#                                                  content_type, len(content), None)
# 
#     def from_dict(cls, file_dict):
#         """
#         Creates a SimpleUploadedFile object from
#         a dictionary object with the following keys:
#            - filename
#            - content-type
#            - content
#         """
#         return cls(file_dict['filename'],
#                    file_dict['content'],
#                    file_dict.get('content-type', 'text/plain'))
#     from_dict = classmethod(from_dict)
# 
# Path: airy/core/reportbug.py
# def report_on_fail(function):
# 
#     def wrapped(ins, *args, **kwargs):
#         try:
#             return function(ins, *args, **kwargs)
#         except:
#             if settings.debug:
#                 raise
#             ReportBug(ins, args=args, kwargs=kwargs)
# 
#     wrapped.__doc__ = function.__doc__
#     wrapped.__name__ = function.__name__
# 
#     return wrapped
# 
# Path: airy/utils/encoding.py
# def smart_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
#     """
#     Returns a unicode object representing 's'. Treats bytestrings using the
#     'encoding' codec.
# 
#     If strings_only is True, don't convert (some) non-string-like objects.
#     """
#     if isinstance(s, Promise):
#         # The input is the result of a gettext_lazy() call.
#         return s
#     return force_unicode(s, encoding, strings_only, errors)
# 
# Path: airy/utils/functional.py
# def curry(_curried_func, *args, **kwargs):
#     def _curried(*moreargs, **morekwargs):
#         return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
#     return _curried


# Path: airy/core/web.py
import calendar
import logging
import base64
from airy.core.conf import settings
from airy.core.exceptions import Http404
from airy.core.files.uploadedfile import SimpleUploadedFile
from airy.core.reportbug import report_on_fail
from airy.utils.encoding import smart_unicode
from airy.utils.functional import curry
from tornado.web import *
from tornado.escape import *
from tornadio2 import TornadioRouter, SocketConnection, event
from urlparse import urlparse, parse_qs
from urllib2 import unquote


    def post(self, *args, **kwargs):
        args = self.get_flat_arguments()
        args['files'] = {}
        for file in self.request.files:
            if len(self.request.files[file]) > 1:
                for content in self.request.files[file]:
                    args['files'][file] = {
                        'content': '%s;%s,%s' % (content['content_type'], 'base64', base64.b64encode(content['body'])),
                        'name': smart_unicode(content['filename'])
                    }
            else:
                content = self.request.files[file][0]
                args['files'][file] = {
                    'content': '%s;%s,%s' % (content['content_type'], 'base64', base64.b64encode(content['body'])),
                    'name': smart_unicode(content['filename'])
                }
        self.write(json_encode(args))
        self.finish()


def utf8(value):
    """Converts a string argument to a byte string.

    If the argument is already a byte string or None, it is returned unchanged.
    Otherwise it must be a unicode string and is encoded as utf8.
    """
    if isinstance(value, _UTF8_TYPES):
        return value
    assert isinstance(value, unicode)

    return smart_unicode(value, encoding="utf-8", errors="ignore")