# -*- coding: utf-8 -*-

from flask import request, Response
from flask import json
from flask.views import MethodView

class Resource(MethodView):

    vendors = []
    method_decorators = []

    def dispatch_request(self, *args, **kw):
        method = getattr(self, request.method.lower(), None)
        # if the request method is HEAD and we don't have a handler for it
        # retry with GET
        if method is None and request.method == 'HEAD':
            method = getattr(self, 'get', None)

        if method is None:
            raise NotImplementedError(request.method)

        for decorator in self.method_decorators:
            method = decorator(method)

        response = method(*args, **kw)

        if isinstance(response, Response):
            return response

        data, code, headers = self._parse_response(response)
        presenter = next((v for v in self.vendors
            if v.mediatype==request.access_mediatype), None)

        if not presenter:
            return response

        return presenter.as_representation(method, data, code, headers)

    def _parse_response(self, value):
        if not isinstance(value, tuple):
            code = 200
            if value == '':
                code = 204
            return json.dumps(value), code, {}

        try:
            data, code, headers = value
        except ValueError:
            pass

        try:
            data, code = value
            headers = {}
        except ValueError:
            data, code, headers = value, 200, {}

        data = dumps(data)
        return code, data, headers

@@ -1157,24 +1157,56 @@
 ue, tuple):%0A
+            if value == '':%0A    
             
@@ -1214,17 +1214,17 @@
 ode = 20
-0
+4
 %0A       
@@ -1224,38 +1224,28 @@
             
-if value == ''
+else
 :%0A          
@@ -1251,33 +1251,33 @@
        code = 20
-4
+0
 %0A            ret
@@ -1273,22 +1273,27 @@
         
-return
+    value =
  json.du
@@ -1302,16 +1302,41 @@
 s(value)
+%0A            return value
 , code, 
@@ -1427,22 +1427,8 @@
     
-        pass%0A%0A
     
@@ -1428,32 +1428,36 @@
            try:%0A
+    
             data
@@ -1463,32 +1463,36 @@
 a, code = value%0A
+    
             head
@@ -1500,32 +1500,36 @@
 rs = %7B%7D%0A        
+    
 except ValueErro
@@ -1523,32 +1523,36 @@
 ept ValueError:%0A
+    
             data
@@ -1600,16 +1600,21 @@
  data = 
+json.
 dumps(da
@@ -1636,18 +1636,18 @@
 urn 
-code, data
+data, code
 , he

Fix parser error.