# Path: riv/wrappers.py
# class BaseWrapper(object):
# 
#     exclude_create = ['id',]
#     fields = []
# 
#     handler_methods = {
#         'GET': 'read',
#         'POST': 'create',
#         'PUT': 'update',
#         'DELETE': 'delete',
#         'GET_multiple': 'read_multiple',
#         'POST_multiple': 'create_multiple',
#         'PUT_multiple': 'update_multiple',
#         'DELETE_multiple': 'delete_multiple',
#         'GET_list': 'read_multiple',
#         'POST_list': 'create_multiple',
#         'PUT_list': 'update_multiple',
#         'DELETE_list': 'delete_multiple',
#     }
# 
#     def get_handler_for(self, full_req_meth):
#         """
#         Tries to find the handler for the given request method. If no 
#         specific handler for 'object' or 'multiple' is defined it
#         tries to find a common fallback handler for the given
#         request method.
#         """
#         try:
#             view_name = self.handler_methods[full_req_meth]
#         except KeyError:
#             try:
#                 # if req_meth does not contain the '_' this results in the
#                 # same call as above leading to a KeyError.
#                 view_name = self.handler_methods[full_req_meth.split('_')[0]]
#             except KeyError:
#                 raise AttributeError('Invalid request method: %s' % full_req_meth)
# 
#         try:
#             callback = self._get_callable(view_name)
#         except:
#             raise NotImplementedError()
#         return callback
# 
#     def read(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
#         from django.contrib import auth
#         # This is temporary testing!!
#         #user = auth.authenticate(username='cgraf', password='hallo')
#         #auth.login(request, user)
#         #if 'id' in kwargs:
#         #   return client.project(request, projectid=kwargs['id'])
#         #else:
#         #   return client.list_projects(request)
# 
#     # This is the original comment.
#     def create(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def update(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def delete(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def read_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def create_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def update_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def delete_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def _get_callable(self, view):
#         """
#         This is basically a copy of django.core.urlresolvers.get_callable.
#         But this function does not fail on an UnicodeEncodeError. We do.
#         """
#         if not callable(view):
#             try:
#                 view = view.encode('ascii')
#             except UnicodeEncodeError:
#                 raise AttributeError, "View %s is non-ascii." % (view,)
# 
#             mod_name, func_name = self._get_mod_func(view)
#             if func_name == '':
#                 raise AttributeError, "No function found."
# 
#             try:
#                 if mod_name != '':
#                     view = getattr(import_module(mod_name), func_name)
#                 else:
#                     view = getattr(self, func_name)
#                 if not callable(view):
#                     raise AttributeError, "%s.%s is not callable" % (mod_name, func_name)
#             except (ImportError, AttributeError):
#                 raise AttributeError, "Unable to load %s" % view
#         return view
# 
#     def _get_mod_func(self, mod_func):
#         """
#         The get_mod_func function from django.core.urlresolvers converts 'func'
#         to ['func', ''] whereas we want ['', 'func'].
#         """
#         try:
#             dot_pos = mod_func.rindex('.')
#         except ValueError:
#             return '', mod_func
#         return mod_func[:dot_pos], mod_func[dot_pos+1:]
# 
# Path: riv/helpers.py
# def call_view(view):
#     def selffunc(self, *args, **kwargs):
#         return view(*args, **kwargs)
#     return selffunc


from riv.wrappers import BaseWrapper
from riv.helpers import call_view
from polls import views

#class ChoiceWrapper(BaseWrapper):
#   read = call_view(views.choice_detail)
#   read_multiple = call_view(views.choice_index)
#   delete = call_view(views.choice_delete)
#   update = call_view(views.choice_update)

class PollWrapper(BaseWrapper):
    read = call_view(views.poll_detail)
    read_multiple = call_view(views.poll_index)
    delete = call_view(views.poll_delete)
    update = call_view(views.poll_create_or_update)
    create = call_view(views.poll_create_or_update)

    create_multiple = create

class PollBatchWrapper(PollWrapper):
    create_multiple = call_view(views.poll_create_multiple)
    #delete_multiple = call_view(views.delete_all)

class VoteWrapper(BaseWrapper):
    create = call_view(views.vote)
    create_multiple = create


