@@ -136,12 +136,16 @@ def Utf8Encode(code):
136
136
137
137
138
138
SHOW_CYCLES = 1 << 1 # show as [...] or {...} or (...), with object ID
139
- SHOW_NON_DATA = 1 << 2 # non-data objects like Eggex can be <Eggex 0xff>
140
- LOSSY_JSON = 1 << 3 # JSON may lose data about strings
141
- INF_NAN_ARE_NULL = 1 << 4 # for JSON
139
+ NON_DATA_PRETTY_PRINT = 1 << 2 # non-data objects like Eggex can be <Eggex 0xff>
140
+ LOSSY_JSON_STRINGS = 1 << 3 # JSON may lose data about strings
141
+ INF_NAN_ARE_NULL = 1 << 4 # another lossy json issue
142
+
143
+ # TODO:
144
+ # - default is NON_DATA_PRETTY_PRINT
145
+ # - opt into either NON_DATA_IS_ERROR or NON_DATA_IS_NULL
142
146
143
147
# Hack until we fully translate
144
- assert pyj8 .LOSSY_JSON == LOSSY_JSON
148
+ assert pyj8 .LOSSY_JSON_STRINGS == LOSSY_JSON_STRINGS
145
149
146
150
147
151
def _Print (val , buf , indent , options = 0 ):
@@ -170,35 +174,22 @@ def PrintJsonMessage(val, buf, indent):
170
174
Caller must handle error.Encode()
171
175
Doesn't decay to b'' strings - will use Unicode replacement char.
172
176
"""
173
- _Print (val , buf , indent , options = LOSSY_JSON | INF_NAN_ARE_NULL )
177
+ _Print (val , buf , indent , options = LOSSY_JSON_STRINGS | INF_NAN_ARE_NULL )
174
178
175
179
176
180
def PrintLine (val , f ):
177
181
# type: (value_t, mylib.Writer) -> None
178
- """ For pp line (x) """
182
+ """ For pp test_ (x) """
179
183
180
184
# error.Encode should be impossible - we show cycles and non-data
181
185
buf = mylib .BufWriter ()
182
186
183
- _Print (val , buf , - 1 , options = SHOW_CYCLES | SHOW_NON_DATA )
187
+ _Print (val , buf , - 1 , options = SHOW_CYCLES | NON_DATA_PRETTY_PRINT )
184
188
185
189
f .write (buf .getvalue ())
186
190
f .write ('\n ' )
187
191
188
192
189
- if 0 :
190
-
191
- def Repr (val ):
192
- # type: (value_t) -> str
193
- """ Unused
194
- This is like Python's repr
195
- """
196
- # error.Encode should be impossible - we show cycles and non-data
197
- buf = mylib .BufWriter ()
198
- _Print (val , buf , - 1 , options = SHOW_CYCLES | SHOW_NON_DATA )
199
- return buf .getvalue ()
200
-
201
-
202
193
def EncodeString (s , buf , unquoted_ok = False ):
203
194
# type: (str, mylib.BufWriter, bool) -> None
204
195
""" For pp proc, etc."""
@@ -229,7 +220,7 @@ def MaybeEncodeJsonString(s):
229
220
# TODO: add unquoted_ok here?
230
221
# /usr/local/foo-bar/x.y/a_b
231
222
buf = mylib .BufWriter ()
232
- _Print (value .Str (s ), buf , - 1 , options = LOSSY_JSON )
223
+ _Print (value .Str (s ), buf , - 1 , options = LOSSY_JSON_STRINGS )
233
224
return buf .getvalue ()
234
225
235
226
@@ -575,7 +566,7 @@ def Print(self, val, level=0):
575
566
elif case (value_e .Obj ):
576
567
val = cast (Obj , UP_val )
577
568
578
- if not (self .options & SHOW_NON_DATA ):
569
+ if not (self .options & NON_DATA_PRETTY_PRINT ):
579
570
raise error .Encode ("Can't encode value of type Obj" )
580
571
581
572
# Cycle detection, only for containers that can be in cycles
@@ -609,7 +600,7 @@ def Print(self, val, level=0):
609
600
610
601
else :
611
602
pass # mycpp workaround
612
- if self .options & SHOW_NON_DATA :
603
+ if self .options & NON_DATA_PRETTY_PRINT :
613
604
# Similar to = operator, ui.DebugPrint()
614
605
# TODO: that prints value.Range in a special way
615
606
ysh_type = ValType (val )
0 commit comments