def _parse_xml_string_to_dom(self, xml_string): try: parser = ETree.XMLParser(target=ETree.TreeBuilder(), encoding=self.DEFAULT_ENCODING) parser.feed(xml_string) root = parser.close() except XMLParseError as e: raise ResponseParserError( "Unable to parse response (%s), " "invalid XML received. Further retries may succeed:\n%s" % (e, xml_string)) return root
def parse_get_bucket_location(parsed, http_response, **kwargs): # s3.GetBucketLocation cannot be modeled properly. To # account for this we just manually parse the XML document. # The "parsed" passed in only has the ResponseMetadata # filled out. This handler will fill in the LocationConstraint # value. if http_response.raw is None: return response_body = http_response.content parser = ETree.XMLParser(target=ETree.TreeBuilder(), encoding='utf-8') parser.feed(response_body) root = parser.close() region = root.text parsed['LocationConstraint'] = region
def _looks_like_special_case_error(http_response): if http_response.status_code == 200: try: parser = ETree.XMLParser(target=ETree.TreeBuilder(), encoding='utf-8') parser.feed(http_response.content) root = parser.close() except XMLParseError: # In cases of network disruptions, we may end up with a partial # streamed response from S3. We need to treat these cases as # 500 Service Errors and try again. return True if root.tag == 'Error': return True return False
def _initial_body_parse(self, xml_string): if not xml_string: return ETree.Element('') return self._parse_xml_string_to_dom(xml_string)