python: Normalize quotes with Black.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:20:45 -08:00
committed by Tim Abbott
parent 11741543da
commit 6e4c3e41dc
989 changed files with 32792 additions and 32792 deletions

View File

@@ -43,11 +43,11 @@ IGNORED_PHRASES = [
r"Play Store",
r"PM",
r"PMs",
r'REMOTE_USER',
r'Slack',
r"REMOTE_USER",
r"Slack",
r"SSO",
r'Terms of Service',
r'Tuesday',
r"Terms of Service",
r"Tuesday",
r"URL",
r"Ubuntu",
r"Updown",
@@ -94,13 +94,13 @@ IGNORED_PHRASES = [
r"streamname",
r"user@example.com",
# Fragments of larger strings
(r'your subscriptions on your Streams page'),
(r"your subscriptions on your Streams page"),
(
r'Change notification settings for individual streams on your '
r"Change notification settings for individual streams on your "
'<a href="/#streams">Streams page</a>.'
),
(
r'Looking for our '
r"Looking for our "
'<a href="/integrations" target="_blank">Integrations</a> or '
'<a href="/api" target="_blank">API</a> documentation?'
),
@@ -128,10 +128,10 @@ IGNORED_PHRASES = [
r"in 20 minutes",
r"in 3 hours",
# We should probably just delete this string from translations
r'activation key',
r"activation key",
# these are used as topics
r'^new streams$',
r'^stream events$',
r"^new streams$",
r"^stream events$",
# These are used as example short names (e.g. an uncapitalized context):
r"^marketing$",
r"^cookie$",
@@ -167,22 +167,22 @@ IGNORED_PHRASES.sort(key=lambda regex: len(regex), reverse=True)
# text using BeautifulSoup and then removes extra whitespaces from
# it. This step enables us to add HTML in our regexes directly.
COMPILED_IGNORED_PHRASES = [
re.compile(' '.join(BeautifulSoup(regex, 'lxml').text.split())) for regex in IGNORED_PHRASES
re.compile(" ".join(BeautifulSoup(regex, "lxml").text.split())) for regex in IGNORED_PHRASES
]
SPLIT_BOUNDARY = '?.!' # Used to split string into sentences.
SPLIT_BOUNDARY_REGEX = re.compile(fr'[{SPLIT_BOUNDARY}]')
SPLIT_BOUNDARY = "?.!" # Used to split string into sentences.
SPLIT_BOUNDARY_REGEX = re.compile(fr"[{SPLIT_BOUNDARY}]")
# Regexes which check capitalization in sentences.
DISALLOWED = [
r'^[a-z](?!\})', # Checks if the sentence starts with a lower case character.
r'^[A-Z][a-z]+[\sa-z0-9]+[A-Z]', # Checks if an upper case character exists
r"^[a-z](?!\})", # Checks if the sentence starts with a lower case character.
r"^[A-Z][a-z]+[\sa-z0-9]+[A-Z]", # Checks if an upper case character exists
# after a lower case character when the first character is in upper case.
]
DISALLOWED_REGEX = re.compile(r"|".join(DISALLOWED))
BANNED_WORDS = {
'realm': 'The term realm should not appear in user-facing strings. Use organization instead.',
"realm": "The term realm should not appear in user-facing strings. Use organization instead.",
}
@@ -192,7 +192,7 @@ def get_safe_phrase(phrase: str) -> str:
conflict with split boundaries. All conflicting characters are replaced
with low dash (_).
"""
phrase = SPLIT_BOUNDARY_REGEX.sub('_', phrase)
phrase = SPLIT_BOUNDARY_REGEX.sub("_", phrase)
return phrase.lower()
@@ -226,8 +226,8 @@ def get_safe_text(text: str) -> str:
This returns text which is rendered by BeautifulSoup and is in the
form that can be split easily and has all IGNORED_PHRASES processed.
"""
soup = BeautifulSoup(text, 'lxml')
text = ' '.join(soup.text.split()) # Remove extra whitespaces.
soup = BeautifulSoup(text, "lxml")
text = " ".join(soup.text.split()) # Remove extra whitespaces.
for phrase_regex in COMPILED_IGNORED_PHRASES:
text = phrase_regex.sub(replace_with_safe_phrase, text)
@@ -246,7 +246,7 @@ def check_banned_words(text: str) -> List[str]:
if word in lower_cased_text:
# Hack: Should move this into BANNED_WORDS framework; for
# now, just hand-code the skips:
if 'realm_name' in lower_cased_text:
if "realm_name" in lower_cased_text:
continue
kwargs = dict(word=word, text=text, reason=reason)
msg = "{word} found in '{text}'. {reason}".format(**kwargs)
@@ -260,7 +260,7 @@ def check_capitalization(strings: List[str]) -> Tuple[List[str], List[str], List
ignored = []
banned_word_errors = []
for text in strings:
text = ' '.join(text.split()) # Remove extra whitespaces.
text = " ".join(text.split()) # Remove extra whitespaces.
safe_text = get_safe_text(text)
has_ignored_phrase = text != safe_text
capitalized = is_capitalized(safe_text)