We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CloudFormation ValidateTemplate response is not parsed correctly.
I'm running Python 2.7.5 and boto 2.24.0, and I noticed an issue with the result returned by CloudFormationConnection.validate_template().  It appears the stack capabilities is not properly parsed.

Here's a code snippet that tickles the issue - the CloudFormation template (iam-user.json) is pasted below.

``` Python
import boto
import logging
boto_logger = logging.getLogger('boto')
boto_logger.setLevel(logging.DEBUG)
tpl_file = open('iam-user.json')
cfn_template_body = tpl_file.read()
tpl_file.close()
cfn_conn = boto.connect_cloudformation()
validation_response = cfn_conn.validate_template(template_body=cfn_template_body)
```

When inspecting Capabilities in the response, I see a string with a newline and spaces, rather than a list that includes something like CAPABILITY_IAM:

``` Python
In [11]: validation_response.Capabilities
Out[11]: u'\n    '
```

Here's the full output of the code example:

``` Python
In [2]: import boto

In [3]: import logging

In [4]: boto_logger = logging.getLogger('boto')

In [5]: boto_logger.setLevel(logging.DEBUG)

In [6]: tpl_file = open('iam-user.json')

In [7]: cfn_template_body = tpl_file.read()

In [8]: tpl_file.close()

In [9]: cfn_conn = boto.connect_cloudformation()
DEBUG:boto:Using access key found in environment variable.
DEBUG:boto:Using secret key found in config file.

In [10]: validation_response = cfn_conn.validate_template(template_body=cfn_template_body)
DEBUG:boto:Method: POST
DEBUG:boto:Path: /
DEBUG:boto:Data: 
DEBUG:boto:Headers: {}
DEBUG:boto:Host: cloudformation.us-east-1.amazonaws.com
DEBUG:boto:Port: 443
DEBUG:boto:Params: {'Action': 'ValidateTemplate', 'Version': '2010-05-15', 'TemplateBody': '{\n    "AWSTemplateFormatVersion" : "2010-09-09",\n    "Description" : "Test",\n\n    "Resources" : {\n\n        "IamUser" : {\n            "Type" : "AWS::IAM::User",\n            "Properties" : {\n                "Path" : "/",\n                "Policies" : [{\n                    "PolicyName" : "CfnInit",\n                    "PolicyDocument": {\n                        "Statement":[{\n                            "Effect"   : "Allow",\n                            "Action"   : [ "cloudformation:DescribeStackResource" ],\n                            "Resource" : "*"\n                        }]\n                    }\n                }]\n            }\n        },\n\n        "CfnKeys" : {\n            "Type" : "AWS::IAM::AccessKey",\n            "Properties" : {\n                "UserName" : { "Ref" : "IamUser" }\n            }\n        }\n    },\n\n    "Outputs" : {\n        "User" : {\n            "Description" : "IAM User",\n            "Value" : { "Ref" : "IamUser" }\n        },\n        "AccessKeyId" : {\n            "Description" : "AccessKeyId",\n            "Value" : { "Ref" : "CfnKeys" }\n        }\n    }\n}\n'}
DEBUG:boto:establishing HTTPS connection: host=cloudformation.us-east-1.amazonaws.com, kwargs={'port': 443, 'timeout': 70}
DEBUG:boto:Token: None
DEBUG:boto:CanonicalRequest:
POST
/

host:cloudformation.us-east-1.amazonaws.com
x-amz-date:20140204T211547Z

host;x-amz-date
ed2b6b57e57a95cefe1ed9a0a8a1d6cbb92060ccda448706ce9a7577107045bc
DEBUG:boto:StringToSign:
AWS4-HMAC-SHA256
20140204T211547Z
20140204/us-east-1/cloudformation/aws4_request
f2704f5688594252d7cd4f721c7a7e03d51d41a0c3f33e82a1f58bfba97fcafa
DEBUG:boto:Signature:
ac40d1a913cf3ca67cc2b80bc05e7c1f364eb02e83bb3c2c96ea18241f183564
DEBUG:boto:wrapping ssl socket; CA certificate file=/Users/vrivellino/.devninja.env/lib/python2.7/site-packages/boto/cacerts/cacerts.txt
DEBUG:boto:validating server certificate: hostname=cloudformation.us-east-1.amazonaws.com, certificate hosts=['cloudformation.us-east-1.amazonaws.com']
DEBUG:boto:<ValidateTemplateResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
  <ValidateTemplateResult>
    <Description>Test</Description>
    <CapabilitiesReason>The following resource(s) require capabilities: [AWS::IAM::User, AWS::IAM::AccessKey]</CapabilitiesReason>
    <Capabilities>
      <member>CAPABILITY_IAM</member>
    </Capabilities>
    <Parameters/>
  </ValidateTemplateResult>
  <ResponseMetadata>
    <RequestId>8465355d-8de1-11e3-ab21-addb98855f3a</RequestId>
  </ResponseMetadata>
</ValidateTemplateResponse>

In [11]: validation_response.Capabilities
Out[11]: u'\n    '
```

