-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.py
executable file
·38 lines (32 loc) · 1.16 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
import jsrpc
import time
try:
def get_message(message):
print " -> got a message: %s" % message
js = jsrpc.JSRPC(port=8080, http_root='demo_www')
#Sync
print "### Testing synchronous"
print "# Variable access"
print " -> window.location.href: %s" % js.sync.window.location.href
print "# Function call"
print " -> window.prompt(): %s" % js.sync.window.prompt('Enter some data...')
#Async
def location(value):
print " -> window.location.href: %s" % value
def prompt(value):
print " -> window.prompt(): %s" % value
print "### Testing asynchronous"
print "# Variable access"
js.async(location).window.location.href.flush() #Note that flush() is necessary for async variable access
print "# Function call"
js.async(prompt).window.prompt('Enter some data...')
#Async no return
print "### Testing asynchronous no-return"
print "# Variable access (lulwut)"
js.async.window.location.href.flush()
print "# Function call"
js.async.window.prompt('Enter some data...')
time.sleep(10000)
except KeyboardInterrupt, e:
js.server.shutdown()