1
0
Fork 0

Merging upstream version 2.1.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-12 21:45:23 +01:00
parent 9011a461b8
commit 2a78ba5ef7
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4 changed files with 23 additions and 3 deletions

View file

@ -183,6 +183,7 @@ EXTENSIONS = {
'txsprofile': {'text', 'ini', 'txsprofile'}, 'txsprofile': {'text', 'ini', 'txsprofile'},
'txt': {'text', 'plain-text'}, 'txt': {'text', 'plain-text'},
'v': {'text', 'verilog'}, 'v': {'text', 'verilog'},
'vb': {'text', 'vb'},
'vbproj': {'text', 'xml', 'vbproj'}, 'vbproj': {'text', 'xml', 'vbproj'},
'vcxproj': {'text', 'xml', 'vcxproj'}, 'vcxproj': {'text', 'xml', 'vcxproj'},
'vdx': {'text', 'vdx'}, 'vdx': {'text', 'vdx'},

View file

@ -1,3 +1,4 @@
import errno
import os.path import os.path
import re import re
import shlex import shlex
@ -205,8 +206,14 @@ def parse_shebang_from_file(path: str) -> Tuple[str, ...]:
if not os.access(path, os.X_OK): if not os.access(path, os.X_OK):
return () return ()
with open(path, 'rb') as f: try:
return parse_shebang(f) with open(path, 'rb') as f:
return parse_shebang(f)
except OSError as e:
if e.errno == errno.EINVAL:
return ()
else:
raise
COPYRIGHT_RE = re.compile(r'^\s*(Copyright|\(C\)) .*$', re.I | re.MULTILINE) COPYRIGHT_RE = re.compile(r'^\s*(Copyright|\(C\)) .*$', re.I | re.MULTILINE)

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = identify name = identify
version = 2.1.0 version = 2.1.2
description = File identification library for Python description = File identification library for Python
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown

View file

@ -1,8 +1,11 @@
import builtins
import errno
import io import io
import os import os
import socket import socket
import stat import stat
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from unittest import mock
import pytest import pytest
@ -330,6 +333,15 @@ def test_parse_shebang_from_file_simple(tmpdir):
assert identify.parse_shebang_from_file(x.strpath) == ('python',) assert identify.parse_shebang_from_file(x.strpath) == ('python',)
def test_parse_shebang_open_raises_einval(tmpdir):
x = tmpdir.join('f')
x.write('#!/usr/bin/env not-expected\n')
make_executable(x)
error = OSError(errno.EINVAL, f'Invalid argument {x}')
with mock.patch.object(builtins, 'open', side_effect=error):
assert identify.parse_shebang_from_file(x.strpath) == ()
def make_executable(filename): def make_executable(filename):
original_mode = os.stat(filename).st_mode original_mode = os.stat(filename).st_mode
os.chmod( os.chmod(