Here's the CloudFormation template I used:

``` JSON
{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Test",

    "Resources" : {

        "IamUser" : {
            "Type" : "AWS::IAM::User",
            "Properties" : {
                "Path" : "/",
                "Policies" : [{
                    "PolicyName" : "CfnInit",
                    "PolicyDocument": {
                        "Statement":[{
                            "Effect"   : "Allow",
                            "Action"   : [ "cloudformation:DescribeStackResource" ],
                            "Resource" : "*"
                        }]
                    }
                }]
            }
        },

        "CfnKeys" : {
            "Type" : "AWS::IAM::AccessKey",
            "Properties" : {
                "UserName" : { "Ref" : "IamUser" }
            }
        }
    },

    "Outputs" : {
        "User" : {
            "Description" : "IAM User",
            "Value" : { "Ref" : "IamUser" }
        },
        "AccessKeyId" : {
            "Description" : "AccessKeyId",
            "Value" : { "Ref" : "CfnKeys" }
        }
    }
}
```

Just for reference, this is the output when using the AWS cli tools to validate the template:

```
$ aws cloudformation validate-template --template-body file://./iam-user.json
{
    "CapabilitiesReason": "The following resource(s) require capabilities: [AWS::IAM::User, AWS::IAM::AccessKey]",
    "Description": "Test",
    "Parameters": [],
    "Capabilities": [
        "CAPABILITY_IAM"
    ]
}
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `boto/cloudformation/template.py`
Content:
```
1 from boto.resultset import ResultSet
2 
3 class Template(object):
4     def __init__(self, connection=None):
5         self.connection = connection
6         self.description = None
7         self.template_parameters = None
8 
9     def startElement(self, name, attrs, connection):
10         if name == "Parameters":
11             self.template_parameters = ResultSet([('member', TemplateParameter)])
12             return self.template_parameters
13         else:
14             return None
15 
16     def endElement(self, name, value, connection):
17         if name == "Description":
18             self.description = value
19         else:
20             setattr(self, name, value)
21 
22 class TemplateParameter(object):
23     def __init__(self, parent):
24         self.parent = parent
25         self.default_value = None
26         self.description = None
27         self.no_echo = None
28         self.parameter_key = None
29 
30     def startElement(self, name, attrs, connection):
31         return None
32 
33     def endElement(self, name, value, connection):
34         if name == "DefaultValue":
35             self.default_value = value
36         elif name == "Description":
37             self.description = value
38         elif name == "NoEcho":
39             self.no_echo = bool(value)
40         elif name == "ParameterKey":
41             self.parameter_key = value
42         else:
43             setattr(self, name, value)
44
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/boto/cloudformation/template.py b/boto/cloudformation/template.py
--- a/boto/cloudformation/template.py
+++ b/boto/cloudformation/template.py
@@ -1,21 +1,29 @@
 from boto.resultset import ResultSet
+from boto.cloudformation.stack import Capability
 
 class Template(object):
     def __init__(self, connection=None):
         self.connection = connection
         self.description = None
         self.template_parameters = None
