# Path: djangorpc/datastructures.py
# class RpcMultiValueDict(MultiValueDict):
#     """
#     Just allow pass not list values and get only dict as argument
#     """
# 
#     def __init__(self, key_to_list_mapping={}):
#         for key, value in key_to_list_mapping.items():
#             if not isinstance(value, (list, tuple)):
#                 key_to_list_mapping[key] = [value]
# 
#         super(MultiValueDict, self).__init__(key_to_list_mapping)
# 
# Path: djangorpc/exceptions.py
# class RpcExceptionEvent(BaseRpcException):
#     """
#     This exception is sent to server as Ext.Direct.ExceptionEvent.
#     So we can handle it in client and show pretty message for user.
#     Example::
# 
#         class MainApiClass(object):
# 
#             def func2(self, user):
#                 if not user.is_authenticated():
#                     raise RpcExceptionEvent(u'Permission denied.')
# 
#     And you can catch this with::
# 
#         jQuery.Rpc.on('exception', function(event){
#             alert('ERROR: '+event.message);
#         });
#     """
#     pass
# 
# Path: djangorpc/settings.py
# JS_API_URL_NAME = getattr(settings, 'DJANGORPC_JS_API_URL_NAME', 'jsapi')
# 
# ROUTER_URL_NAME = getattr(settings, 'DJANGORPC_ROUTER_URL_NAME', 'router')
# 
# Path: djangorpc/responses.py
# class RpcHttpResponse(RpcResponse):
#     """
#     This is vrapper for method's reponse, which allow save some modification of HTTP response.
#     For example set COOKIES. This should be flexible and useful for in future.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         super(RpcHttpResponse, self).__init__(*args, **kwargs)
#         self.cookies = SimpleCookie()
# 
#     def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
#                    domain=None, secure=False):
#         """
#         Set cookie.
#         """
#         self.cookies[key] = value
#         if max_age is not None:
#             self.cookies[key]['max-age'] = max_age
#         if expires is not None:
#             self.cookies[key]['expires'] = expires
#         if path is not None:
#             self.cookies[key]['path'] = path
#         if domain is not None:
#             self.cookies[key]['domain'] = domain
#         if secure:
#             self.cookies[key]['secure'] = True


import json
from inspect import getargspec
from django.conf.urls import *
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from djangorpc.datastructures import RpcMultiValueDict
from djangorpc.exceptions import RpcExceptionEvent
from djangorpc.settings import JS_API_URL_NAME, ROUTER_URL_NAME
from djangorpc.responses import RpcHttpResponse
                'method': method,
                'message': unicode(e)
            }


class RpcRouterJSONEncoder(json.JSONEncoder):
    """
    JSON Encoder for RpcRouter
    """

    def __init__(self, url_args, url_kwargs, *args, **kwargs):
        self.url_args = url_args
        self.url_kwargs = url_kwargs
        super(RpcRouterJSONEncoder, self).__init__(*args, **kwargs)

    def _encode_action(self, o):
        output = []

        for method in dir(o):
            if not method.startswith('_'):
                data = dict(name=method)
                f = getattr(o, method)
                if hasattr(f, '_form_handler'):
                    data['formHandler'] = getattr(f, '_form_handler')
                output.append(data)
        return output

    def default(self, obj):
        if isinstance(obj, RpcRouter):
            if obj.url_namespace:

# Path: djangorpc/datastructures.py
# class RpcMultiValueDict(MultiValueDict):
#     """
#     Just allow pass not list values and get only dict as argument
#     """
# 
#     def __init__(self, key_to_list_mapping={}):
#         for key, value in key_to_list_mapping.items():
#             if not isinstance(value, (list, tuple)):
#                 key_to_list_mapping[key] = [value]
# 
#         super(MultiValueDict, self).__init__(key_to_list_mapping)
# 
# Path: djangorpc/exceptions.py
# class RpcExceptionEvent(BaseRpcException):
#     """
#     This exception is sent to server as Ext.Direct.ExceptionEvent.
#     So we can handle it in client and show pretty message for user.
#     Example::
# 
#         class MainApiClass(object):
# 
#             def func2(self, user):
#                 if not user.is_authenticated():
#                     raise RpcExceptionEvent(u'Permission denied.')
# 
#     And you can catch this with::
# 
#         jQuery.Rpc.on('exception', function(event){
#             alert('ERROR: '+event.message);
#         });
#     """
#     pass
# 
# Path: djangorpc/settings.py
# JS_API_URL_NAME = getattr(settings, 'DJANGORPC_JS_API_URL_NAME', 'jsapi')
# 
# ROUTER_URL_NAME = getattr(settings, 'DJANGORPC_ROUTER_URL_NAME', 'router')
# 
# Path: djangorpc/responses.py
# class RpcHttpResponse(RpcResponse):
#     """
#     This is vrapper for method's reponse, which allow save some modification of HTTP response.
#     For example set COOKIES. This should be flexible and useful for in future.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         super(RpcHttpResponse, self).__init__(*args, **kwargs)
#         self.cookies = SimpleCookie()
# 
#     def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
#                    domain=None, secure=False):
#         """
#         Set cookie.
#         """
#         self.cookies[key] = value
#         if max_age is not None:
#             self.cookies[key]['max-age'] = max_age
#         if expires is not None:
#             self.cookies[key]['expires'] = expires
#         if path is not None:
#             self.cookies[key]['path'] = path
#         if domain is not None:
#             self.cookies[key]['domain'] = domain
#         if secure:
#             self.cookies[key]['secure'] = True


# Path: djangorpc/router.py
import json
from inspect import getargspec
from django.conf.urls import *
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from djangorpc.datastructures import RpcMultiValueDict
from djangorpc.exceptions import RpcExceptionEvent
from djangorpc.settings import JS_API_URL_NAME, ROUTER_URL_NAME
from djangorpc.responses import RpcHttpResponse

                'method': method,
                'message': unicode(e)
            }


class RpcRouterJSONEncoder(json.JSONEncoder):
    """
    JSON Encoder for RpcRouter
    """

    def __init__(self, url_args, url_kwargs, *args, **kwargs):
        self.url_args = url_args
        self.url_kwargs = url_kwargs
        super(RpcRouterJSONEncoder, self).__init__(*args, **kwargs)

    def _encode_action(self, o):
        output = []

        for method in dir(o):
            if not method.startswith('_'):
                data = dict(name=method)
                f = getattr(o, method)
                if hasattr(f, '_form_handler'):
                    data['formHandler'] = getattr(f, '_form_handler')
                output.append(data)
        return output

    def default(self, obj):
        if isinstance(obj, RpcRouter):
            if obj.url_namespace:

                url_name = '%s:%s' % (obj.url_namespace, ROUTER_URL_NAME)