Use format() instead of string interpolation, for old Python versions.

pull/13171/head
Joshua Haberman 4 years ago
parent 8e08282c3b
commit 8b7dabe1a2
  1. 2
      benchmarks/BUILD
  2. 8
      benchmarks/gen_protobuf_binary_cc.py
  3. 8
      benchmarks/gen_upb_binary_c.py

@ -84,11 +84,13 @@ py_binary(
py_binary( py_binary(
name = "gen_upb_binary_c", name = "gen_upb_binary_c",
srcs = ["gen_upb_binary_c.py"], srcs = ["gen_upb_binary_c.py"],
python_version = "PY3",
) )
py_binary( py_binary(
name = "gen_protobuf_binary_cc", name = "gen_protobuf_binary_cc",
srcs = ["gen_protobuf_binary_cc.py"], srcs = ["gen_protobuf_binary_cc.py"],
python_version = "PY3",
) )
genrule( genrule(

@ -11,22 +11,22 @@ if m:
msg_basename = m.group(1) msg_basename = m.group(1)
count = int(m.group(2)) count = int(m.group(2))
print(f''' print('''
#include "{include}" #include "{include}"
char buf[1]; char buf[1];
int main() {{ int main() {{
''') '''.format(include=include))
def RefMessage(name): def RefMessage(name):
print(f''' print('''
{{ {{
{name} proto; {name} proto;
proto.ParseFromArray(buf, 0); proto.ParseFromArray(buf, 0);
proto.SerializePartialToArray(&buf[0], 0); proto.SerializePartialToArray(&buf[0], 0);
}} }}
''') '''.format(name=name))
RefMessage(msg_basename) RefMessage(msg_basename)

@ -11,7 +11,7 @@ if m:
msg_basename = m.group(1) msg_basename = m.group(1)
count = int(m.group(2)) count = int(m.group(2))
print(f''' print('''
#include "{include}" #include "{include}"
char buf[1]; char buf[1];
@ -19,15 +19,15 @@ char buf[1];
int main() {{ int main() {{
upb_arena *arena = upb_arena_new(); upb_arena *arena = upb_arena_new();
size_t size; size_t size;
''') '''.format(include=include))
def RefMessage(name): def RefMessage(name):
print(f''' print('''
{{ {{
{name} *proto = {name}_parse(buf, 1, arena); {name} *proto = {name}_parse(buf, 1, arena);
{name}_serialize(proto, arena, &size); {name}_serialize(proto, arena, &size);
}} }}
''') '''.format(name=name))
RefMessage(msg_basename) RefMessage(msg_basename)

Loading…
Cancel
Save