We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0ecce77 commit 48829cdCopy full SHA for 48829cd
1 file changed
tests/extmod/ujson_dump_iobase.py
@@ -0,0 +1,32 @@
1
+# test ujson.dump in combination with uio.IOBase
2
+
3
+try:
4
+ import uio as io
5
+ import ujson as json
6
+except ImportError:
7
+ try:
8
+ import io, json
9
+ except ImportError:
10
+ print('SKIP')
11
+ raise SystemExit
12
13
+if not hasattr(io, 'IOBase'):
14
15
16
17
18
+# a user stream that only has the write method
19
+class S(io.IOBase):
20
+ def __init__(self):
21
+ self.buf = ''
22
+ def write(self, buf):
23
+ if type(buf) == bytearray:
24
+ # uPy passes a bytearray, CPython passes a str
25
+ buf = str(buf, 'ascii')
26
+ self.buf += buf
27
28
29
+# dump to the user stream
30
+s = S()
31
+json.dump([123, {}], s)
32
+print(s.buf)
0 commit comments