Merge pull request from radarhere/black

This commit is contained in:
Hugo van Kemenade 2022-03-04 14:23:53 +02:00 committed by GitHub
commit 38f4660d9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 98 additions and 98 deletions

View File

@ -1,6 +1,6 @@
repos: repos:
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: f1d4e742c91dd5179d742b0db9293c4472b765f8 # frozen: 21.12b0 rev: fc0be6eb1e2a96091e6f64009ee5e9081bf8b6c6 # frozen: 22.1.0
hooks: hooks:
- id: black - id: black
args: ["--target-version", "py37"] args: ["--target-version", "py37"]
@ -19,7 +19,7 @@ repos:
- id: yesqa - id: yesqa
- repo: https://github.com/Lucas-C/pre-commit-hooks - repo: https://github.com/Lucas-C/pre-commit-hooks
rev: 3592548bbd98528887eeed63486cf6c9bae00b98 # frozen: v1.1.10 rev: ca52c4245639abd55c970e6bbbca95cab3de22d8 # frozen: v1.1.13
hooks: hooks:
- id: remove-tabs - id: remove-tabs
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.opt$) exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.opt$)

View File

@ -115,6 +115,6 @@ def test_pdf_repr():
assert pdf_repr(True) == b"true" assert pdf_repr(True) == b"true"
assert pdf_repr(False) == b"false" assert pdf_repr(False) == b"false"
assert pdf_repr(None) == b"null" assert pdf_repr(None) == b"null"
assert pdf_repr(b"a)/b\\(c") == br"(a\)/b\\\(c)" assert pdf_repr(b"a)/b\\(c") == rb"(a\)/b\\\(c)"
assert pdf_repr([123, True, {"a": PdfName(b"b")}]) == b"[ 123 true <<\n/a /b\n>> ]" assert pdf_repr([123, True, {"a": PdfName(b"b")}]) == b"[ 123 true <<\n/a /b\n>> ]"
assert pdf_repr(PdfBinary(b"\x90\x1F\xA0")) == b"<901FA0>" assert pdf_repr(PdfBinary(b"\x90\x1F\xA0")) == b"<901FA0>"

View File

@ -167,7 +167,7 @@ def _find_library_dirs_ldconfig():
# Assuming GLIBC's ldconfig (with option -p) # Assuming GLIBC's ldconfig (with option -p)
# Alpine Linux uses musl that can't print cache # Alpine Linux uses musl that can't print cache
args = ["/sbin/ldconfig", "-p"] args = ["/sbin/ldconfig", "-p"]
expr = fr".*\({abi_type}.*\) => (.*)" expr = rf".*\({abi_type}.*\) => (.*)"
env = dict(os.environ) env = dict(os.environ)
env["LC_ALL"] = "C" env["LC_ALL"] = "C"
env["LANG"] = "C" env["LANG"] = "C"

View File

@ -38,7 +38,7 @@ class GimpPaletteFile:
break break
# skip fields and comment lines # skip fields and comment lines
if re.match(br"\w+:|#", s): if re.match(rb"\w+:|#", s):
continue continue
if len(s) > 100: if len(s) > 100:
raise SyntaxError("bad palette file") raise SyntaxError("bad palette file")

View File

@ -100,7 +100,7 @@ for i in range(2, 33):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Read IM directory # Read IM directory
split = re.compile(br"^([A-Za-z][^:]*):[ \t]*(.*)[ \t]*$") split = re.compile(rb"^([A-Za-z][^:]*):[ \t]*(.*)[ \t]*$")
def number(s): def number(s):

View File

@ -22,7 +22,7 @@ from . import Image, ImageFile
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
field = re.compile(br"([a-z]*) ([^ \r\n]*)") field = re.compile(rb"([a-z]*) ([^ \r\n]*)")
## ##

View File

