-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (50 loc) · 1.5 KB
/
index.js
File metadata and controls
62 lines (50 loc) · 1.5 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
var fs = require('fs');
var python = require('python-shell');
var pythonParser = function() {};
pythonParser.register = function(handlers, app, config) {
handlers.tools['python-parser'] = pythonParser;
app.get('/python-parser', function(req, res) {
res.set('Content-Type', 'text/html');
fs.readFile(__dirname + '/form.html', function(err, data) {
if (!err) {
res.send(data);
} else {
res.send("Error");
}
});
});
app.post('/python-parser', function(req, res) {
var code = { 'code': req.body.code, 'mode': req.body.mode || 'simple' };
var options = {
mode: 'json',
pythonPath: config.pythonPath || '/usr/bin/python3',
pythonOptions: ['-u'], // -u is unbuffered output
scriptPath: __dirname
};
var pyshell = new python('parser.py', options);
pyshell.send(code);
var response = '';
pyshell.on('message', function(message) {
response = message;
});
pyshell.end(function(err) {
if (err) {
res.json({ status: 'ERROR', message: 'Parsing failed.' });
} else {
res.json(response);
}
});
});
};
pythonParser.namespace = 'python-parser';
pythonParser.packageType = 'tool';
pythonParser.meta = {
'name': 'python-parser',
'shortDescription': 'Parser for parsing arbitrary Python code to export all language concepts used in the code.',
'description': '',
'author': 'Teemu Sirkiä',
'license': 'MIT',
'version': '0.0.1',
'url': ''
};
module.exports = pythonParser;