summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu-Jie Lin <livibetter@gmail.com>2013-08-12 01:08:50 +0800
committerYu-Jie Lin <livibetter@gmail.com>2013-08-12 01:08:50 +0800
commitca29de552b9c99596af708e49e82aee9ff64133d (patch)
tree7b7391f0acb829ef8bd8568df3d42c16549b3d1f
parentc580044c0771b7fe55a15666cf6e8322ef042a29 (diff)
downloadsmartypants-ca29de552b9c99596af708e49e82aee9ff64133d.tar.gz
Don't use str as variable name, use text, instead
-rwxr-xr-xsmartypants.py122
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"""&#8217;""", str)
- str = re.sub(r"""^"(?=%s\\B)""" % (punct_class,), r"""&#8221;""", str)
+ text = re.sub(r"""^'(?=%s\\B)""" % (punct_class,), r"""&#8217;""", text)
+ text = re.sub(r"""^"(?=%s\\B)""" % (punct_class,), r"""&#8221;""", 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)""", """&#8220;&#8216;""", str)
- str = re.sub(r"""'"(?=\w)""", """&#8216;&#8220;""", str)
+ text = re.sub(r""""'(?=\w)""", """&#8220;&#8216;""", text)
+ text = re.sub(r"""'"(?=\w)""", """&#8216;&#8220;""", text)
# Special case for decade abbreviations (the '80s):
- str = re.sub(r"""\b'(?=\d{2}s)""", r"""&#8217;""", str)
+ text = re.sub(r"""\b'(?=\d{2}s)""", r"""&#8217;""", text)
close_class = r"""[^\ \t\r\n\[\{\(\-]"""
dec_dashes = r"""&#8211;|&#8212;"""
@@ -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&#8216;""", str)
+ text = opening_single_quotes_regex.sub(r"""\1&#8216;""", 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&#8217;""", str)
+ text = closing_single_quotes_regex.sub(r"""\1&#8217;""", text)
closing_single_quotes_regex = re.compile(r"""
(%s)
'
(\s | s\b)
""" % (close_class,), re.VERBOSE)
- str = closing_single_quotes_regex.sub(r"""\1&#8217;\2""", str)
+ text = closing_single_quotes_regex.sub(r"""\1&#8217;\2""", text)
# Any remaining single quotes should be opening ones:
- str = re.sub(r"""'""", r"""&#8216;""", str)
+ text = re.sub(r"""'""", r"""&#8216;""", 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&#8220;""", str)
+ text = opening_double_quotes_regex.sub(r"""\1&#8220;""", 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"""&#8221;""", str)
+ text = closing_double_quotes_regex.sub(r"""&#8221;""", 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&#8221;""", str)
+ text = closing_double_quotes_regex.sub(r"""\1&#8221;""", text)
# Any remaining quotes should be opening ones.
- str = re.sub(r'"', r"""&#8220;""", str)
+ text = re.sub(r'"', r"""&#8220;""", 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: &#8220;Isn't this fun?&#8221;
"""
- str = re.sub(r"""``""", r"""&#8220;""", str)
- str = re.sub(r"""''""", r"""&#8221;""", str)
- return str
+ text = re.sub(r"""``""", r"""&#8220;""", text)
+ text = re.sub(r"""''""", r"""&#8221;""", 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: &#8216;Isn&#8217;t this fun?&#8217;
"""
- str = re.sub(r"""`""", r"""&#8216;""", str)
- str = re.sub(r"""'""", r"""&#8217;""", str)
- return str
+ text = re.sub(r"""`""", r"""&#8216;""", text)
+ text = re.sub(r"""'""", r"""&#8217;""", 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"""&#8211;""", str) # en (yes, backwards)
- str = re.sub(r"""--""", r"""&#8212;""", str) # em (yes, backwards)
- return str
+ text = re.sub(r"""---""", r"""&#8211;""", text) # en (yes, backwards)
+ text = re.sub(r"""--""", r"""&#8212;""", 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"""&#8212;""", str) # em (yes, backwards)
- str = re.sub(r"""--""", r"""&#8211;""", str) # en (yes, backwards)
- return str
+ text = re.sub(r"""---""", r"""&#8212;""", text) # em (yes, backwards)
+ text = re.sub(r"""--""", r"""&#8211;""", 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"""&#8211;""", str) # em
- str = re.sub(r"""--""", r"""&#8212;""", str) # en
- return str
+ text = re.sub(r"""---""", r"""&#8211;""", text) # em
+ text = re.sub(r"""--""", r"""&#8212;""", 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&#8230;?
"""
- str = re.sub(r"""\.\.\.""", r"""&#8230;""", str)
- str = re.sub(r"""\. \. \.""", r"""&#8230;""", str)
- return str
+ text = re.sub(r"""\.\.\.""", r"""&#8230;""", text)
+ text = re.sub(r"""\. \. \.""", r"""&#8230;""", 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"""&#8211;""", r"""-""", str) # en-dash
- str = re.sub(r"""&#8212;""", r"""--""", str) # em-dash
+ text = re.sub(r"""&#8211;""", r"""-""", text) # en-dash
+ text = re.sub(r"""&#8212;""", r"""--""", text) # em-dash
- str = re.sub(r"""&#8216;""", r"""'""", str) # open single quote
- str = re.sub(r"""&#8217;""", r"""'""", str) # close single quote
+ text = re.sub(r"""&#8216;""", r"""'""", text) # open single quote
+ text = re.sub(r"""&#8217;""", r"""'""", text) # close single quote
- str = re.sub(r"""&#8220;""", r'''"''', str) # open double quote
- str = re.sub(r"""&#8221;""", r'''"''', str) # close double quote
+ text = re.sub(r"""&#8220;""", r'''"''', text) # open double quote
+ text = re.sub(r"""&#8221;""", r'''"''', text) # close double quote
- str = re.sub(r"""&#8230;""", r"""...""", str) # ellipsis
+ text = re.sub(r"""&#8230;""", 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):
\- &#45;
\` &#96;
"""
- str = re.sub(r"""\\\\""", r"""&#92;""", str)
- str = re.sub(r'''\\"''', r"""&#34;""", str)
- str = re.sub(r"""\\'""", r"""&#39;""", str)
- str = re.sub(r"""\\\.""", r"""&#46;""", str)
- str = re.sub(r"""\\-""", r"""&#45;""", str)
- str = re.sub(r"""\\`""", r"""&#96;""", str)
+ text = re.sub(r"""\\\\""", r"""&#92;""", text)
+ text = re.sub(r'''\\"''', r"""&#34;""", text)
+ text = re.sub(r"""\\'""", r"""&#39;""", text)
+ text = re.sub(r"""\\\.""", r"""&#46;""", text)
+ text = re.sub(r"""\\-""", r"""&#45;""", text)
+ text = re.sub(r"""\\`""", r"""&#96;""", 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