diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-03-04 15:54:22 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-03-04 15:54:22 +0000 |
| commit | 703d5ddbc3b7a805e82b4b80d01c8964a50d8a0a (patch) | |
| tree | 6460ac86985f2312227b3c4ca396c3f2ee6652e9 /docutils/utils | |
| parent | 62974fa0f4a5ddc02be8df015511c90dcb00f5e2 (diff) | |
| download | docutils-703d5ddbc3b7a805e82b4b80d01c8964a50d8a0a.tar.gz | |
Ensure at least two spaces before inline comment.
flake 8 rule E261
Exceptions for modules sheduled for removal or with
3rd-party origin and for data collections.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@9021 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/utils')
| -rw-r--r-- | docutils/utils/__init__.py | 9 | ||||
| -rw-r--r-- | docutils/utils/code_analyzer.py | 10 | ||||
| -rw-r--r-- | docutils/utils/math/latex2mathml.py | 2 | ||||
| -rw-r--r-- | docutils/utils/math/tex2mathml_extern.py | 10 | ||||
| -rw-r--r-- | docutils/utils/punctuation_chars.py | 21 | ||||
| -rw-r--r-- | docutils/utils/smartquotes.py | 107 |
6 files changed, 79 insertions, 80 deletions
diff --git a/docutils/utils/__init__.py b/docutils/utils/__init__.py index 53695406f..37d89929e 100644 --- a/docutils/utils/__init__.py +++ b/docutils/utils/__init__.py @@ -168,8 +168,9 @@ class Reporter: if line is not None: attributes.setdefault('line', line) # assert source is not None, "node has line- but no source-argument" - if 'source' not in attributes: # 'line' is absolute line number - try: # look up (source, line-in-source) + if 'source' not in attributes: + # 'line' is absolute line number + try: source, line = self.get_source_and_line(attributes.get('line')) except AttributeError: source, line = None, None @@ -345,7 +346,7 @@ def decode_path(path): return path try: path = path.decode(sys.getfilesystemencoding(), 'strict') - except AttributeError: # default value None has no decode method + except AttributeError: # default value None has no decode method if not path: return '' raise ValueError('`path` value must be a String or ``None``, ' @@ -525,7 +526,7 @@ def get_stylesheet_list(settings): # expand relative paths if found in stylesheet-dirs: stylesheets = [find_file_in_dirs(path, settings.stylesheet_dirs) for path in stylesheets] - if os.sep != '/': # for URLs, we need POSIX paths + if os.sep != '/': # for URLs, we need POSIX paths stylesheets = [path.replace(os.sep, '/') for path in stylesheets] return stylesheets diff --git a/docutils/utils/code_analyzer.py b/docutils/utils/code_analyzer.py index 5edc8736f..f0ecc9b71 100644 --- a/docutils/utils/code_analyzer.py +++ b/docutils/utils/code_analyzer.py @@ -16,9 +16,9 @@ except ImportError: with_pygments = False # Filter the following token types from the list of class arguments: -unstyled_tokens = ['token', # Token (base token type) - 'text', # Token.Text - ''] # short name for Token and Text +unstyled_tokens = ['token', # Token (base token type) + 'text', # Token.Text + ''] # short name for Token and Text # (Add, e.g., Token.Punctuation with ``unstyled_tokens += 'punctuation'``.) class LexerError(ApplicationError): @@ -97,9 +97,9 @@ class Lexer: return tokens = pygments.lex(self.code, self.lexer) for tokentype, value in self.merge(tokens): - if self.tokennames == 'long': # long CSS class args + if self.tokennames == 'long': # long CSS class args classes = str(tokentype).lower().split('.') - else: # short CSS class args + else: # short CSS class args classes = [_get_ttype_class(tokentype)] classes = [cls for cls in classes if cls not in unstyled_tokens] yield classes, value diff --git a/docutils/utils/math/latex2mathml.py b/docutils/utils/math/latex2mathml.py index 8df9d30b2..2dc95b8fc 100644 --- a/docutils/utils/math/latex2mathml.py +++ b/docutils/utils/math/latex2mathml.py @@ -39,7 +39,7 @@ from docutils.utils.math import tex2unichar, toplevel_code # identifiers -> <mi> letters = tex2unichar.mathalpha -letters['hbar'] = '\u210F' # compatibility mapping to ℏ (\hslash). +letters['hbar'] = '\u210F' # compatibility mapping to ℏ (\hslash). # (ħ LATIN SMALL LETTER H WITH STROKE is upright) # special case: Capital Greek letters: (upright in TeX style) diff --git a/docutils/utils/math/tex2mathml_extern.py b/docutils/utils/math/tex2mathml_extern.py index 6aa46133b..03b336805 100644 --- a/docutils/utils/math/tex2mathml_extern.py +++ b/docutils/utils/math/tex2mathml_extern.py @@ -31,7 +31,7 @@ def latexml(math_code, reporter=None): .. _LaTeXML: http://dlmf.nist.gov/LaTeXML/ """ p = subprocess.Popen(['latexml', - '-', # read from stdin + '-', # read from stdin # '--preload=amsmath', '--inputencoding=utf8', ], @@ -50,7 +50,7 @@ def latexml(math_code, reporter=None): '-', '--nonumbersections', '--format=xhtml', - # '--linelength=78', # experimental + # '--linelength=78', # experimental '--' ], stdin=subprocess.PIPE, @@ -77,9 +77,9 @@ def ttm(math_code, reporter=None): .. _TtM: http://hutchinson.belmont.ma.us/tth/mml/ """ p = subprocess.Popen(['ttm', - # '-i', # italic font for equations. Default roman. - '-', # unicode character encoding. (Default iso-8859-1). - '-r', # output raw MathML (no preamble or postlude) + # '-i', # italic font for equations. Default roman. + '-u', # unicode encoding. (Default iso-8859-1). + '-r', # output raw MathML (no wrapper) ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, diff --git a/docutils/utils/punctuation_chars.py b/docutils/utils/punctuation_chars.py index b3617fe55..99ab36f14 100644 --- a/docutils/utils/punctuation_chars.py +++ b/docutils/utils/punctuation_chars.py @@ -82,7 +82,7 @@ delimiters = (u'\\-/:\u058a\xa1\xb7\xbf\u037e\u0387\u055a-\u055f\u0589' u'\ufe50-\ufe52\ufe54-\ufe58\ufe5f-\ufe61\ufe63\ufe68\ufe6a' u'\ufe6b\uff01-\uff03\uff05-\uff07\uff0a\uff0c-\uff0f\uff1a' u'\uff1b\uff1f\uff20\uff3c\uff61\uff64\uff65') -if sys.maxunicode >= 0x10FFFF: # "wide" build +if sys.maxunicode >= 0x10FFFF: # "wide" build delimiters += (u'\U00010100\U00010101\U0001039f\U000103d0\U00010857' u'\U0001091f\U0001093f\U00010a50-\U00010a58\U00010a7f' u'\U00010b39-\U00010b3f\U000110bb\U000110bc\U000110be-' @@ -93,15 +93,16 @@ closing_delimiters = u'\\\\.,;!?' # Matching open/close quotes # -------------------------- -quote_pairs = {# open char: matching closing characters # usage example - u'\xbb': u'\xbb', # » » Swedish - u'\u2018': u'\u201a', # ‘ ‚ Albanian/Greek/Turkish - u'\u2019': u'\u2019', # ’ ’ Swedish - u'\u201a': u'\u2018\u2019', # ‚ ‘ German ‚ ’ Polish - u'\u201c': u'\u201e', # “ „ Albanian/Greek/Turkish - u'\u201e': u'\u201c\u201d', # „ “ German „ ” Polish - u'\u201d': u'\u201d', # ” ” Swedish - u'\u203a': u'\u203a', # › › Swedish +quote_pairs = { + # open char: matching closing characters # usage example + u'\xbb': u'\xbb', # » » Swedish + u'\u2018': u'\u201a', # ‘ ‚ Albanian/Greek/Turkish + u'\u2019': u'\u2019', # ’ ’ Swedish + u'\u201a': u'\u2018\u2019', # ‚ ‘ German ‚ ’ Polish + u'\u201c': u'\u201e', # “ „ Albanian/Greek/Turkish + u'\u201e': u'\u201c\u201d', # „ “ German „ ” Polish + u'\u201d': u'\u201d', # ” ” Swedish + u'\u203a': u'\u203a', # › › Swedish } """Additional open/close quote pairs.""" diff --git a/docutils/utils/smartquotes.py b/docutils/utils/smartquotes.py index a5b127e20..66d9f9a7e 100644 --- a/docutils/utils/smartquotes.py +++ b/docutils/utils/smartquotes.py @@ -387,10 +387,10 @@ import re, sys class smartchars: """Smart quotes and dashes""" - endash = '–' # "–" EN DASH - emdash = '—' # "—" EM DASH - ellipsis = '…' # "…" HORIZONTAL ELLIPSIS - apostrophe = '’' # "’" RIGHT SINGLE QUOTATION MARK + endash = '–' # "–" EN DASH + emdash = '—' # "—" EM DASH + ellipsis = '…' # "…" HORIZONTAL ELLIPSIS + apostrophe = '’' # "’" RIGHT SINGLE QUOTATION MARK # quote characters (language-specific, set in __init__()) # [1] https://en.wikipedia.org/wiki/Non-English_usage_of_quotation_marks @@ -407,7 +407,7 @@ class smartchars: # See also configuration option "smartquote-locales". quotes = {'af': '“”‘’', 'af-x-altquot': '„”‚’', - 'bg': '„“‚‘', # Bulgarian, https://bg.wikipedia.org/wiki/Кавички + 'bg': '„“‚‘', # https://bg.wikipedia.org/wiki/Кавички 'ca': '«»“”', 'ca-x-altquot': '“”‘’', 'cs': '„“‚‘', @@ -420,24 +420,24 @@ class smartchars: 'de-ch': '«»‹›', 'el': '«»“”', 'en': '“”‘’', - 'en-uk-x-altquot': '‘’“”', # Attention: " → ‘ and ' → “ ! + 'en-uk-x-altquot': '‘’“”', # Attention: " → ‘ and ' → “ ! 'eo': '“”‘’', 'es': '«»“”', 'es-x-altquot': '“”‘’', - 'et': '„“‚‘', # no secondary quote listed in - 'et-x-altquot': '«»‹›', # the sources above (wikipedia.org) + 'et': '„“‚‘', # no secondary quote listed in + 'et-x-altquot': '«»‹›', # the sources above (wikipedia.org) 'eu': '«»‹›', 'fi': '””’’', 'fi-x-altquot': '»»››', - 'fr': ('« ', ' »', '“', '”'), # full no-break space - 'fr-x-altquot': ('« ', ' »', '“', '”'), # narrow no-break space - 'fr-ch': '«»‹›', - 'fr-ch-x-altquot': ('« ', ' »', '‹ ', ' ›'), # narrow no-break space, http://typoguide.ch/ + 'fr': ('« ', ' »', '“', '”'), # full no-break space + 'fr-x-altquot': ('« ', ' »', '“', '”'), # narrow no-break space + 'fr-ch': '«»‹›', # http://typoguide.ch/ + 'fr-ch-x-altquot': ('« ', ' »', '‹ ', ' ›'), # narrow no-break space 'gl': '«»“”', - 'he': '”“»«', # Hebrew is RTL, test position: - 'he-x-altquot': '„”‚’', # low quotation marks are opening. - # 'he-x-altquot': '“„‘‚', # RTL: low quotation marks opening - 'hr': '„”‘’', # http://hrvatska-tipografija.com/polunavodnici/ + 'he': '”“»«', # Hebrew is RTL, test position: + 'he-x-altquot': '„”‚’', # low quotation marks are opening. + # 'he-x-altquot': '“„‘‚', # RTL: low quotation marks opening + 'hr': '„”‘’', # http://hrvatska-tipografija.com/polunavodnici/ 'hr-x-altquot': '»«›‹', 'hsb': '„“‚‘', 'hsb-x-altquot': '»«›‹', @@ -446,38 +446,38 @@ class smartchars: 'it': '«»“”', 'it-ch': '«»‹›', 'it-x-altquot': '“”‘’', - # 'it-x-altquot2': '“„‘‚', # [7] in headlines + # 'it-x-altquot2': '“„‘‚', # [7] in headlines 'ja': '「」『』', 'ko': '“”‘’', 'lt': '„“‚‘', 'lv': '„“‚‘', - 'mk': '„“‚‘', # Macedonian, https://mk.wikipedia.org/wiki/Правопис_и_правоговор_на_македонскиот_јазик + 'mk': '„“‚‘', # Macedonian, https://mk.wikipedia.org/wiki/Правопис_и_правоговор_на_македонскиот_јазик 'nl': '“”‘’', 'nl-x-altquot': '„”‚’', # 'nl-x-altquot2': '””’’', - 'nb': '«»’’', # Norsk bokmål (canonical form 'no') - 'nn': '«»’’', # Nynorsk [10] - 'nn-x-altquot': '«»‘’', # [8], [10] - # 'nn-x-altquot2': '«»«»', # [9], [10 - # 'nn-x-altquot3': '„“‚‘', # [10] - 'no': '«»’’', # Norsk bokmål [10] - 'no-x-altquot': '«»‘’', # [8], [10] - # 'no-x-altquot2': '«»«»', # [9], [10 - # 'no-x-altquot3': '„“‚‘', # [10] + 'nb': '«»’’', # Norsk bokmål (canonical form 'no') + 'nn': '«»’’', # Nynorsk [10] + 'nn-x-altquot': '«»‘’', # [8], [10] + # 'nn-x-altquot2': '«»«»', # [9], [10 + # 'nn-x-altquot3': '„“‚‘', # [10] + 'no': '«»’’', # Norsk bokmål [10] + 'no-x-altquot': '«»‘’', # [8], [10] + # 'no-x-altquot2': '«»«»', # [9], [10 + # 'no-x-altquot3': '„“‚‘', # [10] 'pl': '„”«»', 'pl-x-altquot': '«»‚’', - # 'pl-x-altquot2': '„”‚’', # https://pl.wikipedia.org/wiki/Cudzys%C5%82%C3%B3w + # 'pl-x-altquot2': '„”‚’', # https://pl.wikipedia.org/wiki/Cudzys%C5%82%C3%B3w 'pt': '«»“”', 'pt-br': '“”‘’', 'ro': '„”«»', 'ru': '«»„“', - 'sh': '„”‚’', # Serbo-Croatian + 'sh': '„”‚’', # Serbo-Croatian 'sh-x-altquot': '»«›‹', - 'sk': '„“‚‘', # Slovak + 'sk': '„“‚‘', # Slovak 'sk-x-altquot': '»«›‹', - 'sl': '„“‚‘', # Slovenian + 'sl': '„“‚‘', # Slovenian 'sl-x-altquot': '»«›‹', - 'sq': '«»‹›', # Albanian + 'sq': '«»‹›', # Albanian 'sq-x-altquot': '“„‘‚', 'sr': '„”’’', 'sr-x-altquot': '»«›‹', @@ -485,7 +485,7 @@ class smartchars: 'sv-x-altquot': '»»››', 'tr': '“”‘’', 'tr-x-altquot': '«»‹›', - # 'tr-x-altquot2': '“„‘‚', # [7] antiquated? + # 'tr-x-altquot2': '“„‘‚', # [7] antiquated? 'uk': '«»„“', 'uk-x-altquot': '„“‚‘', 'zh-cn': '“”‘’', @@ -532,8 +532,8 @@ def educate_tokens(text_tokens, attr=default_smartypants_attr, language='en'): do_ellipses = False do_stupefy = False - # if attr == "0": # pass tokens unchanged (see below). - if attr == "1": # Do everything, turn all options on. + # if attr == "0": # pass tokens unchanged (see below). + if attr == "1": # Do everything, turn all options on. do_quotes = True do_backticks = True do_dashes = 1 @@ -550,7 +550,7 @@ def educate_tokens(text_tokens, attr=default_smartypants_attr, language='en'): do_backticks = True do_dashes = 3 do_ellipses = True - elif attr == "-1": # Special "stupefy" mode. + elif attr == "-1": # Special "stupefy" mode. do_stupefy = True else: if "q" in attr: do_quotes = True @@ -580,7 +580,7 @@ def educate_tokens(text_tokens, attr=default_smartypants_attr, language='en'): yield text continue - last_char = text[-1:] # Remember last char before processing. + last_char = text[-1:] # Remember last char before processing. text = processEscapes(text) @@ -633,12 +633,12 @@ def educateQuotes(text, language='en'): """ smart = smartchars(language) - ch_classes = {'open': '[([{]', # opening braces - 'close': r'[^\s]', # everything except whitespace - 'punct': r"""[-!"#\$\%'()*+,.\/:;<=>?\@\[\\\]\^_`{|}~]""", - 'dash': '[-–—]' # hyphen and em/en dashes - + r'|&[mn]dash;|&\#8211;|&\#8212;|&\#x201[34];', - 'sep': '[\\s\u200B\u200C]| ', # Whitespace, ZWSP, ZWNJ + ch_classes = {'open': '[([{]', # opening braces + 'close': r'[^\s]', # everything except whitespace + 'punct': r"""[-!" #\$\%'()*+,.\/:;<=>?\@\[\\\]\^_`{|}~]""", + 'dash': '[-–—]' # hyphen and em/en dashes + r'|&[mn]dash;|&\#8211;|&\#8212;|&\#x201[34];', + 'sep': '[\\s\u200B\u200C]| ', # Whitespace, ZWSP, ZWNJ } # Special case if the very first character is a quote @@ -660,7 +660,7 @@ def educateQuotes(text, language='en'): r'\1%s'%smart.cpquote, text) # Special case for decade abbreviations (the '80s): - if language.startswith('en'): # TODO similar cases in other languages? + if language.startswith('en'): # TODO similar cases in other languages? text = re.sub(r"'(?=\d{2}s)", smart.apostrophe, text) # Get most opening secondary quotes: @@ -670,8 +670,8 @@ def educateQuotes(text, language='en'): %(open)s | # opening brace, or %(dash)s # em/en-dash ) - ' # the quote - (?=\\w|%(punct)s) # followed by a word character or punctuation + ' # the quote + (?=\\w|%(punct)s) # word character or punctuation """ % ch_classes, re.VERBOSE) text = opening_secondary_quotes_regex.sub(r'\1'+smart.osquote, text) @@ -755,8 +755,8 @@ def educateDashes(text): an em-dash character. """ - text = text.replace(r'---', smartchars.endash) # en (yes, backwards) - text = text.replace(r'--', smartchars.emdash) # em (yes, backwards) + text = text.replace(r'---', smartchars.endash) # en (yes, backwards) + text = text.replace(r'--', smartchars.emdash) # em (yes, backwards) return text @@ -819,16 +819,13 @@ def stupefyEntities(text, language='en'): """ smart = smartchars(language) - text = text.replace(smart.endash, "-") # en-dash - text = text.replace(smart.emdash, "--") # em-dash - + text = text.replace(smart.endash, "-") + text = text.replace(smart.emdash, "--") text = text.replace(smart.osquote, "'") # open secondary quote text = text.replace(smart.csquote, "'") # close secondary quote - text = text.replace(smart.opquote, '"') # open primary quote text = text.replace(smart.cpquote, '"') # close primary quote - - text = text.replace(smart.ellipsis, '...') # ellipsis + text = text.replace(smart.ellipsis, '...') return text @@ -898,7 +895,7 @@ if __name__ == "__main__": import itertools import locale try: - locale.setlocale(locale.LC_ALL, '') # set to user defaults + locale.setlocale(locale.LC_ALL, '') # set to user defaults defaultlanguage = locale.getdefaultlocale()[0] except: defaultlanguage = 'en' |
