diff options
author | Yu-Jie Lin <livibetter@gmail.com> | 2013-08-12 01:08:50 +0800 |
---|---|---|
committer | Yu-Jie Lin <livibetter@gmail.com> | 2013-08-12 01:08:50 +0800 |
commit | ca29de552b9c99596af708e49e82aee9ff64133d (patch) | |
tree | 7b7391f0acb829ef8bd8568df3d42c16549b3d1f | |
parent | c580044c0771b7fe55a15666cf6e8322ef042a29 (diff) | |
download | smartypants-ca29de552b9c99596af708e49e82aee9ff64133d.tar.gz |
Don't use str as variable name, use text, instead
-rwxr-xr-x | smartypants.py | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/smartypants.py b/smartypants.py index a1a2f53..8090f4e 100755 --- a/smartypants.py +++ b/smartypants.py @@ -215,7 +215,7 @@ def smartyPants(text, attr=default_smartypants_attr): return "".join(result) -def educateQuotes(str): +def educateQuotes(text): """ Parameter: String. @@ -230,16 +230,16 @@ def educateQuotes(str): # Special case if the very first character is a quote # followed by punctuation at a non-word-break. Close the quotes by brute # force: - str = re.sub(r"""^'(?=%s\\B)""" % (punct_class,), r"""’""", str) - str = re.sub(r"""^"(?=%s\\B)""" % (punct_class,), r"""”""", str) + text = re.sub(r"""^'(?=%s\\B)""" % (punct_class,), r"""’""", text) + text = re.sub(r"""^"(?=%s\\B)""" % (punct_class,), r"""”""", text) # Special case for double sets of quotes, e.g.: # <p>He said, "'Quoted' words in a larger quote."</p> - str = re.sub(r""""'(?=\w)""", """“‘""", str) - str = re.sub(r"""'"(?=\w)""", """‘“""", str) + text = re.sub(r""""'(?=\w)""", """“‘""", text) + text = re.sub(r"""'"(?=\w)""", """‘“""", text) # Special case for decade abbreviations (the '80s): - str = re.sub(r"""\b'(?=\d{2}s)""", r"""’""", str) + text = re.sub(r"""\b'(?=\d{2}s)""", r"""’""", text) close_class = r"""[^\ \t\r\n\[\{\(\-]""" dec_dashes = r"""–|—""" @@ -257,24 +257,24 @@ def educateQuotes(str): ' # the quote (?=\w) # followed by a word character """ % (dec_dashes,), re.VERBOSE) - str = opening_single_quotes_regex.sub(r"""\1‘""", str) + text = opening_single_quotes_regex.sub(r"""\1‘""", text) closing_single_quotes_regex = re.compile(r""" (%s) ' (?!\s | s\b | \d) """ % (close_class,), re.VERBOSE) - str = closing_single_quotes_regex.sub(r"""\1’""", str) + text = closing_single_quotes_regex.sub(r"""\1’""", text) closing_single_quotes_regex = re.compile(r""" (%s) ' (\s | s\b) """ % (close_class,), re.VERBOSE) - str = closing_single_quotes_regex.sub(r"""\1’\2""", str) + text = closing_single_quotes_regex.sub(r"""\1’\2""", text) # Any remaining single quotes should be opening ones: - str = re.sub(r"""'""", r"""‘""", str) + text = re.sub(r"""'""", r"""‘""", text) # Get most opening double quotes: opening_double_quotes_regex = re.compile(r""" @@ -289,7 +289,7 @@ def educateQuotes(str): " # the quote (?=\w) # followed by a word character """ % (dec_dashes,), re.VERBOSE) - str = opening_double_quotes_regex.sub(r"""\1“""", str) + text = opening_double_quotes_regex.sub(r"""\1“""", text) # Double closing quotes: closing_double_quotes_regex = re.compile(r""" @@ -297,21 +297,21 @@ def educateQuotes(str): " (?=\s) """ % (close_class,), re.VERBOSE) - str = closing_double_quotes_regex.sub(r"""”""", str) + text = closing_double_quotes_regex.sub(r"""”""", text) closing_double_quotes_regex = re.compile(r""" (%s) # character that indicates the quote should be closing " """ % (close_class,), re.VERBOSE) - str = closing_double_quotes_regex.sub(r"""\1”""", str) + text = closing_double_quotes_regex.sub(r"""\1”""", text) # Any remaining quotes should be opening ones. - str = re.sub(r'"', r"""“""", str) + text = re.sub(r'"', r"""“""", text) - return str + return text -def educateBackticks(str): +def educateBackticks(text): """ Parameter: String. Returns: The string, with ``backticks'' -style double quotes @@ -320,12 +320,12 @@ def educateBackticks(str): Example output: “Isn't this fun?” """ - str = re.sub(r"""``""", r"""“""", str) - str = re.sub(r"""''""", r"""”""", str) - return str + text = re.sub(r"""``""", r"""“""", text) + text = re.sub(r"""''""", r"""”""", text) + return text -def educateSingleBackticks(str): +def educateSingleBackticks(text): """ Parameter: String. Returns: The string, with `backticks' -style single quotes @@ -335,12 +335,12 @@ def educateSingleBackticks(str): Example output: ‘Isn’t this fun?’ """ - str = re.sub(r"""`""", r"""‘""", str) - str = re.sub(r"""'""", r"""’""", str) - return str + text = re.sub(r"""`""", r"""‘""", text) + text = re.sub(r"""'""", r"""’""", text) + return text -def educateDashes(str): +def educateDashes(text): """ Parameter: String. @@ -348,12 +348,12 @@ def educateDashes(str): an em-dash HTML entity. """ - str = re.sub(r"""---""", r"""–""", str) # en (yes, backwards) - str = re.sub(r"""--""", r"""—""", str) # em (yes, backwards) - return str + text = re.sub(r"""---""", r"""–""", text) # en (yes, backwards) + text = re.sub(r"""--""", r"""—""", text) # em (yes, backwards) + return text -def educateDashesOldSchool(str): +def educateDashesOldSchool(text): """ Parameter: String. @@ -362,12 +362,12 @@ def educateDashesOldSchool(str): an em-dash HTML entity. """ - str = re.sub(r"""---""", r"""—""", str) # em (yes, backwards) - str = re.sub(r"""--""", r"""–""", str) # en (yes, backwards) - return str + text = re.sub(r"""---""", r"""—""", text) # em (yes, backwards) + text = re.sub(r"""--""", r"""–""", text) # en (yes, backwards) + return text -def educateDashesOldSchoolInverted(str): +def educateDashesOldSchoolInverted(text): """ Parameter: String. @@ -382,12 +382,12 @@ def educateDashesOldSchoolInverted(str): the shortcut should be shorter to type. (Thanks to Aaron Swartz for the idea.) """ - str = re.sub(r"""---""", r"""–""", str) # em - str = re.sub(r"""--""", r"""—""", str) # en - return str + text = re.sub(r"""---""", r"""–""", text) # em + text = re.sub(r"""--""", r"""—""", text) # en + return text -def educateEllipses(str): +def educateEllipses(text): """ Parameter: String. Returns: The string, with each instance of "..." translated to @@ -397,12 +397,12 @@ def educateEllipses(str): Example output: Huh…? """ - str = re.sub(r"""\.\.\.""", r"""…""", str) - str = re.sub(r"""\. \. \.""", r"""…""", str) - return str + text = re.sub(r"""\.\.\.""", r"""…""", text) + text = re.sub(r"""\. \. \.""", r"""…""", text) + return text -def stupefyEntities(str): +def stupefyEntities(text): """ Parameter: String. Returns: The string, with each SmartyPants HTML entity translated to @@ -412,21 +412,21 @@ def stupefyEntities(str): Example output: "Hello -- world." """ - str = re.sub(r"""–""", r"""-""", str) # en-dash - str = re.sub(r"""—""", r"""--""", str) # em-dash + text = re.sub(r"""–""", r"""-""", text) # en-dash + text = re.sub(r"""—""", r"""--""", text) # em-dash - str = re.sub(r"""‘""", r"""'""", str) # open single quote - str = re.sub(r"""’""", r"""'""", str) # close single quote + text = re.sub(r"""‘""", r"""'""", text) # open single quote + text = re.sub(r"""’""", r"""'""", text) # close single quote - str = re.sub(r"""“""", r'''"''', str) # open double quote - str = re.sub(r"""”""", r'''"''', str) # close double quote + text = re.sub(r"""“""", r'''"''', text) # open double quote + text = re.sub(r"""”""", r'''"''', text) # close double quote - str = re.sub(r"""…""", r"""...""", str) # ellipsis + text = re.sub(r"""…""", r"""...""", text) # ellipsis - return str + return text -def processEscapes(str): +def processEscapes(text): r""" Parameter: String. Returns: The string, with after processing the following backslash @@ -442,17 +442,17 @@ def processEscapes(str): \- - \` ` """ - str = re.sub(r"""\\\\""", r"""\""", str) - str = re.sub(r'''\\"''', r""""""", str) - str = re.sub(r"""\\'""", r"""'""", str) - str = re.sub(r"""\\\.""", r""".""", str) - str = re.sub(r"""\\-""", r"""-""", str) - str = re.sub(r"""\\`""", r"""`""", str) + text = re.sub(r"""\\\\""", r"""\""", text) + text = re.sub(r'''\\"''', r""""""", text) + text = re.sub(r"""\\'""", r"""'""", text) + text = re.sub(r"""\\\.""", r""".""", text) + text = re.sub(r"""\\-""", r"""-""", text) + text = re.sub(r"""\\`""", r"""`""", text) - return str + return text -def _tokenize(str): +def _tokenize(text): """ Parameter: String containing HTML markup. Returns: Reference to an array of the tokens comprising the input @@ -470,7 +470,7 @@ def _tokenize(str): tag_soup = re.compile(r"""([^<]*)(<[^>]*>)""") - token_match = tag_soup.search(str) + token_match = tag_soup.search(text) previous_end = 0 while token_match is not None: @@ -480,9 +480,9 @@ def _tokenize(str): tokens.append(['tag', token_match.group(2)]) previous_end = token_match.end() - token_match = tag_soup.search(str, token_match.end()) + token_match = tag_soup.search(text, token_match.end()) - if previous_end < len(str): - tokens.append(['text', str[previous_end:]]) + if previous_end < len(text): + tokens.append(['text', text[previous_end:]]) return tokens |