-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
9 changed files
with
57 additions
and
41 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
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 |
---|---|---|
|
@@ -3,15 +3,18 @@ | |
Created on: May 19, 2017 | ||
Author: Jeroen van der Heijden <[email protected]> | ||
""" | ||
from typing import Iterable, Union | ||
from .pathelement import PathElement | ||
from .pathelement import path_element_from_decoder | ||
from .buffer import BufferDecodeError | ||
|
||
|
||
class Path: | ||
|
||
def __init__(self, pairs): | ||
self._path = tuple( | ||
def __init__(self, pairs: Union[ | ||
Iterable[PathElement], | ||
Iterable[tuple[str, Union[int, str]]]]): | ||
self._path: tuple[PathElement] = tuple( | ||
pe if isinstance(pe, PathElement) else PathElement(*pe) | ||
for pe in pairs) | ||
|
||
|
@@ -30,17 +33,17 @@ def __getitem__(self, item): | |
def __repr__(self): | ||
return str(self.get_as_tuple()) | ||
|
||
def get_dict(self): | ||
def get_dict(self) -> dict: | ||
return {'path': [pe.get_dict() for pe in self._path]} | ||
|
||
@property | ||
def byte_size(self): | ||
def byte_size(self) -> int: | ||
n = 2 * len(self._path) | ||
for path_element in self._path: | ||
n += path_element.byte_size | ||
return n | ||
|
||
def get_as_tuple(self): | ||
def get_as_tuple(self) -> tuple[tuple[str, Union[str, int]], ...]: | ||
"""Returns a tuple of pairs (tuples) representing the key path of an | ||
entity. Useful for composing entities with a specific ancestor.""" | ||
return tuple((pe.kind, pe.id) for pe in self._path) | ||
|
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