'Get template file contents.
Get template file contents, either inline, from stack adopt data or
from a URL, in JSON or YAML format.'

def template(self):

    template_data = None
    if (rpc_api.PARAM_ADOPT_STACK_DATA in self.data):
        adopt_data = self.data[rpc_api.PARAM_ADOPT_STACK_DATA]
        try:
            adopt_data = template_format.simple_parse(adopt_data)
            template_format.validate_template_limit(six.text_type(adopt_data['template']))
            return adopt_data['template']
        except (ValueError, KeyError) as ex:
            err_reason = (_('Invalid    adopt    data:    %s') % ex)
            raise exc.HTTPBadRequest(err_reason)
    elif (self.PARAM_TEMPLATE in self.data):
        template_data = self.data[self.PARAM_TEMPLATE]
        if isinstance(template_data, dict):
            template_format.validate_template_limit(six.text_type(template_data))
            return template_data
    elif (self.PARAM_TEMPLATE_URL in self.data):
        url = self.data[self.PARAM_TEMPLATE_URL]
        LOG.debug(('TemplateUrl    %s' % url))
        try:
            template_data = urlfetch.get(url)
        except IOError as ex:
            err_reason = (_('Could    not    retrieve    template:    %s') % ex)
            raise exc.HTTPBadRequest(err_reason)
    if (template_data is None):
        if self.patch:
            return None
        else:
            raise exc.HTTPBadRequest(_('No    template    specified'))
    with self.parse_error_check('Template'):
        return template_format.parse(template_data)
