-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --input for query subcommand (#107)
This is an alternative to include a file in your query alongside the positional or stdin query.
- Loading branch information
Showing
22 changed files
with
316 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Module to track constants for the project.""" | ||
|
||
VERSION = "0.1.0" | ||
#: Define the version for the program | ||
VERSION = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Utilitary module to handle file operations""" | ||
|
||
from typing import Union | ||
|
||
#: Common binary signatures | ||
BINARY_SIGNATURES = [ | ||
b"\x7fELF", # ELF files | ||
b"%PDF", # PDF files | ||
b"PK\x03\x04", # ZIP files | ||
] | ||
|
||
|
||
def is_content_in_binary_format(content: Union[str, bytes]) -> bool: | ||
"""Check if a given content is in binary format. | ||
Args: | ||
content (str): The content to be checked for binary presence. | ||
Raises: | ||
ValueError: If the content is binary or contains invalid text encoding. | ||
Returns: | ||
bool: True if the content is binary, False otherwise. | ||
""" | ||
try: | ||
# Try to decode as utf-8 | ||
if isinstance(content, bytes): | ||
content = content.decode("utf-8") | ||
|
||
# Check for null bytes which often indicate binary data | ||
if "\0" in content: | ||
return True | ||
|
||
# Additional check for common binary file signatures | ||
content_bytes = content.encode("utf-8") if isinstance(content, str) else content | ||
if any(content_bytes.startswith(sig) for sig in BINARY_SIGNATURES): | ||
return True | ||
except UnicodeDecodeError as e: | ||
raise ValueError( | ||
"File appears to be binary or contains invalid text encoding" | ||
) from e | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.