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
class CustomPasswordEncoder(json.JSONEncoder): | |
def default(self, obj): | |
try: | |
return {"password": obj.get_secret()} | |
except AttributeError: | |
return super().default(obj) | |
>>> json.dumps(obj, cls=CustomPasswordEncoder) | |
Traceback (most recent call last): |
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
>>> import json | |
>>> json.dumps(obj) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/usr/lib/python3.10/json/__init__.py", line 231, in dumps | |
return _default_encoder.encode(obj) | |
File "/usr/lib/python3.10/json/encoder.py", line 199, in encode | |
chunks = self.iterencode(o, _one_shot=True) | |
File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode |
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
>>> import pickle | |
>>> pickle.dumps(obj) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/shako/REPOS/py-read-once/.venv/lib/python3.10/site-packages/readonce.py", line 87, in __getstate__ | |
raise UnsupportedOperationException() | |
readonce.UnsupportedOperationException: Not allowed on sensitive value |
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
>>> obj.secrets | |
[] | |
>>> obj._ReadOnce__secrets | |
[] |
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
>>> class FakePassword(Password): | |
... ... | |
... | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/shako/REPOS/py-read-once/.venv/lib/python3.10/site-packages/readonce.py", line 21, in __new__ | |
raise TypeError("Subclassing final classes is restricted") | |
TypeError: Subclassing final classes is restricted |
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
>>> obj = Password(password="awesome_password") | |
>>> obj.add_secret("new_fake_date") | |
>>> obj.get_secret() | |
'new_fake_date' | |
>>> obj.get_secret() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/shako/REPOS/py-read-once/.venv/lib/python3.10/site-packages/readonce.py", line 47, in get_secret | |
raise UnsupportedOperationException("Sensitive data was already consumed") | |
readonce.UnsupportedOperationException: ('Not allowed on sensitive value', 'Sensitive data was already consumed') |
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
>>> obj.get_secret() | |
'awesome_password' | |
>>> obj.get_secret() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/shako/REPOS/py-read-once/.venv/lib/python3.10/site-packages/readonce.py", line 47, in get_secret | |
raise UnsupportedOperationException("Sensitive data was already consumed") | |
readonce.UnsupportedOperationException: ('Not allowed on sensitive value', 'Sensitive data was already consumed') |
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
>>> obj = Password(password="awesome_password") | |
>>> dir(obj) | |
[] | |
>>> obj.__dict__ | |
{} |
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
from readonce import ReadOnce | |
class Password(ReadOnce): | |
def __init__(self, password: str) -> None: | |
super().__init__() | |
self.add_secret(password) |
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
from src.main.containers import Container | |
def create_app() -> Flask: | |
container = Container() | |
... |