+        self.capabilities_reason = None
+        self.capabilities = None
 
     def startElement(self, name, attrs, connection):
         if name == "Parameters":
             self.template_parameters = ResultSet([('member', TemplateParameter)])
             return self.template_parameters
+        elif name == "Capabilities":
+            self.capabilities = ResultSet([('member', Capability)])
+            return self.capabilities
         else:
             return None
 
     def endElement(self, name, value, connection):
         if name == "Description":
             self.description = value
+        elif name == "CapabilitiesReason":
+            self.capabilities_reason = value
         else:
             setattr(self, name, value)

{"golden_diff": "diff --git a/boto/cloudformation/template.py b/boto/cloudformation/template.py\n--- a/boto/cloudformation/template.py\n+++ b/boto/cloudformation/template.py\n@@ -1,21 +1,29 @@\n from boto.resultset import ResultSet\n+from boto.cloudformation.stack import Capability\n \n class Template(object):\n     def __init__(self, connection=None):\n         self.connection = connection\n         self.description = None\n         self.template_parameters = None\n+        self.capabilities_reason = None\n+        self.capabilities = None\n \n     def startElement(self, name, attrs, connection):\n         if name == \"Parameters\":\n             self.template_parameters = ResultSet([('member', TemplateParameter)])\n             return self.template_parameters\n+        elif name == \"Capabilities\":\n+            self.capabilities = ResultSet([('member', Capability)])\n+            return self.capabilities\n         else:\n             return None\n \n     def endElement(self, name, value, connection):\n         if name == \"Description\":\n             self.description = value\n+        elif name == \"CapabilitiesReason\":\n+            self.capabilities_reason = value\n         else:\n             setattr(self, name, value)\n", "issue": "CloudFormation ValidateTemplate response is not parsed correctly.\nI'm running Python 2.7.5 and boto 2.24.0, and I noticed an issue with the result returned by CloudFormationConnection.validate_template().  It appears the stack capabilities is not properly parsed.\n\nHere's a code snippet that tickles the issue - the CloudFormation template (iam-user.json) is pasted below.\n\n``` Python\nimport boto\nimport logging\nboto_logger = logging.getLogger('boto')\nboto_logger.setLevel(logging.DEBUG)\ntpl_file = open('iam-user.json')\ncfn_template_body = tpl_file.read()\ntpl_file.close()\ncfn_conn = boto.connect_cloudformation()\nvalidation_response = cfn_conn.validate_template(template_body=cfn_template_body)\n```\n\nWhen inspecting Capabilities in the response, I see a string with a newline and spaces, rather than a list that includes something like CAPABILITY_IAM:\n\n``` Python\nIn [11]: validation_response.Capabilities\nOut[11]: u'\\n    '\n```\n\nHere's the full output of the code example:\n\n``` Python\nIn [2]: import boto\n\nIn [3]: import logging\n\nIn [4]: boto_logger = logging.getLogger('boto')\n\nIn [5]: boto_logger.setLevel(logging.DEBUG)\n\nIn [6]: tpl_file = open('iam-user.json')\n\nIn [7]: cfn_template_body = tpl_file.read()\n\nIn [8]: tpl_file.close()\n\nIn [9]: cfn_conn = boto.connect_cloudformation()\nDEBUG:boto:Using access key found in environment variable.\nDEBUG:boto:Using secret key found in config file.\n\nIn [10]: validation_response = cfn_conn.validate_template(template_body=cfn_template_body)\nDEBUG:boto:Method: POST\nDEBUG:boto:Path: /\nDEBUG:boto:Data: \nDEBUG:boto:Headers: {}\nDEBUG:boto:Host: cloudformation.us-east-1.amazonaws.com\nDEBUG:boto:Port: 443\nDEBUG:boto:Params: {'Action': 'ValidateTemplate', 'Version': '2010-05-15', 'TemplateBody': '{\\n    \"AWSTemplateFormatVersion\" : \"2010-09-09\",\\n    \"Description\" : \"Test\",\\n\\n    \"Resources\" : {\\n\\n        \"IamUser\" : {\\n            \"Type\" : \"AWS::IAM::User\",\\n            \"Properties\" : {\\n                \"Path\" : \"/\",\\n                \"Policies\" : [{\\n                    \"PolicyName\" : \"CfnInit\",\\n                    \"PolicyDocument\": {\\n                        \"Statement\":[{\\n                            \"Effect\"   : \"Allow\",\\n                            \"Action\"   : [ \"cloudformation:DescribeStackResource\" ],\\n                            \"Resource\" : \"*\"\\n                        }]\\n                    }\\n                }]\\n            }\\n        },\\n\\n        \"CfnKeys\" : {\\n            \"Type\" : \"AWS::IAM::AccessKey\",\\n            \"Properties\" : {\\n                \"UserName\" : { \"Ref\" : \"IamUser\" }\\n            }\\n        }\\n    },\\n\\n    \"Outputs\" : {\\n        \"User\" : {\\n            \"Description\" : \"IAM User\",\\n            \"Value\" : { \"Ref\" : \"IamUser\" }\\n        },\\n        \"AccessKeyId\" : {\\n            \"Description\" : \"AccessKeyId\",\\n            \"Value\" : { \"Ref\" : \"CfnKeys\" }\\n        }\\n    }\\n}\\n'}\nDEBUG:boto:establishing HTTPS connection: host=cloudformation.us-east-1.amazonaws.com, kwargs={'port': 443, 'timeout': 70}\nDEBUG:boto:Token: None\nDEBUG:boto:CanonicalRequest:\nPOST\n/\n\nhost:cloudformation.us-east-1.amazonaws.com\nx-amz-date:20140204T211547Z\n\nhost;x-amz-date\ned2b6b57e57a95cefe1ed9a0a8a1d6cbb92060ccda448706ce9a7577107045bc\nDEBUG:boto:StringToSign:\nAWS4-HMAC-SHA256\n20140204T211547Z\n20140204/us-east-1/cloudformation/aws4_request\nf2704f5688594252d7cd4f721c7a7e03d51d41a0c3f33e82a1f58bfba97fcafa\nDEBUG:boto:Signature:\nac40d1a913cf3ca67cc2b80bc05e7c1f364eb02e83bb3c2c96ea18241f183564\nDEBUG:boto:wrapping ssl socket; CA certificate file=/Users/vrivellino/.devninja.env/lib/python2.7/site-packages/boto/cacerts/cacerts.txt\nDEBUG:boto:validating server certificate: hostname=cloudformation.us-east-1.amazonaws.com, certificate hosts=['cloudformation.us-east-1.amazonaws.com']\nDEBUG:boto:<ValidateTemplateResponse xmlns=\"http://cloudformation.amazonaws.com/doc/2010-05-15/\">\n  <ValidateTemplateResult>\n    <Description>Test</Description>\n    <CapabilitiesReason>The following resource(s) require capabilities: [AWS::IAM::User, AWS::IAM::AccessKey]</CapabilitiesReason>\n    <Capabilities>\n      <member>CAPABILITY_IAM</member>\n    </Capabilities>\n    <Parameters/>\n  </ValidateTemplateResult>\n  <ResponseMetadata>\n    <RequestId>8465355d-8de1-11e3-ab21-addb98855f3a</RequestId>\n  </ResponseMetadata>\n</ValidateTemplateResponse>\n\nIn [11]: validation_response.Capabilities\nOut[11]: u'\\n    '\n```\n\nHere's the CloudFormation template I used:\n\n``` JSON\n{\n    \"AWSTemplateFormatVersion\" : \"2010-09-09\",\n    \"Description\" : \"Test\",\n\n    \"Resources\" : {\n\n        \"IamUser\" : {\n            \"Type\" : \"AWS::IAM::User\",\n            \"Properties\" : {\n                \"Path\" : \"/\",\n                \"Policies\" : [{\n                    \"PolicyName\" : \"CfnInit\",\n                    \"PolicyDocument\": {\n                        \"Statement\":[{\n                            \"Effect\"   : \"Allow\",\n                            \"Action\"   : [ \"cloudformation:DescribeStackResource\" ],\n                            \"Resource\" : \"*\"\n                        }]\n                    }\n                }]\n            }\n        },\n\n        \"CfnKeys\" : {\n            \"Type\" : \"AWS::IAM::AccessKey\",\n            \"Properties\" : {\n                \"UserName\" : { \"Ref\" : \"IamUser\" }\n            }\n        }\n    },\n\n    \"Outputs\" : {\n        \"User\" : {\n            \"Description\" : \"IAM User\",\n            \"Value\" : { \"Ref\" : \"IamUser\" }\n        },\n        \"AccessKeyId\" : {\n            \"Description\" : \"AccessKeyId\",\n            \"Value\" : { \"Ref\" : \"CfnKeys\" }\n        }\n    }\n}\n```\n\nJust for reference, this is the output when using the AWS cli tools to validate the template:\n\n```\n$ aws cloudformation validate-template --template-body file://./iam-user.json\n{\n    \"CapabilitiesReason\": \"The following resource(s) require capabilities: [AWS::IAM::User, AWS::IAM::AccessKey]\",\n    \"Description\": \"Test\",\n    \"Parameters\": [],\n    \"Capabilities\": [\n        \"CAPABILITY_IAM\"\n    ]\n}\n```\n\n", "before_files": [{"content": "from boto.resultset import ResultSet\n\nclass Template(object):\n    def __init__(self, connection=None):\n        self.connection = connection\n        self.description = None\n        self.template_parameters = None\n\n    def startElement(self, name, attrs, connection):\n        if name == \"Parameters\":\n            self.template_parameters = ResultSet([('member', TemplateParameter)])\n            return self.template_parameters\n        else:\n            return None\n\n    def endElement(self, name, value, connection):\n        if name == \"Description\":\n            self.description = value\n        else:\n            setattr(self, name, value)\n\nclass TemplateParameter(object):\n    def __init__(self, parent):\n        self.parent = parent\n        self.default_value = None\n        self.description = None\n        self.no_echo = None\n        self.parameter_key = None\n\n    def startElement(self, name, attrs, connection):\n        return None\n\n    def endElement(self, name, value, connection):\n        if name == \"DefaultValue\":\n            self.default_value = value\n        elif name == \"Description\":\n            self.description = value\n        elif name == \"NoEcho\":\n            self.no_echo = bool(value)\n        elif name == \"ParameterKey\":\n            self.parameter_key = value\n        else:\n            setattr(self, name, value)\n", "path": "boto/cloudformation/template.py"}], "after_files": [{"content": "from boto.resultset import ResultSet\nfrom boto.cloudformation.stack import Capability\n\nclass Template(object):\n    def __init__(self, connection=None):\n        self.connection = connection\n        self.description = None\n        self.template_parameters = None\n        self.capabilities_reason = None\n        self.capabilities = None\n\n    def startElement(self, name, attrs, connection):\n        if name == \"Parameters\":\n            self.template_parameters = ResultSet([('member', TemplateParameter)])\n            return self.template_parameters\n        elif name == \"Capabilities\":\n            self.capabilities = ResultSet([('member', Capability)])\n            return self.capabilities\n        else:\n            return None\n\n    def endElement(self, name, value, connection):\n        if name == \"Description\":\n            self.description = value\n        elif name == \"CapabilitiesReason\":\n            self.capabilities_reason = value\n        else:\n            setattr(self, name, value)\n\nclass TemplateParameter(object):\n    def __init__(self, parent):\n        self.parent = parent\n        self.default_value = None\n        self.description = None\n        self.no_echo = None\n        self.parameter_key = None\n\n    def startElement(self, name, attrs, connection):\n        return None\n\n    def endElement(self, name, value, connection):\n        if name == \"DefaultValue\":\n            self.default_value = value\n        elif name == \"Description\":\n            self.description = value\n        elif name == \"NoEcho\":\n            self.no_echo = bool(value)\n        elif name == \"ParameterKey\":\n            self.parameter_key = value\n        else:\n            setattr(self, name, value)\n", "path": "boto/cloudformation/template.py"}]}