Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
New methods to get and set website configurations
Browse files Browse the repository at this point in the history
The following methods are defined:
- get_website_configuration_xml
- get_website_configuration_obj
- set_website_configuration
- set_website_configuration_xml
  • Loading branch information
Nathan Grigg committed Mar 13, 2013
1 parent a7dd0a0 commit a061b51
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions boto/s3/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,8 +1246,20 @@ def configure_website(self, suffix=None, error_key=None,
config = website.WebsiteConfiguration(
suffix, error_key, redirect_all_requests_to,
routing_rules)
body = config.to_xml()
response = self.connection.make_request('PUT', self.name, data=body,
return self.set_website_configuration(config, headers=headers)

def set_website_configuration(self, config, headers=None):
"""
:type config: boto.s3.website.WebsiteConfiguration
:param config: Configuration data
"""
return self.set_website_configuration_xml(config.to_xml(),
headers=headers)


def set_website_configuration_xml(self, xml, headers=None):
"""Upload xml website configuration"""
response = self.connection.make_request('PUT', self.name, data=xml,
query_args='website',
headers=headers)
body = response.read()
Expand Down Expand Up @@ -1277,6 +1289,16 @@ def get_website_configuration(self, headers=None):
"""
return self.get_website_configuration_with_xml(headers)[0]

def get_website_configuration_obj(self, headers=None):
"""Get the website configuration as a
:class:`boto.s3.website.WebsiteConfiguration` object.
"""
config_xml = self.get_website_configuration_xml(headers=headers)
config = website.WebsiteConfiguration()
h = handler.XmlHandler(config, self)
xml.sax.parseString(config_xml, h)
return config

def get_website_configuration_with_xml(self, headers=None):
"""
Returns the current status of website configuration on the bucket as
Expand All @@ -1294,6 +1316,15 @@ def get_website_configuration_with_xml(self, headers=None):
* Key : name of object to serve when an error occurs
2) unparsed XML describing the bucket's website configuration.
"""

body = self.get_website_configuration_xml(headers=headers)
e = boto.jsonresponse.Element()
h = boto.jsonresponse.XmlHandler(e, None)
h.parse(body)
return e, body

def get_website_configuration_xml(self, headers=None):
"""Get raw website configuration xml"""
response = self.connection.make_request('GET', self.name,
query_args='website', headers=headers)
body = response.read()
Expand All @@ -1302,11 +1333,7 @@ def get_website_configuration_with_xml(self, headers=None):
if response.status != 200:
raise self.connection.provider.storage_response_error(
response.status, response.reason, body)

e = boto.jsonresponse.Element()
h = boto.jsonresponse.XmlHandler(e, None)
h.parse(body)
return e, body
return body

def delete_website_configuration(self, headers=None):
"""
Expand Down

0 comments on commit a061b51

Please sign in to comment.