mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
use b prefix for bytes instead of sphinx.pycompat.b function.
This commit is contained in:
+25
-31
@@ -17,12 +17,6 @@ import cStringIO
|
||||
from optparse import OptionParser
|
||||
from os.path import join, splitext, abspath
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
def b(s):
|
||||
return s.encode('utf-8')
|
||||
else:
|
||||
b = str
|
||||
|
||||
|
||||
checkers = {}
|
||||
|
||||
@@ -37,24 +31,24 @@ def checker(*suffixes, **kwds):
|
||||
|
||||
|
||||
name_mail_re = r'[\w ]+(<.*?>)?'
|
||||
copyright_re = re.compile(b(r'^ :copyright: Copyright 200\d(-20\d\d)? '
|
||||
r'by %s(, %s)*[,.]$' %
|
||||
(name_mail_re, name_mail_re)))
|
||||
license_re = re.compile(b(r" :license: (.*?).\n"))
|
||||
copyright_2_re = re.compile(b(r'^ %s(, %s)*[,.]$' %
|
||||
(name_mail_re, name_mail_re)))
|
||||
coding_re = re.compile(b(r'coding[:=]\s*([-\w.]+)'))
|
||||
not_ix_re = re.compile(b(r'\bnot\s+\S+?\s+i[sn]\s\S+'))
|
||||
is_const_re = re.compile(b(r'if.*?==\s+(None|False|True)\b'))
|
||||
copyright_re = re.compile(br'^ :copyright: Copyright 200\d(-20\d\d)? '
|
||||
br'by %s(, %s)*[,.]$' %
|
||||
(name_mail_re, name_mail_re))
|
||||
license_re = re.compile(br" :license: (.*?).\n")
|
||||
copyright_2_re = re.compile(br'^ %s(, %s)*[,.]$' %
|
||||
(name_mail_re, name_mail_re))
|
||||
coding_re = re.compile(br'coding[:=]\s*([-\w.]+)')
|
||||
not_ix_re = re.compile(br'\bnot\s+\S+?\s+i[sn]\s\S+')
|
||||
is_const_re = re.compile(br'if.*?==\s+(None|False|True)\b')
|
||||
|
||||
misspellings = [b("developement"), b("adress"), # ALLOW-MISSPELLING
|
||||
b("verificate"), b("informations")] # ALLOW-MISSPELLING
|
||||
misspellings = [b"developement", b"adress", # ALLOW-MISSPELLING
|
||||
b"verificate", b"informations"] # ALLOW-MISSPELLING
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
@checker('.py')
|
||||
def check_syntax(fn, lines):
|
||||
try:
|
||||
compile(b('').join(lines), fn, "exec")
|
||||
compile(b''.join(lines), fn, "exec")
|
||||
except SyntaxError as err:
|
||||
yield 0, "not compilable: %s" % err
|
||||
|
||||
@@ -69,7 +63,7 @@ def check_style_and_encoding(fn, lines):
|
||||
co = coding_re.search(line)
|
||||
if co:
|
||||
encoding = co.group(1).decode('ascii')
|
||||
if line.strip().startswith(b('#')):
|
||||
if line.strip().startswith(b'#'):
|
||||
continue
|
||||
#m = not_ix_re.search(line)
|
||||
#if m:
|
||||
@@ -89,7 +83,7 @@ def check_style_and_encoding(fn, lines):
|
||||
def check_fileheader(fn, lines):
|
||||
# line number correction
|
||||
c = 1
|
||||
if lines[0:1] == [b('#!/usr/bin/env python\n')]:
|
||||
if lines[0:1] == [b'#!/usr/bin/env python\n']:
|
||||
lines = lines[1:]
|
||||
c = 2
|
||||
|
||||
@@ -98,38 +92,38 @@ def check_fileheader(fn, lines):
|
||||
for lno, l in enumerate(lines):
|
||||
llist.append(l)
|
||||
if lno == 0:
|
||||
if l == b('# -*- coding: rot13 -*-\n'):
|
||||
if l == b'# -*- coding: rot13 -*-\n':
|
||||
# special-case pony package
|
||||
return
|
||||
elif l != b('# -*- coding: utf-8 -*-\n'):
|
||||
elif l != b'# -*- coding: utf-8 -*-\n':
|
||||
yield 1, "missing coding declaration"
|
||||
elif lno == 1:
|
||||
if l != b('"""\n') and l != b('r"""\n'):
|
||||
if l != b'"""\n' and l != b'r"""\n':
|
||||
yield 2, 'missing docstring begin (""")'
|
||||
else:
|
||||
docopen = True
|
||||
elif docopen:
|
||||
if l == b('"""\n'):
|
||||
if l == b'"""\n':
|
||||
# end of docstring
|
||||
if lno <= 4:
|
||||
yield lno+c, "missing module name in docstring"
|
||||
break
|
||||
|
||||
if l != b("\n") and l[:4] != b(' ') and docopen:
|
||||
if l != b"\n" and l[:4] != b' ' and docopen:
|
||||
yield lno+c, "missing correct docstring indentation"
|
||||
|
||||
if lno == 2:
|
||||
# if not in package, don't check the module name
|
||||
modname = fn[:-3].replace('/', '.').replace('.__init__', '')
|
||||
while modname:
|
||||
if l.lower()[4:-1] == b(modname):
|
||||
if l.lower()[4:-1] == bytes(modname):
|
||||
break
|
||||
modname = '.'.join(modname.split('.')[1:])
|
||||
else:
|
||||
yield 3, "wrong module name in docstring heading"
|
||||
modnamelen = len(l.strip())
|
||||
elif lno == 3:
|
||||
if l.strip() != modnamelen * b("~"):
|
||||
if l.strip() != modnamelen * b"~":
|
||||
yield 4, "wrong module name underline, should be ~~~...~"
|
||||
|
||||
else:
|
||||
@@ -152,16 +146,16 @@ def check_fileheader(fn, lines):
|
||||
@checker('.py', '.html', '.rst')
|
||||
def check_whitespace_and_spelling(fn, lines):
|
||||
for lno, line in enumerate(lines):
|
||||
if b("\t") in line:
|
||||
if b"\t" in line:
|
||||
yield lno+1, "OMG TABS!!!1 "
|
||||
if line[:-1].rstrip(b(' \t')) != line[:-1]:
|
||||
if line[:-1].rstrip(b' \t') != line[:-1]:
|
||||
yield lno+1, "trailing whitespace"
|
||||
for word in misspellings:
|
||||
if word in line and b('ALLOW-MISSPELLING') not in line:
|
||||
if word in line and b'ALLOW-MISSPELLING' not in line:
|
||||
yield lno+1, '"%s" used' % word
|
||||
|
||||
|
||||
bad_tags = map(b, ['<u>', '<s>', '<strike>', '<center>', '<font'])
|
||||
bad_tags = [b'<u>', b'<s>', b'<strike>', b'<center>', b'<font']
|
||||
|
||||
@checker('.html')
|
||||
def check_xhtml(fn, lines):
|
||||
|
||||
Reference in New Issue
Block a user