clean up core responses

This commit is contained in:
Steve Pulec 2013-02-25 23:48:17 -05:00
commit dc9677e323
5 changed files with 25 additions and 8 deletions

View file

@ -1,12 +1,13 @@
import functools
import re
from httpretty import HTTPretty
from moto.packages.httpretty import HTTPretty
class BaseBackend(object):
def reset(self):
self.__dict__ = {}
self.__init__()
@property
@ -22,7 +23,6 @@ class BaseBackend(object):
def wrapper(*args, **kw):
self.reset()
HTTPretty.reset()
HTTPretty.enable()
for method in HTTPretty.METHODS:

23
moto/core/responses.py Normal file
View file

@ -0,0 +1,23 @@
from urlparse import parse_qs
from moto.core.utils import headers_to_dict, camelcase_to_underscores, method_names_from_class
class BaseResponse(object):
def dispatch(self, uri, body, headers):
if body:
querystring = parse_qs(body)
else:
querystring = headers_to_dict(headers)
self.path = uri.path
self.querystring = querystring
action = querystring['Action'][0]
action = camelcase_to_underscores(action)
method_names = method_names_from_class(self.__class__)
if action in method_names:
method = getattr(self, action)
return method()
raise NotImplementedError("The {} action has not been implemented".format(action))