21 from ec2
import lookup
22 from ec2.base.action
import Action, CLMException
23 from ec2.error
import InvalidAction, MethodNotAllowed, InvalidArgument, InvalidURI, EC2Exception
24 from ec2.settings
import BUCKETS_PATH
25 from ec2.helpers.auth
import authenticate
26 from ec2.helpers.utils
import get_path
43 user_name = self.
parameters[
'authorization'].split(
' ')[1].split(
':')[0]
67 if parameters[
'query_string']:
68 qs_dict = urlparse.parse_qs(parameters[
'query_string'], keep_blank_values=
True)
69 for k, v
in qs_dict.iteritems():
70 if len(v) == 1
and not v[0]:
71 raise MethodNotAllowed()
72 parameters[
'query_string'] =
''
74 path = os.path.normpath(parameters[
'path_info'])
75 if path.startswith(
'/'):
77 if path.endswith(
'/'):
80 path_parts = path.split(
'/')
82 if len(path_parts) == 1:
83 if parameters[
'request_method'] ==
'GET' or parameters[
'request_method'] ==
'HEAD':
84 concrete_class_name =
'ListBucket'
86 if parameters[
'request_method'] ==
'PUT':
87 concrete_class_name =
'PutObject'
88 if parameters[
'request_method'] ==
'GET':
89 concrete_class_name =
'GetObject'
91 for concrete_class
in cls.__subclasses__():
92 if concrete_class.__name__ == concrete_class_name:
97 action = super(S3Action, cls).
__new__(concrete_class, parameters)
98 action.concrete_class_name = concrete_class_name
102 def _get_template(self):
103 name =
'%s.xml' % self.concrete_class_name
104 return lookup.get_template(name)
108 context = self._execute()
111 if context[
'body'].__class__
is dict:
113 response = template.render(**context[
'body'])
116 response = context[
'body']
118 result = {
'body': response,
119 'headers': context.get(
'headers')}