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