# Path: riv/wrappers.py
# class BaseWrapper(object):
# 
#     exclude_create = ['id',]
#     fields = []
# 
#     handler_methods = {
#         'GET': 'read',
#         'POST': 'create',
#         'PUT': 'update',
#         'DELETE': 'delete',
#         'GET_multiple': 'read_multiple',
#         'POST_multiple': 'create_multiple',
#         'PUT_multiple': 'update_multiple',
#         'DELETE_multiple': 'delete_multiple',
#         'GET_list': 'read_multiple',
#         'POST_list': 'create_multiple',
#         'PUT_list': 'update_multiple',
#         'DELETE_list': 'delete_multiple',
#     }
# 
#     def get_handler_for(self, full_req_meth):
#         """
#         Tries to find the handler for the given request method. If no 
#         specific handler for 'object' or 'multiple' is defined it
#         tries to find a common fallback handler for the given
#         request method.
#         """
#         try:
#             view_name = self.handler_methods[full_req_meth]
#         except KeyError:
#             try:
#                 # if req_meth does not contain the '_' this results in the
#                 # same call as above leading to a KeyError.
#                 view_name = self.handler_methods[full_req_meth.split('_')[0]]
#             except KeyError:
#                 raise AttributeError('Invalid request method: %s' % full_req_meth)
# 
#         try:
#             callback = self._get_callable(view_name)
#         except:
#             raise NotImplementedError()
#         return callback
# 
#     def read(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
#         from django.contrib import auth
#         # This is temporary testing!!
#         #user = auth.authenticate(username='cgraf', password='hallo')
#         #auth.login(request, user)
#         #if 'id' in kwargs:
#         #   return client.project(request, projectid=kwargs['id'])
#         #else:
#         #   return client.list_projects(request)
# 
#     # This is the original comment.
#     def create(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def update(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def delete(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def read_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def create_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def update_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def delete_multiple(self, request, *args, **kwargs):
#         raise Http404('Subclass the BaseWrapper and implement the "%s" method to make this resource available' % sys._getframe().f_code.co_name)
# 
#     def _get_callable(self, view):
#         """
#         This is basically a copy of django.core.urlresolvers.get_callable.
#         But this function does not fail on an UnicodeEncodeError. We do.
#         """
#         if not callable(view):
#             try:
#                 view = view.encode('ascii')
#             except UnicodeEncodeError:
#                 raise AttributeError, "View %s is non-ascii." % (view,)
# 
#             mod_name, func_name = self._get_mod_func(view)
#             if func_name == '':
#                 raise AttributeError, "No function found."
# 
#             try:
#                 if mod_name != '':
#                     view = getattr(import_module(mod_name), func_name)
#                 else:
#                     view = getattr(self, func_name)
#                 if not callable(view):
#                     raise AttributeError, "%s.%s is not callable" % (mod_name, func_name)
#             except (ImportError, AttributeError):
#                 raise AttributeError, "Unable to load %s" % view
#         return view
# 
#     def _get_mod_func(self, mod_func):
#         """
#         The get_mod_func function from django.core.urlresolvers converts 'func'
#         to ['func', ''] whereas we want ['', 'func'].
#         """
#         try:
#             dot_pos = mod_func.rindex('.')
#         except ValueError:
#             return '', mod_func
#         return mod_func[:dot_pos], mod_func[dot_pos+1:]
# 
# Path: riv/helpers.py
# def call_view(view):
#     def selffunc(self, *args, **kwargs):
#         return view(*args, **kwargs)
#     return selffunc


# Path: tests/polls/wrappers.py
from riv.wrappers import BaseWrapper
from riv.helpers import call_view
from polls import views


#class ChoiceWrapper(BaseWrapper):
#   read = call_view(views.choice_detail)
#   read_multiple = call_view(views.choice_index)
#   delete = call_view(views.choice_delete)
#   update = call_view(views.choice_update)

class PollWrapper(BaseWrapper):
    read = call_view(views.poll_detail)
    read_multiple = call_view(views.poll_index)
    delete = call_view(views.poll_delete)
    update = call_view(views.poll_create_or_update)
    create = call_view(views.poll_create_or_update)

    create_multiple = create

class PollBatchWrapper(PollWrapper):
    create_multiple = call_view(views.poll_create_multiple)
    #delete_multiple = call_view(views.delete_all)

class VoteWrapper(BaseWrapper):
    create = call_view(views.vote)
    create_multiple = create


class ResultWrapper(BaseWrapper):