pyupgrade related fixes to python scripts #2.

Patch from Jose.
https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg217790.html
This commit is contained in:
Pavel Sanda 2022-07-31 20:08:44 +02:00
parent 4c72d8aeac
commit 79f321d0f5
8 changed files with 12 additions and 13 deletions

View File

@ -78,7 +78,7 @@ else:
# with tetex.
epsfile = outbase + '.pstex'
tmp = mkstemp()
boundingboxline = re.compile(b'%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
boundingboxline = re.compile(br'%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
for line in open(epsfile, 'rb'):
if line[:13] == b'%%BoundingBox':
(llx, lly, urx, ury) = list(map(int, boundingboxline.search(line).groups()))

View File

@ -457,10 +457,10 @@ def convert(lines, end_format):
re_ChapterStyle = re.compile(b'^\\s*Style\\s+Chapter\\s*$', re.IGNORECASE)
re_InsetLayout_CaptionLTNN = re.compile(b'^(\\s*InsetLayout\\s+)(Caption:LongTableNonumber)', re.IGNORECASE)
# for format 64
re_trimLabelString = re.compile(b'^(\\s*LabelString\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimLabelStringAppendix = re.compile(b'^(\\s*LabelStringAppendix\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimLabelCounter = re.compile(b'^(\\s*LabelCounter\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimLabelString = re.compile(b'^(\\s*LabelString\\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimLabelStringAppendix = re.compile(b'^(\\s*LabelStringAppendix\\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimLabelCounter = re.compile(b'^(\\s*LabelCounter\\s+)"\\s*(.*?)\\s*"\\s*$')
# counters for sectioning styles (hardcoded in 1.3)

View File

@ -156,7 +156,7 @@ def legacy_extract_metrics_info(log_file):
def extract_resolution(log_file, dpi):
fontsize_re = re.compile(b"Preview: Fontsize")
magnification_re = re.compile(b"Preview: Magnification")
extract_decimal_re = re.compile(b"([0-9\.]+)")
extract_decimal_re = re.compile(br"([0-9\.]+)")
extract_integer_re = re.compile(b"([0-9]+)")
found_fontsize = 0

View File

@ -37,7 +37,7 @@ if running_on_windows:
from tempfile import NamedTemporaryFile
# Pre-compiled regular expressions.
re_lyxfile = re.compile(b"\.lyx$")
re_lyxfile = re.compile(br"\.lyx$")
re_input = re.compile(b'^(.*)\\\\(input|include){(\\s*)(.+)(\\s*)}.*$')
re_ertinput = re.compile(b'^(input|include)({)(\\s*)(.+)(\\s*)}.*$')
re_package = re.compile(b'^(.*)\\\\(usepackage){(\\s*)(.+)(\\s*)}.*$')

View File

@ -78,7 +78,7 @@ def find(args, path):
# use locate if possible (faster)
if find_exe(['locate']):
p1 = subprocess.Popen(['locate', '-i', args[0].lower()], stdout=subprocess.PIPE)
px = subprocess.Popen(['grep', '-Ei', '\.pdf$|\.ps$'], stdin=p1.stdout, stdout=subprocess.PIPE)
px = subprocess.Popen(['grep', '-Ei', r'\.pdf$|\.ps$'], stdin=p1.stdout, stdout=subprocess.PIPE)
for arg in args:
if arg == args[0]:
# have this already

View File

@ -120,7 +120,7 @@ def extract_metrics_info(dvipng_stdout):
# "\[[0-9]+" can match two kinds of numbers: page numbers from dvipng
# and glyph numbers from mktexpk. The glyph numbers always match
# "\[[0-9]+\]" while the page number never is followed by "\]". Thus:
page_re = re.compile("\[([0-9]+)[^]]");
page_re = re.compile(r"\[([0-9]+)[^]]");
metrics_re = re.compile("depth=(-?[0-9]+) height=(-?[0-9]+)")
success = 0
@ -197,7 +197,7 @@ def fix_latex_file(latex_file, pdf_output):
def convert_to_ppm_format(pngtopnm, basename):
png_file_re = re.compile("\.png$")
png_file_re = re.compile(r"\.png$")
for png_file in glob.glob("%s*.png" % basename):
ppm_file = png_file_re.sub(".ppm", png_file)

View File

@ -1,4 +1,3 @@
# file lyxpreview_tools.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.

View File

@ -223,7 +223,7 @@ def remove_obsolete(line):
def language_use_babel(line):
if not line.lower().startswith("\language_use_babel"):
if not line.lower().startswith(r"\language_use_babel"):
return no_match
re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
m = re_lub.match(line)
@ -364,7 +364,7 @@ def split_pdf_format(line):
viewer = ''
else:
viewer = entries[5]
converted = line.replace('application/pdf', '') + '''
converted = line.replace('application/pdf', '') + r'''
\Format pdf6 pdf "PDF (graphics)" "" "''' + viewer + '" "" "vector" "application/pdf"'
return (True, converted)
elif line.lower().startswith("\\viewer_alternatives") or \