@ -576,42 +576,42 @@ class PdfParser:
self.xref_table[reference.object_id] = (offset, 0) self.xref_table[reference.object_id] = (offset, 0)
return reference return reference
delimiter = br"[][()<>{}/%]" delimiter = rb"[][()<>{}/%]"
delimiter_or_ws = br"[][()<>{}/%\000\011\012\014\015\040]" delimiter_or_ws = rb"[][()<>{}/%\000\011\012\014\015\040]"
whitespace = br"[\000\011\012\014\015\040]" whitespace = rb"[\000\011\012\014\015\040]"
whitespace_or_hex = br"[\000\011\012\014\015\0400-9a-fA-F]" whitespace_or_hex = rb"[\000\011\012\014\015\0400-9a-fA-F]"
whitespace_optional = whitespace + b"*" whitespace_optional = whitespace + b"*"
whitespace_mandatory = whitespace + b"+" whitespace_mandatory = whitespace + b"+"
# No "\012" aka "\n" or "\015" aka "\r": # No "\012" aka "\n" or "\015" aka "\r":
whitespace_optional_no_nl = br"[\000\011\014\040]*" whitespace_optional_no_nl = rb"[\000\011\014\040]*"
newline_only = br"[\r\n]+" newline_only = rb"[\r\n]+"
newline = whitespace_optional_no_nl + newline_only + whitespace_optional_no_nl newline = whitespace_optional_no_nl + newline_only + whitespace_optional_no_nl
re_trailer_end = re.compile( re_trailer_end = re.compile(
whitespace_mandatory whitespace_mandatory
+ br"trailer" + rb"trailer"
+ whitespace_optional + whitespace_optional
+ br"\<\<(.*\>\>)" + rb"\<\<(.*\>\>)"
+ newline + newline
+ br"startxref" + rb"startxref"
+ newline + newline
+ br"([0-9]+)" + rb"([0-9]+)"
+ newline + newline
+ br"%%EOF" + rb"%%EOF"
+ whitespace_optional + whitespace_optional
+ br"$", + rb"$",
re.DOTALL, re.DOTALL,
) )
re_trailer_prev = re.compile( re_trailer_prev = re.compile(
whitespace_optional whitespace_optional
+ br"trailer" + rb"trailer"
+ whitespace_optional + whitespace_optional
+ br"\<\<(.*?\>\>)" + rb"\<\<(.*?\>\>)"
+ newline + newline
+ br"startxref" + rb"startxref"
+ newline + newline
+ br"([0-9]+)" + rb"([0-9]+)"
+ newline + newline
+ br"%%EOF" + rb"%%EOF"
+ whitespace_optional, + whitespace_optional,
re.DOTALL, re.DOTALL,
) )
@ -655,12 +655,12 @@ class PdfParser:
re_whitespace_optional = re.compile(whitespace_optional) re_whitespace_optional = re.compile(whitespace_optional)
re_name = re.compile( re_name = re.compile(
whitespace_optional whitespace_optional
+ br"/([!-$&'*-.0-;=?-Z\\^-z|~]+)(?=" + rb"/([!-$&'*-.0-;=?-Z\\^-z|~]+)(?="
+ delimiter_or_ws + delimiter_or_ws
+ br")" + rb")"
) )
re_dict_start = re.compile(whitespace_optional + br"\<\<") re_dict_start = re.compile(whitespace_optional + rb"\<\<")
re_dict_end = re.compile(whitespace_optional + br"\>\>" + whitespace_optional) re_dict_end = re.compile(whitespace_optional + rb"\>\>" + whitespace_optional)
@classmethod @classmethod
def interpret_trailer(cls, trailer_data): def interpret_trailer(cls, trailer_data):
@ -689,7 +689,7 @@ class PdfParser:
) )
return trailer return trailer
re_hashes_in_name = re.compile(br"([^#]*)(#([0-9a-fA-F]{2}))?") re_hashes_in_name = re.compile(rb"([^#]*)(#([0-9a-fA-F]{2}))?")
@classmethod @classmethod
def interpret_name(cls, raw, as_text=False): def interpret_name(cls, raw, as_text=False):
@ -704,53 +704,53 @@ class PdfParser:
else: else:
return bytes(name) return bytes(name)
re_null = re.compile(whitespace_optional + br"null(?=" + delimiter_or_ws + br")") re_null = re.compile(whitespace_optional + rb"null(?=" + delimiter_or_ws + rb")")
re_true = re.compile(whitespace_optional + br"true(?=" + delimiter_or_ws + br")") re_true = re.compile(whitespace_optional + rb"true(?=" + delimiter_or_ws + rb")")
re_false = re.compile(whitespace_optional + br"false(?=" + delimiter_or_ws + br")") re_false = re.compile(whitespace_optional + rb"false(?=" + delimiter_or_ws + rb")")
re_int = re.compile( re_int = re.compile(
whitespace_optional + br"([-+]?[0-9]+)(?=" + delimiter_or_ws + br")" whitespace_optional + rb"([-+]?[0-9]+)(?=" + delimiter_or_ws + rb")"
) )
re_real = re.compile( re_real = re.compile(
whitespace_optional whitespace_optional
+ br"([-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+))(?=" + rb"([-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+))(?="
+ delimiter_or_ws + delimiter_or_ws
+ br")" + rb")"
) )
re_array_start = re.compile(whitespace_optional + br"\[") re_array_start = re.compile(whitespace_optional + rb"\[")
re_array_end = re.compile(whitespace_optional + br"]") re_array_end = re.compile(whitespace_optional + rb"]")
re_string_hex = re.compile( re_string_hex = re.compile(
whitespace_optional + br"\<(" + whitespace_or_hex + br"*)\>" whitespace_optional + rb"\<(" + whitespace_or_hex + rb"*)\>"
) )
re_string_lit = re.compile(whitespace_optional + br"\(") re_string_lit = re.compile(whitespace_optional + rb"\(")
re_indirect_reference = re.compile( re_indirect_reference = re.compile(
whitespace_optional whitespace_optional
+ br"([-+]?[0-9]+)" + rb"([-+]?[0-9]+)"
+ whitespace_mandatory + whitespace_mandatory
+ br"([-+]?[0-9]+)" + rb"([-+]?[0-9]+)"
+ whitespace_mandatory + whitespace_mandatory
+ br"R(?=" + rb"R(?="
+ delimiter_or_ws + delimiter_or_ws
+ br")" + rb")"
) )
re_indirect_def_start = re.compile( re_indirect_def_start = re.compile(
whitespace_optional whitespace_optional
+ br"([-+]?[0-9]+)" + rb"([-+]?[0-9]+)"
+ whitespace_mandatory + whitespace_mandatory
+ br"([-+]?[0-9]+)" + rb"([-+]?[0-9]+)"
+ whitespace_mandatory + whitespace_mandatory
+ br"obj(?=" + rb"obj(?="
+ delimiter_or_ws + delimiter_or_ws
+ br")" + rb")"
) )
re_indirect_def_end = re.compile( re_indirect_def_end = re.compile(
whitespace_optional + br"endobj(?=" + delimiter_or_ws + br")" whitespace_optional + rb"endobj(?=" + delimiter_or_ws + rb")"
) )
re_comment = re.compile( re_comment = re.compile(
br"(" + whitespace_optional + br"%[^\r\n]*" + newline + br")*" rb"(" + whitespace_optional + rb"%[^\r\n]*" + newline + rb")*"
) )
re_stream_start = re.compile(whitespace_optional + br"stream\r?\n") re_stream_start = re.compile(whitespace_optional + rb"stream\r?\n")
re_stream_end = re.compile( re_stream_end = re.compile(
whitespace_optional + br"endstream(?=" + delimiter_or_ws + br")" whitespace_optional + rb"endstream(?=" + delimiter_or_ws + rb")"
) )
@classmethod @classmethod
@ -876,7 +876,7 @@ class PdfParser:
raise PdfFormatError("unrecognized object: " + repr(data[offset : offset + 32])) raise PdfFormatError("unrecognized object: " + repr(data[offset : offset + 32]))
re_lit_str_token = re.compile( re_lit_str_token = re.compile(
br"(\\[nrtbf()\\])|(\\[0-9]{1,3})|(\\(\r\n|\r|\n))|(\r\n|\r|\n)|(\()|(\))" rb"(\\[nrtbf()\\])|(\\[0-9]{1,3})|(\\(\r\n|\r|\n))|(\r\n|\r|\n)|(\()|(\))"
) )
escaped_chars = { escaped_chars = {
b"n": b"\n", b"n": b"\n",
@ -922,16 +922,16 @@ class PdfParser:
offset = m.end() offset = m.end()
raise PdfFormatError("unfinished literal string") raise PdfFormatError("unfinished literal string")
re_xref_section_start = re.compile(whitespace_optional + br"xref" + newline) re_xref_section_start = re.compile(whitespace_optional + rb"xref" + newline)
re_xref_subsection_start = re.compile( re_xref_subsection_start = re.compile(
whitespace_optional whitespace_optional
+ br"([0-9]+)" + rb"([0-9]+)"
+ whitespace_mandatory + whitespace_mandatory
+ br"([0-9]+)" + rb"([0-9]+)"
+ whitespace_optional + whitespace_optional
+ newline_only + newline_only
) )
re_xref_entry = re.compile(br"([0-9]{10}) ([0-9]{5}) ([fn])( \r| \n|\r\n)") re_xref_entry = re.compile(rb"([0-9]{10}) ([0-9]{5}) ([fn])( \r| \n|\r\n)")
def read_xref_table(self, xref_section_offset): def read_xref_table(self, xref_section_offset):
subsection_found = False subsection_found = False

View File

@ -48,7 +48,7 @@ from ._binary import o32be as o32
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
is_cid = re.compile(br"\w\w\w\w").match is_cid = re.compile(rb"\w\w\w\w").match
_MAGIC = b"\211PNG\r\n\032\n" _MAGIC = b"\211PNG\r\n\032\n"

View File

@ -25,7 +25,7 @@ from . import Image, ImageFile
# XBM header # XBM header
xbm_head = re.compile( xbm_head = re.compile(
br"\s*#define[ \t]+.*_width[ \t]+(?P<width>[0-9]+)[\r\n]+" rb"\s*#define[ \t]+.*_width[ \t]+(?P<width>[0-9]+)[\r\n]+"
b"#define[ \t]+.*_height[ \t]+(?P<height>[0-9]+)[\r\n]+" b"#define[ \t]+.*_height[ \t]+(?P<height>[0-9]+)[\r\n]+"
b"(?P<hotspot>" b"(?P<hotspot>"
b"#define[ \t]+[^_]*_x_hot[ \t]+(?P<xhot>[0-9]+)[\r\n]+" b"#define[ \t]+[^_]*_x_hot[ \t]+(?P<xhot>[0-9]+)[\r\n]+"

View File

@ -464,7 +464,7 @@ def build_dep_all():
if dep_name in disabled: if dep_name in disabled:
continue continue
script = build_dep(dep_name) script = build_dep(dep_name)
lines.append(fr'cmd.exe /c "{{build_dir}}\{script}"') lines.append(rf'cmd.exe /c "{{build_dir}}\{script}"')
lines.append("if errorlevel 1 echo Build failed! && exit /B 1") lines.append("if errorlevel 1 echo Build failed! && exit /B 1")
lines.append("@echo All Pillow dependencies built successfully!") lines.append("@echo All Pillow dependencies built successfully!")
write_script("build_dep_all.cmd", lines) write_script("build_dep_all.cmd", lines)