1- """
2- Parser for Rouvy API responses using turbo-stream format.
1+ """Parser for Rouvy API responses using turbo-stream format.
32
43Rouvy uses the turbo-stream format from Remix (https://github.com/jacob-ebey/turbo-stream),
54which is a streaming data format that supports more types than JSON and uses indexed
@@ -40,8 +39,7 @@ def __init__(self) -> None:
4039 self .promise_values : dict [int , Any ] = {}
4140
4241 def decode (self , response_text : str ) -> dict [str , Any ] | list [Any ] | Any :
43- """
44- Decode a turbo-stream formatted response.
42+ """Decode a turbo-stream formatted response.
4543
4644 Args:
4745 response_text: Raw response text (may be multi-line)
@@ -89,8 +87,7 @@ def _parse_promise_line(self, line: str) -> None:
8987 LOGGER .warning (f"Error parsing promise line '{ line } ': { e } " )
9088
9189 def _decode_value (self , value : Any , resolve_int_as_index : bool = False ) -> Any :
92- """
93- Recursively decode a value, resolving references and special types.
90+ """Recursively decode a value, resolving references and special types.
9491
9592 Args:
9693 value: The value to decode
@@ -100,10 +97,10 @@ def _decode_value(self, value: Any, resolve_int_as_index: bool = False) -> Any:
10097 if isinstance (value , int ):
10198 if value == - 5 :
10299 return UNDEFINED
103- elif value == - 7 :
100+ if value == - 7 :
104101 return NULL
105102 # Only resolve as index if explicitly requested (for indexed object values)
106- elif (
103+ if (
107104 resolve_int_as_index
108105 and value in self .index_map
109106 and value not in getattr (self , "_resolving" , set ())
@@ -136,9 +133,8 @@ def _decode_value(self, value: Any, resolve_int_as_index: bool = False) -> Any:
136133 return self ._decode_value (
137134 self .promise_values [promise_id ], resolve_int_as_index = False
138135 )
139- else :
140- # Promise not yet resolved
141- return f"<Promise:{ promise_id } >"
136+ # Promise not yet resolved
137+ return f"<Promise:{ promise_id } >"
142138
143139 # Regular array - decode each element (don't resolve ints as indices)
144140 return [self ._decode_value (item , resolve_int_as_index = False ) for item in value ]
@@ -183,8 +179,7 @@ def _decode_value(self, value: Any, resolve_int_as_index: bool = False) -> Any:
183179 return value
184180
185181 def extract_data_section (self , decoded : Any , path : str = "root.data" ) -> dict [str , Any ]:
186- """
187- Extract a specific data section from the decoded structure.
182+ """Extract a specific data section from the decoded structure.
188183
189184 Args:
190185 decoded: Decoded turbo-stream data
@@ -210,8 +205,7 @@ def extract_data_section(self, decoded: Any, path: str = "root.data") -> dict[st
210205
211206
212207def parse_response (response_text : str ) -> dict [str , Any ] | list [Any ] | Any :
213- """
214- Parse a Rouvy API response in turbo-stream format.
208+ """Parse a Rouvy API response in turbo-stream format.
215209
216210 Args:
217211 response_text: Raw response text
@@ -224,8 +218,7 @@ def parse_response(response_text: str) -> dict[str, Any] | list[Any] | Any:
224218
225219
226220def extract_user_profile (response_text : str ) -> dict [str , Any ]:
227- """
228- Extract user profile fields from user-settings response.
221+ """Extract user profile fields from user-settings response.
229222
230223 Args:
231224 response_text: Raw user-settings.data response
0 commit comments