-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
289 additions
and
247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import hashlib | ||
|
||
from dictdatabase import utils | ||
from dictdatabase.dataclasses import Index | ||
|
||
|
||
class IndexManager: | ||
@staticmethod | ||
def create_index(all_file_bytes: bytes, key: str, start, end): | ||
""" | ||
It takes a JSON file, a key, and a start and end position, and returns a tuple of information about the key and its | ||
value | ||
def create_index(all_file_bytes: bytes, key: str, start, end) -> Index: | ||
""" | ||
It takes a JSON file, a key, and a start and end position, and returns a tuple of information about the key and its | ||
value | ||
Args: | ||
all_file_bytes (bytes): The entire file as a byte string. | ||
key (str): The key of the value we're indexing. | ||
start: the start of the value in the file | ||
end: the end of the value in the file | ||
Args: | ||
all_file_bytes (bytes): The entire file as a byte string. | ||
key (str): The key of the value we're indexing. | ||
start: the start of the value in the file | ||
end: the end of the value in the file | ||
Returns: | ||
The key, start, end, indent_level, indent_with, value_hash, end | ||
""" | ||
key_start, key_end = utils.find_outermost_key_in_json_bytes(all_file_bytes, key) | ||
indent_level, indent_with = utils.detect_indentation_in_json_bytes( | ||
all_file_bytes, key_start | ||
) | ||
value_bytes = all_file_bytes[start:end] | ||
value_hash = hashlib.sha256(value_bytes).hexdigest() | ||
return key, start, end, indent_level, indent_with, value_hash, end | ||
Returns: | ||
The key, start, end, indent_level, indent_with, value_hash, end | ||
""" | ||
key_start, key_end = utils.find_outermost_key_in_json_bytes(all_file_bytes, key) | ||
indent_level, indent_with = utils.detect_indentation_in_json_bytes( | ||
all_file_bytes, key_start | ||
) | ||
value_bytes = all_file_bytes[start:end] | ||
value_hash = hashlib.sha256(value_bytes).hexdigest() | ||
return Index(key, start, end, indent_level, indent_with, value_hash, end) |
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.