-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkernel.py
More file actions
66 lines (51 loc) · 2 KB
/
Copy pathkernel.py
File metadata and controls
66 lines (51 loc) · 2 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from ipykernel.kernelbase import Kernel
from ipykernel.ipkernel import IPythonKernel
from urdupython import run_module, SCRIPTDIR
from io import StringIO
import sys
import os
class UrduPythonKernel(IPythonKernel):
implementation = 'UrduPython'
implementation_version = '1.1'
# language_version = '0.1'
language_info = {
'name': 'python',
'version': sys.version.split()[0],
'mimetype': 'text/x-python',
'file_extension': '.py',
}
banner = "UrduPython kernel"
def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
error_thrown = False
try:
compiled_code = run_module("lex", code, args = {
'translate': True,
'dictionary': os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'),
'reverse': False,
'keep': False,
'keep_only': False,
'return': True,
})
except Exception as e:
error_thrown = True
error_message = "Error: " + str(e)
print (error_message)
return super(UrduPythonKernel, self).do_execute(compiled_code, silent, store_history, user_expressions,
allow_stdin)
def do_complete(self, code, cursor_pos):
error_thrown = False
# try:
compiled_code = run_module("lex", code, args = {
'translate': True,
'dictionary': os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'),
'reverse': False,
'keep': False,
'keep_only': False,
'return': True,
})
# except Exception as e:
# error_thrown = True
# error_message = "Error: " + str(e)
# print (error_message)
return super(UrduPythonKernel, self).do_complete(compiled_code, cursor_pos)