This commit is contained in:
Kovid Goyal 2023-03-01 10:21:52 +05:30
commit cbf3b5860b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 13 additions and 6 deletions

View File

@ -55,7 +55,7 @@ def real_main(args: List[str]) -> None:
tb = data['tb']
for ln in tb.splitlines():
print('\r\n', ln, sep='', end='')
print(flush=True)
print(end='\r\n', flush=True)
hold_till_enter()

View File

@ -1,12 +1,12 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import imghdr
import os
from base64 import standard_b64decode, standard_b64encode
from typing import TYPE_CHECKING, Optional
from kitty.types import AsyncResponse
from kitty.utils import is_png
from .base import (
MATCH_WINDOW_OPTION,
@ -89,7 +89,7 @@ def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: Arg
if path.lower() == 'none':
ret['data'] = '-'
return ret
if imghdr.what(path) != 'png':
if not is_png(path):
self.fatal(f'{path} is not a PNG image')
def file_pipe(path: str) -> CmdGenerator:

View File

@ -1,13 +1,12 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import imghdr
import os
from base64 import standard_b64decode, standard_b64encode
from typing import TYPE_CHECKING, Optional
from kitty.types import AsyncResponse
from kitty.utils import is_png
from .base import (
MATCH_WINDOW_OPTION,
@ -85,7 +84,7 @@ def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: Arg
if path.lower() == 'none':
ret['data'] = '-'
return ret
if imghdr.what(path) != 'png':
if not is_png(path):
self.fatal(f'{path} is not a PNG image')
def file_pipe(path: str) -> CmdGenerator:

View File

@ -1137,3 +1137,11 @@ def safe_extract(tar: 'tarfile.TarFile', path: str = ".", numeric_owner: bool =
tar.extractall(path, tar.getmembers(), numeric_owner=numeric_owner)
safe_extract(tf, dest)
def is_png(path: str) -> bool:
if path:
with suppress(Exception), open(path, 'rb') as f:
header = f.read(8)
return header.startswith(b'\211PNG\r\n\032\n')
return False