jmux 0.0.2__py3-none-any.whl → 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jmux/demux.py +32 -22
- jmux/helpers.py +12 -2
- jmux/types.py +2 -1
- {jmux-0.0.2.dist-info → jmux-0.0.3.dist-info}/METADATA +1 -1
- jmux-0.0.3.dist-info/RECORD +13 -0
- jmux-0.0.2.dist-info/RECORD +0 -13
- {jmux-0.0.2.dist-info → jmux-0.0.3.dist-info}/WHEEL +0 -0
- {jmux-0.0.2.dist-info → jmux-0.0.3.dist-info}/licenses/LICENSE +0 -0
- {jmux-0.0.2.dist-info → jmux-0.0.3.dist-info}/top_level.txt +0 -0
jmux/demux.py
CHANGED
|
@@ -32,7 +32,7 @@ from jmux.error import (
|
|
|
32
32
|
from jmux.helpers import (
|
|
33
33
|
extract_types_from_generic_alias,
|
|
34
34
|
get_main_type,
|
|
35
|
-
|
|
35
|
+
str_to_bool,
|
|
36
36
|
)
|
|
37
37
|
from jmux.pda import PushDownAutomata
|
|
38
38
|
from jmux.types import (
|
|
@@ -47,12 +47,13 @@ from jmux.types import (
|
|
|
47
47
|
JSON_FALSE,
|
|
48
48
|
JSON_NULL,
|
|
49
49
|
JSON_TRUE,
|
|
50
|
+
JSON_WHITESPACE,
|
|
50
51
|
NULL_ALLOWED,
|
|
51
52
|
NULL_OPEN,
|
|
52
53
|
NUMBER_OPEN,
|
|
53
54
|
OBJECT_CLOSE,
|
|
54
55
|
OBJECT_OPEN,
|
|
55
|
-
|
|
56
|
+
PARSING_PRIMITIVE_STATES,
|
|
56
57
|
QUOTE,
|
|
57
58
|
)
|
|
58
59
|
from jmux.types import Mode as M
|
|
@@ -421,7 +422,7 @@ class JMux(ABC):
|
|
|
421
422
|
case None:
|
|
422
423
|
match self._pda.state:
|
|
423
424
|
case S.START:
|
|
424
|
-
if
|
|
425
|
+
if ch in JSON_WHITESPACE:
|
|
425
426
|
pass
|
|
426
427
|
elif ch in OBJECT_OPEN:
|
|
427
428
|
self._pda.push(M.ROOT)
|
|
@@ -434,7 +435,7 @@ class JMux(ABC):
|
|
|
434
435
|
"JSON must start with '{' character.",
|
|
435
436
|
)
|
|
436
437
|
case S.END:
|
|
437
|
-
if
|
|
438
|
+
if ch in JSON_WHITESPACE:
|
|
438
439
|
pass
|
|
439
440
|
else:
|
|
440
441
|
raise ObjectAlreadyClosedError(
|
|
@@ -458,7 +459,7 @@ class JMux(ABC):
|
|
|
458
459
|
case M.ROOT:
|
|
459
460
|
match self._pda.state:
|
|
460
461
|
case S.EXPECT_KEY:
|
|
461
|
-
if
|
|
462
|
+
if ch in JSON_WHITESPACE:
|
|
462
463
|
pass
|
|
463
464
|
elif ch == '"':
|
|
464
465
|
self._pda.set_state(S.PARSING_KEY)
|
|
@@ -485,7 +486,7 @@ class JMux(ABC):
|
|
|
485
486
|
self._decoder.push(ch)
|
|
486
487
|
|
|
487
488
|
case S.EXPECT_COLON:
|
|
488
|
-
if
|
|
489
|
+
if ch in JSON_WHITESPACE:
|
|
489
490
|
pass
|
|
490
491
|
elif ch in COLON:
|
|
491
492
|
self._pda.set_state(S.EXPECT_VALUE)
|
|
@@ -498,7 +499,7 @@ class JMux(ABC):
|
|
|
498
499
|
)
|
|
499
500
|
|
|
500
501
|
case S.EXPECT_VALUE:
|
|
501
|
-
if
|
|
502
|
+
if ch in JSON_WHITESPACE:
|
|
502
503
|
pass
|
|
503
504
|
elif res := await self._handle_common__expect_value(ch):
|
|
504
505
|
if (
|
|
@@ -550,20 +551,20 @@ class JMux(ABC):
|
|
|
550
551
|
):
|
|
551
552
|
await self._sink.emit(maybe_char)
|
|
552
553
|
|
|
553
|
-
case _ if self._pda.state in
|
|
554
|
-
if ch
|
|
555
|
-
self._assert_primitive_character_allowed_in_state(ch)
|
|
556
|
-
self._decoder.push(ch)
|
|
557
|
-
else:
|
|
554
|
+
case _ if self._pda.state in PARSING_PRIMITIVE_STATES:
|
|
555
|
+
if ch in COMMA | OBJECT_CLOSE | JSON_WHITESPACE:
|
|
558
556
|
await self._parse_primitive()
|
|
559
557
|
await self._sink.close()
|
|
560
558
|
self._decoder.reset()
|
|
561
559
|
self._pda.set_state(S.EXPECT_KEY)
|
|
562
560
|
if ch in OBJECT_CLOSE:
|
|
563
561
|
await self._finalize()
|
|
562
|
+
else:
|
|
563
|
+
self._assert_primitive_character_allowed_in_state(ch)
|
|
564
|
+
self._decoder.push(ch)
|
|
564
565
|
|
|
565
566
|
case S.EXPECT_COMMA_OR_EOC:
|
|
566
|
-
if
|
|
567
|
+
if ch in JSON_WHITESPACE:
|
|
567
568
|
pass
|
|
568
569
|
elif ch in COMMA:
|
|
569
570
|
self._pda.set_state(S.EXPECT_KEY)
|
|
@@ -596,7 +597,7 @@ class JMux(ABC):
|
|
|
596
597
|
|
|
597
598
|
match self._pda.state:
|
|
598
599
|
case S.EXPECT_VALUE:
|
|
599
|
-
if
|
|
600
|
+
if ch in JSON_WHITESPACE:
|
|
600
601
|
pass
|
|
601
602
|
elif await self._handle_common__expect_value(ch):
|
|
602
603
|
pass
|
|
@@ -638,20 +639,20 @@ class JMux(ABC):
|
|
|
638
639
|
else:
|
|
639
640
|
self._decoder.push(ch)
|
|
640
641
|
|
|
641
|
-
case _ if self._pda.state in
|
|
642
|
-
if ch
|
|
643
|
-
self._assert_primitive_character_allowed_in_state(ch)
|
|
644
|
-
self._decoder.push(ch)
|
|
645
|
-
else:
|
|
642
|
+
case _ if self._pda.state in PARSING_PRIMITIVE_STATES:
|
|
643
|
+
if ch in COMMA | ARRAY_CLOSE | JSON_WHITESPACE:
|
|
646
644
|
await self._parse_primitive()
|
|
647
645
|
self._decoder.reset()
|
|
648
646
|
if ch in COMMA:
|
|
649
647
|
self._pda.set_state(S.EXPECT_VALUE)
|
|
650
648
|
elif ch in ARRAY_CLOSE:
|
|
651
649
|
await self._close_context(S.EXPECT_COMMA_OR_EOC)
|
|
650
|
+
else:
|
|
651
|
+
self._assert_primitive_character_allowed_in_state(ch)
|
|
652
|
+
self._decoder.push(ch)
|
|
652
653
|
|
|
653
654
|
case S.EXPECT_COMMA_OR_EOC:
|
|
654
|
-
if
|
|
655
|
+
if ch in JSON_WHITESPACE:
|
|
655
656
|
pass
|
|
656
657
|
elif ch in COMMA:
|
|
657
658
|
self._pda.set_state(S.EXPECT_VALUE)
|
|
@@ -681,8 +682,16 @@ class JMux(ABC):
|
|
|
681
682
|
self._pda.state,
|
|
682
683
|
"State in object context must be 'parsing_object'",
|
|
683
684
|
)
|
|
684
|
-
if ch in
|
|
685
|
+
if ch in OBJECT_OPEN:
|
|
686
|
+
if self._pda.top is M.OBJECT:
|
|
687
|
+
await self._sink.forward_char(ch)
|
|
688
|
+
self._pda.push(M.OBJECT)
|
|
689
|
+
elif ch in OBJECT_CLOSE:
|
|
685
690
|
self._pda.pop()
|
|
691
|
+
if self._pda.top is M.OBJECT:
|
|
692
|
+
await self._sink.forward_char(ch)
|
|
693
|
+
return
|
|
694
|
+
|
|
686
695
|
if self._pda.top is M.ROOT:
|
|
687
696
|
await self._sink.close()
|
|
688
697
|
self._pda.set_state(S.EXPECT_COMMA_OR_EOC)
|
|
@@ -699,7 +708,8 @@ class JMux(ABC):
|
|
|
699
708
|
)
|
|
700
709
|
await self._sink.emit(None)
|
|
701
710
|
elif self._pda.state is S.PARSING_BOOLEAN:
|
|
702
|
-
|
|
711
|
+
bool_value = str_to_bool(self._decoder.buffer)
|
|
712
|
+
await self._sink.emit(bool_value)
|
|
703
713
|
else:
|
|
704
714
|
try:
|
|
705
715
|
buffer = self._decoder.buffer
|
jmux/helpers.py
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
from types import NoneType, UnionType
|
|
2
2
|
from typing import Set, Tuple, Type, Union, get_args, get_origin
|
|
3
3
|
|
|
4
|
+
from jmux.error import ParsePrimitiveError
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
def str_to_bool(s: str) -> bool:
|
|
8
|
+
if s == "true":
|
|
9
|
+
return True
|
|
10
|
+
elif s == "false":
|
|
11
|
+
return False
|
|
12
|
+
else:
|
|
13
|
+
raise ParsePrimitiveError(
|
|
14
|
+
f"Cannot convert string '{s}' to boolean. Expected 'true' or 'false', got"
|
|
15
|
+
f" '{s}'."
|
|
16
|
+
)
|
|
7
17
|
|
|
8
18
|
|
|
9
19
|
def extract_types_from_generic_alias(UnknownType: Type) -> Tuple[Set[Type], Set[Type]]:
|
jmux/types.py
CHANGED
|
@@ -21,7 +21,7 @@ class State(Enum):
|
|
|
21
21
|
PARSING_OBJECT = "parsing_object"
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
PARSING_PRIMITIVE_STATES: Set[State] = {
|
|
25
25
|
State.PARSING_INTEGER,
|
|
26
26
|
State.PARSING_FLOAT,
|
|
27
27
|
State.PARSING_BOOLEAN,
|
|
@@ -55,3 +55,4 @@ NULL_ALLOWED = set("nul")
|
|
|
55
55
|
JSON_FALSE = "false"
|
|
56
56
|
JSON_TRUE = "true"
|
|
57
57
|
JSON_NULL = "null"
|
|
58
|
+
JSON_WHITESPACE = set(" \t\n\r")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
jmux/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
jmux/awaitable.py,sha256=gceBygIf3fAIWLsN1lWxsz9ExWNasDuk1WaGz8d9FAc,8427
|
|
3
|
+
jmux/decoder.py,sha256=Y6KVryRDLvGV5nBsneXpTvC0WUGhR5Z89Dvqz4HMAgg,1562
|
|
4
|
+
jmux/demux.py,sha256=0dKIQibyDQkijuIcT53Za1L2DZbC_Ll0_1mhroqHg9I,35516
|
|
5
|
+
jmux/error.py,sha256=VZJYivt8RPfjcF2bs-T7_UkH3dVA3xH-xGbZggQV14k,4665
|
|
6
|
+
jmux/helpers.py,sha256=DQyPeuwx3AR65aHrET7xpSbfTLTC7ji3CyicyEhqJpk,2226
|
|
7
|
+
jmux/pda.py,sha256=81gnh0eWGsgd_SrHkqjRQy_KkOSlBf5nor7pqKGgYjw,791
|
|
8
|
+
jmux/types.py,sha256=5Ox01s-rGMQ1xGX8NRNBlyWtxvGKwnt9bjexXdESSYc,1233
|
|
9
|
+
jmux-0.0.3.dist-info/licenses/LICENSE,sha256=y0qnwaAe4bEqzNPyq4M_VZA2I2mQly8MawajyZhqw0k,1169
|
|
10
|
+
jmux-0.0.3.dist-info/METADATA,sha256=ZSi9Y5l5FsyaJuTW3N2K199mCNfkMe8_FLmxjIEfSAA,13330
|
|
11
|
+
jmux-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
jmux-0.0.3.dist-info/top_level.txt,sha256=TF2N6kHqLghfOkCiNlCueMDX4l5rPn_5MSPNtYrS1-o,5
|
|
13
|
+
jmux-0.0.3.dist-info/RECORD,,
|
jmux-0.0.2.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
jmux/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
jmux/awaitable.py,sha256=gceBygIf3fAIWLsN1lWxsz9ExWNasDuk1WaGz8d9FAc,8427
|
|
3
|
-
jmux/decoder.py,sha256=Y6KVryRDLvGV5nBsneXpTvC0WUGhR5Z89Dvqz4HMAgg,1562
|
|
4
|
-
jmux/demux.py,sha256=7YJBD_EGUyxjiwjVnKCZOA-NrpXWrTe_y2Eitl4EU3E,35089
|
|
5
|
-
jmux/error.py,sha256=VZJYivt8RPfjcF2bs-T7_UkH3dVA3xH-xGbZggQV14k,4665
|
|
6
|
-
jmux/helpers.py,sha256=6y33RohUGVvGGaAREyRQTmEWfgV4w295SyqDwIMnUNs,1982
|
|
7
|
-
jmux/pda.py,sha256=81gnh0eWGsgd_SrHkqjRQy_KkOSlBf5nor7pqKGgYjw,791
|
|
8
|
-
jmux/types.py,sha256=V63wMx1I7l_P83JAqzOQ7H7B-xKrNUuGshJ3NjKsdeQ,1192
|
|
9
|
-
jmux-0.0.2.dist-info/licenses/LICENSE,sha256=y0qnwaAe4bEqzNPyq4M_VZA2I2mQly8MawajyZhqw0k,1169
|
|
10
|
-
jmux-0.0.2.dist-info/METADATA,sha256=G3PPpw0VhSYx9YyeVUT9T12YCGxORI7HVFAQYTB4Od4,13330
|
|
11
|
-
jmux-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
-
jmux-0.0.2.dist-info/top_level.txt,sha256=TF2N6kHqLghfOkCiNlCueMDX4l5rPn_5MSPNtYrS1-o,5
|
|
13
|
-
jmux-0.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|