polar: handle few more attributes defensively
This commit is contained in:
parent
8277b33c18
commit
65138808e7
2 changed files with 24 additions and 5 deletions
|
@ -127,6 +127,7 @@ def wrap(j, throw=True) -> Iterator[Zoomable]:
|
|||
for c in children:
|
||||
if not c.this_consumed(): # TODO hmm. how does it figure out if it's consumed???
|
||||
if throw:
|
||||
# TODO need to keep a full path or something...
|
||||
raise UnconsumedError(f'''
|
||||
Expected {c} to be fully consumed by the parser.
|
||||
'''.lstrip())
|
||||
|
@ -175,6 +176,19 @@ def test_consume_all():
|
|||
aaa['bbb'].consume_all()
|
||||
|
||||
|
||||
def test_consume_few():
|
||||
import pytest
|
||||
pytest.skip('Will think about it later..')
|
||||
with wrap({
|
||||
'important': 123,
|
||||
'unimportant': 'whatever'
|
||||
}) as w:
|
||||
w = cast(Wdict, w)
|
||||
w['important'].zoom()
|
||||
w.consume_all()
|
||||
# TODO hmm, we want smth like this to work..
|
||||
|
||||
|
||||
def test_zoom() -> None:
|
||||
import pytest # type: ignore
|
||||
with wrap({'aaa': 'whatever'}) as w:
|
||||
|
|
|
@ -101,7 +101,10 @@ class Loader:
|
|||
meta = cast(Wdict, meta)
|
||||
# TODO this should be destructive zoom?
|
||||
meta['notes'].zoom() # TODO ??? is it deliberate?
|
||||
meta['pagemarks'].zoom()
|
||||
|
||||
meta['pagemarks'].consume_all()
|
||||
|
||||
|
||||
if 'notes' in meta:
|
||||
# TODO something nicer?
|
||||
notes = meta['notes'].zoom()
|
||||
|
@ -113,15 +116,17 @@ class Loader:
|
|||
highlights = meta['textHighlights'].zoom()
|
||||
|
||||
# TODO could be useful to at least add a meta bout area highlights/screens
|
||||
meta['areaHighlights'].zoom()
|
||||
meta['areaHighlights'].consume_all()
|
||||
meta['screenshots'].zoom()
|
||||
meta['thumbnails'].zoom()
|
||||
if 'readingProgress' in meta:
|
||||
meta['readingProgress'].zoom()
|
||||
meta['readingProgress'].consume_all()
|
||||
|
||||
# TODO want to ignore the whold subtree..
|
||||
# TODO want to ignore the whole subtree..
|
||||
pi = meta['pageInfo'].zoom()
|
||||
pi['num'].zoom()
|
||||
if 'dimensions' in pi:
|
||||
pi['dimensions'].consume_all()
|
||||
|
||||
# TODO how to make it nicer?
|
||||
cmap: Dict[Hid, List[Comment]] = {}
|
||||
|
@ -207,7 +212,7 @@ class Loader:
|
|||
filename = di['filename'] # TODO here
|
||||
title = di.get('title', None)
|
||||
tags_dict = di['tags']
|
||||
pm = j['pageMetas']
|
||||
pm = j['pageMetas'] # TODO FIXME handle this too
|
||||
|
||||
# todo defensive?
|
||||
tags = tuple(t['label'] for t in tags_dict.values())
|
||||
|
|
Loading…
Add table
Reference in a new issue