mirror of https://github.com/zulip/zulip.git
python: Convert more percent formatting to "".format.
Semgrep has gotten a little more clever at applying the percent formatting rule. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
fff7fe21cb
commit
6189e4d0c1
|
@ -20,12 +20,12 @@ def get_version_file() -> str:
|
|||
PREAMBLE = '''
|
||||
Before we run tests, we make sure your provisioning version
|
||||
is correct by looking at var/provision_version, which is at
|
||||
version %s, and we compare it to the version in source
|
||||
control (version.py), which is %s.
|
||||
version {}, and we compare it to the version in source
|
||||
control (version.py), which is {}.
|
||||
'''
|
||||
|
||||
def preamble(version: str) -> str:
|
||||
text = PREAMBLE % (version, PROVISION_VERSION)
|
||||
text = PREAMBLE.format(version, PROVISION_VERSION)
|
||||
text += '\n'
|
||||
return text
|
||||
|
||||
|
|
|
@ -47,32 +47,32 @@ NODE_MODULES_PATH = os.path.join(ZULIP_PATH, 'node_modules')
|
|||
SPRITE_CSS_FILE_TEMPLATE = """\
|
||||
div.emoji,
|
||||
span.emoji
|
||||
{
|
||||
{{
|
||||
display: inline-block;
|
||||
background-image: url(~emoji-datasource-%(emojiset)s/img/%(alt_name)s/sheets-256/64.png);
|
||||
background-size: %(background_size)s;
|
||||
background-image: url(~emoji-datasource-{emojiset}/img/{alt_name}/sheets-256/64.png);
|
||||
background-size: {background_size};
|
||||
background-repeat: no-repeat;
|
||||
|
||||
/* Hide the text. */
|
||||
text-indent: 100%%;
|
||||
text-indent: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
}}
|
||||
|
||||
.emoji-1f419
|
||||
{
|
||||
{{
|
||||
background-image: url(../emoji/images-google-64/1f419.png) !important;
|
||||
background-position: 0%% 0%% !important;
|
||||
background-position: 0% 0% !important;
|
||||
background-size: contain !important;
|
||||
}
|
||||
}}
|
||||
|
||||
%(emoji_positions)s
|
||||
{emoji_positions}
|
||||
"""
|
||||
|
||||
EMOJI_POS_INFO_TEMPLATE = """\
|
||||
.emoji-%(codepoint)s {
|
||||
background-position: %(pos_x)s %(pos_y)s;
|
||||
}
|
||||
.emoji-{codepoint} {{
|
||||
background-position: {pos_x} {pos_y};
|
||||
}}
|
||||
"""
|
||||
|
||||
# change directory
|
||||
|
@ -207,19 +207,22 @@ def generate_sprite_css_files(cache_path: str,
|
|||
will get more complicated.
|
||||
"""
|
||||
|
||||
emoji_positions += EMOJI_POS_INFO_TEMPLATE % {
|
||||
'codepoint': get_emoji_code(emoji),
|
||||
'pos_x': percent(emoji["sheet_x"] / (n - 1)),
|
||||
'pos_y': percent(emoji["sheet_y"] / (n - 1)),
|
||||
}
|
||||
emoji_positions += EMOJI_POS_INFO_TEMPLATE.format(
|
||||
codepoint=get_emoji_code(emoji),
|
||||
pos_x=percent(emoji["sheet_x"] / (n - 1)),
|
||||
pos_y=percent(emoji["sheet_y"] / (n - 1)),
|
||||
)
|
||||
|
||||
SPRITE_CSS_PATH = os.path.join(cache_path, f'{emojiset}-sprite.css')
|
||||
with open(SPRITE_CSS_PATH, 'w') as f:
|
||||
f.write(SPRITE_CSS_FILE_TEMPLATE % {'emojiset': emojiset,
|
||||
'alt_name': alt_name,
|
||||
'emoji_positions': emoji_positions,
|
||||
'background_size': background_size,
|
||||
})
|
||||
f.write(
|
||||
SPRITE_CSS_FILE_TEMPLATE.format(
|
||||
emojiset=emojiset,
|
||||
alt_name=alt_name,
|
||||
emoji_positions=emoji_positions,
|
||||
background_size=background_size,
|
||||
),
|
||||
)
|
||||
|
||||
def setup_emoji_farms(cache_path: str, emoji_data: List[Dict[str, Any]]) -> None:
|
||||
def ensure_emoji_image(emoji_dict: Dict[str, Any],
|
||||
|
|
|
@ -29,18 +29,18 @@ with open(EMOJI_MAP_FILE) as fp:
|
|||
EMOJI_MAP = ujson.load(fp)
|
||||
|
||||
EMOJI_IMAGE_TEMPLATE = """
|
||||
<img class="emoji" src="images-%(emojiset)s-64/%(emoji_code)s.png" title=%(emojiset)s>
|
||||
<img class="emoji" src="images-{emojiset}-64/{emoji_code}.png" title={emojiset}>
|
||||
"""
|
||||
|
||||
TABLE_ROW_TEMPLATE = """
|
||||
<tr>
|
||||
<td class="new-sorting-info">%(sorting_info)s</td>
|
||||
<td class="emoji-code">%(emoji_code)s</td>
|
||||
<td class="emoji-images">%(images_html)s</td>
|
||||
<td class="zulip-emoji-names">%(zulip_names)s</td>
|
||||
<td class="iamcal-emoji-names">%(iamcal_names)s</td>
|
||||
<td class="gemoji-emoji-names">%(gemoji_names)s</td>
|
||||
<td class="unicode-name">%(unicode_name)s</td>
|
||||
<td class="new-sorting-info">{sorting_info}</td>
|
||||
<td class="emoji-code">{emoji_code}</td>
|
||||
<td class="emoji-images">{images_html}</td>
|
||||
<td class="zulip-emoji-names">{zulip_names}</td>
|
||||
<td class="iamcal-emoji-names">{iamcal_names}</td>
|
||||
<td class="gemoji-emoji-names">{gemoji_names}</td>
|
||||
<td class="unicode-name">{unicode_name}</td>
|
||||
</tr>
|
||||
"""
|
||||
|
||||
|
@ -48,7 +48,7 @@ EMOJI_LISTING_TEMPLATE = """
|
|||
<html>
|
||||
<head>
|
||||
<style>
|
||||
%(table_css)s
|
||||
{table_css}
|
||||
</style>
|
||||
<title>Zulip emoji names</title>
|
||||
</head>
|
||||
|
@ -66,7 +66,7 @@ EMOJI_LISTING_TEMPLATE = """
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
%(tbody)s
|
||||
{tbody}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
|
@ -156,10 +156,10 @@ def get_sorting_info(category: str, sort_order: int) -> str:
|
|||
def get_images_html(emoji_code: str) -> str:
|
||||
images_html = ''
|
||||
for emojiset in EMOJISETS:
|
||||
images_html += (EMOJI_IMAGE_TEMPLATE % {
|
||||
'emoji_code': emoji_code,
|
||||
'emojiset': emojiset,
|
||||
})
|
||||
images_html += EMOJI_IMAGE_TEMPLATE.format(
|
||||
emoji_code=emoji_code,
|
||||
emojiset=emojiset,
|
||||
)
|
||||
|
||||
return images_html
|
||||
|
||||
|
@ -194,14 +194,13 @@ def main() -> None:
|
|||
tbody = ""
|
||||
for category in SORTED_CATEGORIES:
|
||||
for emoji_entry in emoji_collection[category]:
|
||||
# We need to use the weird `dict(**kwargs)` format to avoid lint errors.
|
||||
tbody += TABLE_ROW_TEMPLATE % dict(**emoji_entry)
|
||||
tbody += TABLE_ROW_TEMPLATE.format(**emoji_entry)
|
||||
|
||||
with open(OUTPUT_FILE, 'w') as fp:
|
||||
fp.write(EMOJI_LISTING_TEMPLATE % {
|
||||
'tbody': tbody,
|
||||
'table_css': TABLE_CSS,
|
||||
})
|
||||
fp.write(EMOJI_LISTING_TEMPLATE.format(
|
||||
tbody=tbody,
|
||||
table_css=TABLE_CSS,
|
||||
))
|
||||
|
||||
print("Done! Open http://localhost:9991/static/generated/emoji/emoji_names_table.html "
|
||||
"to view(after starting the dev server).")
|
||||
|
|
|
@ -113,8 +113,8 @@ FENCE_RE = re.compile("""
|
|||
""", re.VERBOSE)
|
||||
|
||||
|
||||
CODE_WRAP = '<pre><code%s>%s\n</code></pre>'
|
||||
LANG_TAG = ' class="%s"'
|
||||
CODE_WRAP = '<pre><code{}>{}\n</code></pre>'
|
||||
LANG_TAG = ' class="{}"'
|
||||
|
||||
def validate_curl_content(lines: List[str]) -> None:
|
||||
error_msg = """
|
||||
|
@ -363,7 +363,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
|
|||
|
||||
def format_code(self, lang: str, text: str) -> str:
|
||||
if lang:
|
||||
langclass = LANG_TAG % (lang,)
|
||||
langclass = LANG_TAG.format(lang)
|
||||
else:
|
||||
langclass = ''
|
||||
|
||||
|
@ -390,7 +390,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
|
|||
|
||||
code = highliter.hilite()
|
||||
else:
|
||||
code = CODE_WRAP % (langclass, self._escape(text))
|
||||
code = CODE_WRAP.format(langclass, self._escape(text))
|
||||
|
||||
return code
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ gear_instructions = """
|
|||
1. From your desktop, click on the **gear**
|
||||
(<i class="fa fa-cog"></i>) in the upper right corner.
|
||||
|
||||
1. Select %(item)s.
|
||||
1. Select {item}.
|
||||
"""
|
||||
|
||||
def gear_handle_match(key: str) -> str:
|
||||
|
@ -38,7 +38,7 @@ def gear_handle_match(key: str) -> str:
|
|||
item = f'[{gear_info[key][0]}]({gear_info[key][1]})'
|
||||
else:
|
||||
item = f'**{gear_info[key][0]}**'
|
||||
return gear_instructions % {'item': item}
|
||||
return gear_instructions.format(item=item)
|
||||
|
||||
|
||||
stream_info = {
|
||||
|
|
|
@ -56,9 +56,9 @@ settings_markdown = """
|
|||
1. From your desktop, click on the **gear**
|
||||
(<i class="fa fa-cog"></i>) in the upper right corner.
|
||||
|
||||
1. Select **%(setting_type_name)s**.
|
||||
1. Select **{setting_type_name}**.
|
||||
|
||||
1. On the left, click %(setting_reference)s.
|
||||
1. On the left, click {setting_reference}.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -105,8 +105,10 @@ class Setting(Preprocessor):
|
|||
setting_link = link_mapping[setting_identifier][2]
|
||||
if relative_settings_links:
|
||||
return f"1. Go to [{setting_name}]({setting_link})."
|
||||
return settings_markdown % {'setting_type_name': setting_type_name,
|
||||
'setting_reference': f"**{setting_name}**"}
|
||||
return settings_markdown.format(
|
||||
setting_type_name=setting_type_name,
|
||||
setting_reference=f"**{setting_name}**",
|
||||
)
|
||||
|
||||
def makeExtension(*args: Any, **kwargs: Any) -> SettingHelpExtension:
|
||||
return SettingHelpExtension(*args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue