本文整理汇总了Python中string.Template.format方法的典型用法代码示例。如果您正苦于以下问题:Python Template.format方法的具体用法?Python Template.format怎么用?Python Template.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string.Template
的用法示例。
在下文中一共展示了Template.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bind_render_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def bind_render_record(self, pk=False):
TXT_LINE_LENGTH = 120
def length_format(line):
if len(line) <= TXT_LINE_LENGTH:
return '"{0}"'.format(line)
return (('"%s"' % line[:TXT_LINE_LENGTH]) + "\n"
+ length_format(line[TXT_LINE_LENGTH:]))
template = Template(self.template).substitute(**self.justs)
bind_name = self.fqdn + "."
if not self.ttl:
self.ttl = 3600
txt_lines = self.escaped_txt_data.split('\n')
txt_data = ""
if len(txt_lines) > 1:
for line in txt_lines:
txt_data += length_format(line) + "\n"
else:
txt_data = length_format(self.escaped_txt_data)
txt_data = txt_data.strip('\n')
if '\n' in txt_data:
txt_data = '(\n{0})'.format(txt_data).replace('\n', '\n ')
return template.format(
bind_name=bind_name, ttl=self.ttl, rdtype=self.rdtype,
rdclass='IN', txt_data=txt_data
)
示例2: bind_render_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def bind_render_record(self, pk=False, **kwargs):
# We need to override this because fqdn is actually self.domain.name
template = Template(self.template).substitute(**self.justs)
return template.format(
rdtype=self.rdtype, rdclass='IN', bind_name=self.domain.name + '.',
**self.__dict__
)
示例3: bind_render_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def bind_render_record(self, pk=False):
template = Template(self.template).substitute(**self.justs)
bind_name = self.fqdn + "."
if not self.ttl:
self.ttl = 3600
return template.format(bind_name=bind_name, rdtype=self.rdtype,
rdclass='IN', **vars(self))
示例4: render_ns
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_ns(nameserver_set):
BUILD_STR = ''
template = Template("{label:$label_just} {rclass:$class_just} {rtype:$type_just} {server:$data_just}.\n")
template = template.substitute(label_just=label_just, class_just=class_just,\
type_just=type_just, data_just=data_just)
for ns in nameserver_set:
BUILD_STR += template.format(label='@', rclass='IN', rtype='NS', server=ns.server)
return BUILD_STR
示例5: render_srv
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_srv(srv_set):
BUILD_STR = ''
template = Template("{label:$label_just} {rclass:$class_just} {rtype:$type_just} {prio:$prio_just} {weight:$extra_just} {port:$extra_just} {target:$extra_just}.\n")
template = template.substitute(label_just=label_just, class_just=class_just,\
type_just=type_just, prio_just=prio_just, extra_just=extra_just)
for srv in srv_set:
BUILD_STR += template.format(label=srv.label, rclass='IN', rtype='SRV', prio=str(srv.priority), weight=str(srv.weight), port=str(srv.port), target=str(srv.target))
return BUILD_STR
示例6: render_ptr
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_ptr(ptr_set):
BUILD_STR = ''
template = Template("{ip:$ip_just} {rclass:$class_just} {rtype:$type_just} {name:$name_just}.\n")
template = template.substitute(ip_just=ip_just, class_just=class_just,\
type_just=type_just, name_just=name_just)
for ptr in ptr_set:
BUILD_STR += template.format(ip=ptr.ip_str, rclass='IN', rtype='PTR', name=ptr.name)
return BUILD_STR
示例7: render_cname
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_cname(cname_set):
BUILD_STR = ''
template = Template("{label:$label_just} {rclass:$class_just} {rtype:$type_just} {data:$data_just}.\n")
template = template.substitute(label_just=label_just, class_just=class_just,\
type_just=type_just, data_just=data_just)
for cname in cname_set:
label = cname.label if cname.label != '' else '@'
BUILD_STR += template.format(label=label, rclass='IN', rtype='CNAME', data=cname.data)
return BUILD_STR
示例8: render_txt
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_txt(txt_set):
BUILD_STR = ''
template = Template("{label:$label_just} {rclass:$class_just} {rtype:$type_just} \"{data:$data_just}\"\n")
template = template.substitute(label_just=label_just, class_just=class_just,\
type_just=type_just, data_just=data_just)
for txt in txt_set:
label = txt.label if txt.label != '' else '@'
BUILD_STR += template.format(label=label, rclass='IN', rtype='TXT', data=txt.txt_data)
return BUILD_STR
示例9: bind_render_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def bind_render_record(self, show_ttl=False):
template = Template(self.template).substitute(**self.justs)
if show_ttl:
ttl_ = self.ttl
else:
ttl_ = '' if self.ttl is None else self.ttl
return template.format(
root_domain=self.root_domain, rdtype=self.rdtype, rdclass='IN',
ttl_=ttl_, **vars(self)
)
示例10: bind_render_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def bind_render_record(self, pk=False, show_ttl=False):
template = Template(self.template).substitute(**self.justs)
bind_name = self.fqdn + "."
if show_ttl:
ttl_ = self.ttl
else:
ttl_ = '' if self.ttl is None else self.ttl
return template.format(
bind_name=bind_name, rdtype=self.rdtype, rdclass='IN',
ttl_=ttl_, **vars(self)
)
示例11: render_mx
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_mx(mx_set):
BUILD_STR = ''
template = Template("{label:$label_just} {rclass:$class_just} {rtype:$type_just} {prio:$prio_just} {server:$data_just}.\n")
template = template.substitute(label_just=label_just, class_just=class_just,\
type_just=type_just, prio_just=prio_just, data_just=data_just)
for mx in mx_set:
BUILD_STR += "$TTL %s\n" % (mx.ttl)
label = mx.label if mx.label != '' else '@'
BUILD_STR += template.format(label=label, rclass='IN', rtype='MX', prio=str(mx.priority),\
server=mx.server)
return BUILD_STR
示例12: render_address_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_address_record(addressrecord_set):
BUILD_STR = ''
template = Template("{label:$label_just} {rclass:$class_just} {rtype:$type_just} {address:$data_just}\n")
template = template.substitute(label_just=label_just, class_just=class_just,\
type_just=type_just, data_just=data_just)
for rec in addressrecord_set:
if rec.ip_type == '4':
rec_type = 'A'
else:
rec_type = 'AAAA'
label = rec.label if rec.label != '' else '@'
BUILD_STR += template.format(label=label, rclass='IN', rtype=rec_type, address=rec.ip_str)
return BUILD_STR
示例13: render_intr
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_intr(interface_set):
BUILD_STR = ''
template = Template("{ip:$ip_just} {ttl} {rclass:$class_just} {rtype:$type_just} {name:$name_just}.\n")
template = template.substitute(ip_just=ip_just, class_just=class_just,
type_just=type_just, name_just=name_just)
for intr in interface_set:
if intr.ttl == 3600 or intr.ttl is None:
ttl = ''
else:
ttl = str(intr.ttl)
BUILD_STR += template.format(
ip=ip_to_dns_form(intr.ip_str), ttl=ttl, rclass='IN',
rtype='PTR', name=intr.fqdn)
return BUILD_STR
示例14: bind_render_record
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def bind_render_record(self, pk=False, custom=None):
kwargs = vars(self)
if custom:
for key, value in custom.items():
kwargs[key] = value
template = Template(self.template).substitute(**self.justs)
bind_name = self.fqdn + "."
if not self.ttl:
self.ttl = 3600
return template.format(bind_name=bind_name, rdtype=self.rdtype,
rdclass='IN', **kwargs)
示例15: render_ns
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import format [as 别名]
def render_ns(nameserver_set):
"""
name ttl class rr name
"""
BUILD_STR = ''
template = Template("{name:$name_just} {ttl} {rclass:$class_just} {rtype:$type_just} {server:$data_just}.\n")
template = template.substitute(name_just=name_just, class_just=class_just,
type_just=type_just, data_just=data_just)
for ns in nameserver_set:
if ns.ttl == 3600 or ns.ttl is None:
ttl = ''
else:
ttl = str(ns.ttl)
BUILD_STR += template.format(name=ns.domain.name + ".", ttl=ttl, rclass='IN', rtype='NS', server=ns.server)
return BUILD_STR