File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Expand file tree Collapse file tree 2 files changed +22
-18
lines changed 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 uuid import uuid4
5
+
4
6
from pycrdt import Map , Text
5
7
6
8
7
- def add_stdin (cell : Map , prompt : str = "" , password : bool = False ) -> None :
9
+ def add_stdin (cell : Map , prompt : str = "" , password : bool = False ) -> str :
8
10
"""
9
- Adds an stdin Map in the cell outputs.
11
+ Adds an stdin Map in the cell outputs, and returns its ID .
10
12
11
13
Schema:
12
14
13
15
.. code-block:: json
14
16
15
17
{
16
- "state ": Map[
17
- "pending ": bool ,
18
- "password ": bool
19
- ],
18
+ "output_type ": "stdin",
19
+ "id ": str ,
20
+ "submitted ": bool,
21
+ "password": bool
20
22
"prompt": str,
21
23
"input": Text
22
24
}
23
25
"""
26
+ idx = uuid4 ().hex
24
27
stdin = Map (
25
28
{
26
29
"output_type" : "stdin" ,
27
- "state" : {
28
- "pending" : True ,
29
- "password" : password ,
30
- },
30
+ "id" : idx ,
31
+ "submitted" : False ,
32
+ "password" : password ,
31
33
"prompt" : prompt ,
32
34
"input" : Text (),
33
35
}
34
36
)
35
37
outputs = cell .get ("outputs" )
36
38
outputs .append (stdin )
39
+ return idx
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ def test_yblob():
12
12
changes = []
13
13
14
14
def callback (topic , event ):
15
- print (topic , event )
16
15
changes .append ((topic , event ))
17
16
18
17
yblob .observe (callback )
@@ -33,20 +32,22 @@ def test_stdin():
33
32
}
34
33
)
35
34
ycell = ynotebook .ycells [0 ]
36
- add_stdin (ycell )
35
+ add_stdin (ycell , prompt = "pwd:" , password = True )
36
+ stdin = ycell ["outputs" ][0 ]["input" ]
37
+ stdin += "mypassword"
37
38
cell = ycell .to_py ()
38
39
# cell ID is random, ignore that
39
40
del cell ["id" ]
41
+ # input ID is random, ignore that
42
+ del cell ["outputs" ][0 ]["id" ]
40
43
assert cell == {
41
44
"outputs" : [
42
45
{
43
46
"output_type" : "stdin" ,
44
- "input" : "" ,
45
- "prompt" : "" ,
46
- "state" : {
47
- "password" : False ,
48
- "pending" : True ,
49
- },
47
+ "input" : "mypassword" ,
48
+ "prompt" : "pwd:" ,
49
+ "password" : True ,
50
+ "submitted" : False ,
50
51
}
51
52
],
52
53
"source" : "" ,
You can’t perform that action at this time.
0 commit comments