-
Notifications
You must be signed in to change notification settings - Fork 7
Refactor/string paths storage rtdb #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
29204cd
update RealtimeDatabase to take path
jckenny59 863696d
update storage to path based based reference
jckenny59 d7c7e78
Update Project Manager to support new path based writing
jckenny59 beccf0b
Update CHANGELOG.md
jckenny59 fdc2cef
linting and formatting
jckenny59 d592ac5
Merge branch 'prep-release' into refactor/string-paths-storage-rtdb
jckenny59 a984b10
Annotate RealtimeDatabase Method Signatures
jckenny59 fed8779
Annotate method signatures inside of Storage Class.
jckenny59 ab05c54
linting and formatting
jckenny59 3484c92
update doc strings for method type_hint
jckenny59 6ec3df2
update doc string for type_hint using Union()
jckenny59 256376f
update comment in rtdb for reference next time.
jckenny59 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,92 @@ | ||
| def normalize_path(path): | ||
| """Normalize a slash-delimited cloud path. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| path : str | list[str] | tuple[str] | ||
| Path as a slash-delimited string or as path segments. | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| Normalized path with single slashes and no leading/trailing slash. | ||
| """ | ||
| if isinstance(path, str): | ||
| raw_parts = path.strip("/").split("/") | ||
| elif isinstance(path, (list, tuple)): | ||
| raw_parts = path | ||
| else: | ||
| raise TypeError("path must be a string, list, or tuple") | ||
|
|
||
| parts = [] | ||
| for part in raw_parts: | ||
| if not isinstance(part, str): | ||
| raise TypeError("all path parts must be strings") | ||
| stripped = part.strip("/") | ||
| if stripped: | ||
| parts.append(stripped) | ||
|
|
||
| return "/".join(parts) | ||
|
|
||
|
|
||
| def path_to_parts(path): | ||
| """Convert a path string or path parts to normalized path segments.""" | ||
| normalized = normalize_path(path) | ||
| if not normalized: | ||
| return [] | ||
| return normalized.split("/") | ||
|
|
||
|
|
||
| def validate_reference_parts(parts, invalid_chars=None): | ||
| """Validate normalized path segments for cloud references. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| parts : list[str] | tuple[str] | ||
| Normalized path segments. | ||
| invalid_chars : set[str] | None, optional | ||
|
jckenny59 marked this conversation as resolved.
Outdated
|
||
| Characters that are not allowed in each path segment. | ||
|
|
||
| Returns | ||
| ------- | ||
| None | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the path is empty or contains invalid characters. | ||
| """ | ||
| if not parts: | ||
| raise ValueError("path must not be empty") | ||
|
|
||
| invalid_chars = invalid_chars or set() | ||
| for part in parts: | ||
| if any(char in part for char in invalid_chars): | ||
| raise ValueError("invalid path segment '{}': contains one of {}".format(part, " ".join(sorted(invalid_chars)))) | ||
| if any(ord(char) < 32 or ord(char) == 127 for char in part): | ||
| raise ValueError("invalid path segment '{}': contains control characters".format(part)) | ||
|
|
||
|
|
||
| def validate_reference_path(path, invalid_chars=None): | ||
| """Normalize and validate a cloud reference path. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| path : str | list[str] | tuple[str] | ||
| Path as a slash-delimited string or as path segments. | ||
| invalid_chars : set[str] | None, optional | ||
| Characters that are not allowed in each path segment. | ||
|
|
||
| Returns | ||
| ------- | ||
| list[str] | ||
| Normalized and validated path segments. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the path is empty or contains invalid characters. | ||
| """ | ||
| parts = path_to_parts(path) | ||
| validate_reference_parts(parts, invalid_chars=invalid_chars) | ||
| return parts | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.