From f9abbe98008099a1e2b392b4fb4618d1a9995cc6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 27 Feb 2014 09:19:08 +0530 Subject: [PATCH] pep8 --- src/calibre/utils/smartypants.py | 64 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/calibre/utils/smartypants.py b/src/calibre/utils/smartypants.py index 1819147c38..0356fb7deb 100644 --- a/src/calibre/utils/smartypants.py +++ b/src/calibre/utils/smartypants.py @@ -392,7 +392,7 @@ def cb_story(args): try: forbidden_flavours = args["entry"]["smartypants_forbidden_flavours"] except KeyError: - forbidden_flavours = [ "rss" ] + forbidden_flavours = ["rss"] try: attributes = args["entry"]["smartypants_attributes"] @@ -416,7 +416,7 @@ def cb_story(args): args["entry"]["title"] = smartyPants(args["entry"]["title"], attributes) -### interal functions below here +# interal functions below here def smartyPants(text, attr=default_smartypants_attr): convert_quot = False # should we translate " entities into normal quotes? @@ -468,14 +468,22 @@ def smartyPants(text, attr=default_smartypants_attr): do_stupefy = "1" else: for c in attr: - if c == "q": do_quotes = "1" - elif c == "b": do_backticks = "1" - elif c == "B": do_backticks = "2" - elif c == "d": do_dashes = "1" - elif c == "D": do_dashes = "2" - elif c == "i": do_dashes = "3" - elif c == "e": do_ellipses = "1" - elif c == "w": convert_quot = "1" + if c == "q": + do_quotes = "1" + elif c == "b": + do_backticks = "1" + elif c == "B": + do_backticks = "2" + elif c == "d": + do_dashes = "1" + elif c == "D": + do_dashes = "2" + elif c == "i": + do_dashes = "3" + elif c == "e": + do_ellipses = "1" + elif c == "w": + convert_quot = "1" else: pass # ignore unknown option @@ -514,7 +522,7 @@ def smartyPants(text, attr=default_smartypants_attr): in_pre = False else: t = cur_token[1] - last_char = t[-1:] # Remember last char of this token before processing. + last_char = t[-1:] # Remember last char of this token before processing. if not in_pre: t = processEscapes(t) @@ -607,12 +615,12 @@ def educateQuotes(str): # meaningful # Special case for Quotes at end of line with a preceeding space (may change just to end of line) - #str = re.sub(r"""(?<=\s)"$""", r"""”""", str) - #str = re.sub(r"""(?<=\s)'$""", r"""’""", str) + # str = re.sub(r"""(?<=\s)"$""", r"""”""", str) + # str = re.sub(r"""(?<=\s)'$""", r"""’""", str) # Special case for Quotes at beginning of line with a space - multiparagraph quoted text: - #str = re.sub(r"""^"(?=\s)""", r"""“""", str) - #str = re.sub(r"""^'(?=\s)""", r"""‘""", str) + # str = re.sub(r"""^"(?=\s)""", r"""“""", str) + # str = re.sub(r"""^'(?=\s)""", r"""‘""", str) # Special case for decade abbreviations (the '80s): str = re.sub(r"""\b'(?=\d{2}s)""", r"""’""", str) @@ -724,8 +732,8 @@ 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) + str = re.sub(r"""---""", r"""–""", str) # en (yes, backwards) + str = re.sub(r"""--""", r"""—""", str) # em (yes, backwards) return str @@ -763,7 +771,6 @@ def educateDashesOldSchoolInverted(str): return str - def educateEllipses(str): """ Parameter: String. @@ -790,7 +797,7 @@ def stupefyEntities(str): """ str = re.sub(r"""–""", r"""-""", str) # en-dash - str = re.sub(r"""—""", r"""--""", str) # em-dash + str = re.sub(r"""—""", r"""--""", str) # em-dash str = re.sub(r"""‘""", r"""'""", str) # open single quote str = re.sub(r"""’""", r"""'""", str) # close single quote @@ -798,7 +805,7 @@ def stupefyEntities(str): str = re.sub(r"""“""", r'''"''', str) # open double quote str = re.sub(r"""”""", r'''"''', str) # close double quote - str = re.sub(r"""…""", r"""...""", str)# ellipsis + str = re.sub(r"""…""", r"""...""", str) # ellipsis return str @@ -847,9 +854,9 @@ def _tokenize(str): #depth = 6 #nested_tags = "|".join(['(?:<(?:[^<>]',] * depth) + (')*>)' * depth) - #match = r"""(?: ) | # comments - # (?: <\? .*? \?> ) | # directives - # %s # nested tags """ % (nested_tags,) + # match = r"""(?: ) | # comments + # (?: <\? .*? \?> ) | # directives + # %s # nested tags """ % (nested_tags,) tag_soup = re.compile(r"""([^<]*)(<[^>]*>)""") token_match = tag_soup.search(str) @@ -870,7 +877,6 @@ def _tokenize(str): return tokens - if __name__ == "__main__": import locale @@ -885,7 +891,6 @@ if __name__ == "__main__": print docstring_html - # Unit test output goes out stderr. No worries. import unittest sp = smartyPants @@ -904,17 +909,16 @@ if __name__ == "__main__": def test_skip_tags(self): self.assertEqual( - sp(""""""), - """""") + sp(""""""), # noqa + """""") # noqa self.assertEqual( sp("""

He said "Let's write some code." This code here if True:\n\tprint "Okay" is python code.

"""), - """

He said “Let’s write some code.” This code here if True:\n\tprint "Okay" is python code.

""") + """

He said “Let’s write some code.” This code here if True:\n\tprint "Okay" is python code.

""") # noqa self.assertEqual( sp('''