Create a new template.

        Args:
            `data`: json data required for creating a template
        Returns:
            Dictionary containing the details of the template with its ID.
511222
def createTemplate(data):
        
        conn = Qubole.agent()
        return conn.post(Template.rest_entity_path, data)
171668
def get_template(self, data=None):  # noqa (complexity)
        """"""
        with self.__lock:
            if self.__value_templates is None and self.__last_parse_ok:
                try:
                    self.__refresh()
                except RefreshException:
                    # Point has no (useable) values - don't try to refetch again
                    self.__last_parse_ok = False
                    raise
            if self.__value_templates is None:
                raise ValueError('Point has no values')
            if data is None:
                template = PointDataObject(self.__value_templates, self.__filter)
            else:
                while True:
                    try:
                        template = PointDataObject._from_dict(self.__value_templates, self.__filter, data)
                    except:
                        # parsing has failed for first time since refresh so try again
                        if self.__last_parse_ok:
                            logger.debug('Failed to parse data from for point %s, refreshing', self.__point)
                            self.__last_parse_ok = False
                            try:
                                self.__refresh()
                            except RefreshException:
                                break
                        else:
                            raise
                    else:
                        self.__last_parse_ok = True
                        break
            return template
416915
def _create_json(self):
        
        data_json = {
            "name": self.name,
            "includesPattern": self.includesPattern,
            "excludesPattern": self.excludesPattern,
            "repositories": self._repositories,
            "principals": {
                'users': self._users,
                'groups': self._groups,
            }
        }
        return data_json
1142502
def add_content(self, data):
        # type: (Optional[Union[Dict[str, Any], ET.Element]]) -> None
        
        if data is None:
            return

        if isinstance(data, ET.Element):
            bytes_data = ET.tostring(data, encoding="utf8")
            self.headers['Content-Length'] = str(len(bytes_data))
            self.data = bytes_data
            return

        # By default, assume JSON
        try:
            self.data = json.dumps(data)
            self.headers['Content-Length'] = str(len(self.data))
        except TypeError:
            self.data = data
394252
def render(self, mold_id, data):
        

        template = self.load_mold(mold_id)
        return template.render(**data)
219489
def generate(self, name: str, **kwargs: Dict[str, str]) -> str:
        
        template = self.patterns[name]
        return template.substitute(kwargs)
630052
def submitTemplate(id, data={}):
        
        conn = Qubole.agent()
        path = str(id) + "/run"
        return conn.post(Template.element_path(path), data)
1285040
def load(template):
    

    try:
        data = load_json(template)
        return data, "json"
    except ValueError as e:
        try:
            data = load_yaml(template)
            return data, "yaml"
        except Exception:
            raise e
318725
def new_template(template_name: str, ordering: int, formatting: dict=None, **kwargs):
        
        if formatting is not None:
            kwargs.update(formatting)

        template = dict([
            ('name', template_name),
            ('qfmt', DEFAULT_TEMPLATE['qfmt']),
            ('did', None),
            ('bafmt', DEFAULT_TEMPLATE['bafmt']),
            ('afmt', DEFAULT_TEMPLATE['afmt']),
            ('ord', ordering),
            ('bqfmt', DEFAULT_TEMPLATE['bqfmt'])
        ])

        for k, v in template.items():
            if k in kwargs.keys():
                template[k] = kwargs[k]

        return template
903509
def create_from_name_and_dictionary(self, name, datas):
        
        parameter = ObjectParameter()
        self.set_common_datas(parameter, name, datas)

        if "optional" in datas:
            parameter.optional = to_boolean(datas["optional"])
        if "type" in datas:
            parameter.type = str(datas["type"])
        if "generic" in datas:
            parameter.generic = to_boolean(datas["generic"])

        return parameter
974989
def get_template_as_json(template_id, **kwargs):
    
    user_id = kwargs['user_id']
    return json.dumps(get_template_as_dict(template_id, user_id=user_id))
1158493
def to_html(data):
    
    base_html_template = Template('''
        <html>
            <head>
                {% if style %}
                <style type="text/css">
                    {{ style }}
                </style>
                {% endif %}
            </head>
            <body>
                {% if style %}
                    {{ body|safe }}
                {% else %}
                    <pre></code>{{ body }}</code></pre>
                {% endif %}
            </body>
        </html>
        ''')

    code = to_json(data, indent=4)
    if PYGMENTS_INSTALLED:
        c = Context({
            'body': highlight(code, JSONLexer(), HtmlFormatter()),
            'style': HtmlFormatter().get_style_defs('.highlight')
        })
        html = base_html_template.render(c)
    else:
        c = Context({'body': code})
        html = base_html_template.render(c)
    return html
218353
def get_template(template_file='', **kwargs):
    
    template = get_template_object(template_file)

    LOG.info('Rendering template %s', template.filename)
    for key, value in kwargs.items():
        LOG.debug('%s => %s', key, value)

    rendered_json = template.render(**kwargs)
    LOG.debug('Rendered JSON:\n%s', rendered_json)

    return rendered_json
1062693
def create(self, data):
        
        response = self.http.post(str(self), json=data, auth=self.auth)
        response.raise_for_status()
        return response.json()
361223
def create_instance(self, name, template, args=None, labels=None):
        
        req = rest_pb2.CreateInstanceRequest()
        req.name = name
        req.template = template
        if args:
            for k in args:
                req.templateArgs[k] = args[k]
        if labels:
            for k in labels:
                req.labels[k] = labels[k]
        url = '/instances'
        self.post_proto(url, data=req.SerializeToString())
81270
def create_for_data(cls, data, format, width, height, stride=None):
        
        return cls(format, width, height, data, stride)
1308280
def create(self, data, inlineparent = None):
        '''
        
        '''
        try:
            return self.struct.unpack(data)[0]
        except struct.error as exc:
            raise BadFormatError(exc)