File tree 3 files changed +66
-1
lines changed
3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 7
7
from .yblob import YBlob as YBlob
8
8
from .yfile import YFile as YFile
9
9
from .ynotebook import YNotebook as YNotebook
10
+ from .ystdin import add_stdin as add_stdin
10
11
from .yunicode import YUnicode as YUnicode
11
12
12
13
# See compatibility note on `group` keyword in
Original file line number Diff line number Diff line change
1
+ from pycrdt import Map , Text
2
+
3
+
4
+ def add_stdin (cell : Map , prompt : str = "" , password : bool = False ) -> None :
5
+ """
6
+ Adds an stdin Map in the cell outputs.
7
+
8
+ Schema:
9
+
10
+ .. code-block:: json
11
+
12
+ {
13
+ "state": Map[
14
+ "pending": bool,
15
+ "password": bool
16
+ ],
17
+ "prompt": str,
18
+ "input": Text
19
+ }
20
+ """
21
+ stdin = Map (
22
+ {
23
+ "output_type" : "stdin" ,
24
+ "state" : {
25
+ "pending" : True ,
26
+ "password" : password ,
27
+ },
28
+ "prompt" : prompt ,
29
+ "input" : Text (),
30
+ }
31
+ )
32
+ outputs = cell .get ("outputs" )
33
+ outputs .append (stdin )
Original file line number Diff line number Diff line change 1
1
# Copyright (c) Jupyter Development Team.
2
2
# Distributed under the terms of the Modified BSD License.
3
3
4
- from jupyter_ydoc import YBlob
4
+ from jupyter_ydoc import YBlob , YNotebook , add_stdin
5
5
6
6
7
7
def test_yblob ():
@@ -22,3 +22,34 @@ def callback(topic, event):
22
22
assert topic == "source"
23
23
assert event .keys ["bytes" ]["oldValue" ] == b"012"
24
24
assert event .keys ["bytes" ]["newValue" ] == b"345"
25
+
26
+
27
+ def test_stdin ():
28
+ ynotebook = YNotebook ()
29
+ ynotebook .append_cell (
30
+ {
31
+ "cell_type" : "code" ,
32
+ "source" : "" ,
33
+ }
34
+ )
35
+ ycell = ynotebook .ycells [0 ]
36
+ add_stdin (ycell )
37
+ cell = ycell .to_py ()
38
+ # cell ID is random, ignore that
39
+ del cell ["id" ]
40
+ assert cell == {
41
+ "outputs" : [
42
+ {
43
+ "output_type" : "stdin" ,
44
+ "input" : "" ,
45
+ "prompt" : "" ,
46
+ "state" : {
47
+ "password" : False ,
48
+ "pending" : True ,
49
+ },
50
+ }
51
+ ],
52
+ "source" : "" ,
53
+ "metadata" : {},
54
+ "cell_type" : "code" ,
55
+ }
You can’t perform that action at this time.
0 commit comments