Commit 319459fb authored by Jacob Durrant's avatar Jacob Durrant

JDD example.

parent c55aea0b
cd python
transcrypt main.py
rm javascript/*
mv __target__/* ../javascript/
rm -rf __target__
cp index.html ../javascript/
<html>
<head>
<script type="module">
import * as main from './main.js';
// Get fake data from the compiled python file.
var d = main.start_with_json_from_javascript({"moo": "dog", "face": 5});
// Add the fake data to the screen.
document.body.innerHTML = JSON.stringify(d);
console.log(d);
</script>
<script>
</script>
</head>
<body>
</body>
</html>
'use strict';import{AssertionError,AttributeError,BaseException,DeprecationWarning,Exception,IndexError,IterableError,KeyError,NotImplementedError,RuntimeWarning,StopIteration,UserWarning,ValueError,Warning,__JsIterator__,__PyIterator__,__Terminal__,__add__,__and__,__call__,__class__,__envir__,__eq__,__floordiv__,__ge__,__get__,__getcm__,__getitem__,__getslice__,__getsm__,__gt__,__i__,__iadd__,__iand__,__idiv__,__ijsmod__,__ilshift__,__imatmul__,__imod__,__imul__,__in__,__init__,__ior__,__ipow__,
__irshift__,__isub__,__ixor__,__jsUsePyNext__,__jsmod__,__k__,__kwargtrans__,__le__,__lshift__,__lt__,__matmul__,__mergefields__,__mergekwargtrans__,__mod__,__mul__,__ne__,__neg__,__nest__,__or__,__pow__,__pragma__,__proxy__,__pyUseJsNext__,__rshift__,__setitem__,__setproperty__,__setslice__,__sort__,__specialattrib__,__sub__,__super__,__t__,__terminal__,__truediv__,__withblock__,__xor__,abs,all,any,assert,bool,bytearray,bytes,callable,chr,copy,deepcopy,delattr,dict,dir,divmod,enumerate,filter,float,
getattr,hasattr,input,int,isinstance,issubclass,len,list,map,max,min,object,ord,pow,print,property,py_TypeError,py_iter,py_metatype,py_next,py_reversed,py_typeof,range,repr,round,set,setattr,sorted,str,sum,tuple,zip}from"./org.transcrypt.__runtime__.js";import*as print_vals from"./package.print_vals.js";import*as print_keys from"./package.print_keys.js";var __name__="__main__";export var obj_to_dict=function(o){var d=dict({});for(var key of function(){var __accu0__=[];for(var py_name of dir(o))if(!py_name.startswith("__"))__accu0__.append(py_name);
return __accu0__}())d[key]=getattr(o,key);return d};export var start_with_json_from_javascript=function(obj_from_javascript){var a_dict=obj_to_dict(obj_from_javascript);var k=print_keys.print_keys(a_dict);var v=print_vals.print_vals(a_dict);var data=[k,v];return data};
//# sourceMappingURL=main.map
\ No newline at end of file
{"options": {"source": "main.py", "anno": false, "alimod": false, "build": false, "complex": false, "docat": false, "dassert": false, "dcheck": false, "dextex": false, "dlog": false, "dmap": false, "dnostrip": false, "dstat": false, "dtree": false, "esv": null, "ecom": false, "fcall": false, "gen": false, "iconv": false, "jscall": false, "jskeys": false, "jsmod": false, "kwargs": false, "keycheck": false, "license": false, "map": false, "nomin": false, "opov": false, "parent": null, "run": false, "symbols": null, "sform": false, "tconv": false, "unit": null, "verbose": false, "x": null, "xreex": false, "xglobs": false, "xpath": null, "xtiny": false, "star": false}, "modules": [{"source": "/Users/jdurrant/anaconda/envs/Python36/lib/python3.6/site-packages/transcrypt/modules/org/transcrypt/__runtime__.py", "target": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/__target__/org.transcrypt.__runtime__.js"}, {"source": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/main.py", "target": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/__target__/main.js"}, {"source": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/package/print_vals.py", "target": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/__target__/package.print_vals.js"}, {"source": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/package/print_keys.py", "target": "/Users/jdurrant/Documents/Work/durrant_git/binana/jdd_tests/python/__target__/package.print_keys.js"}]}
\ No newline at end of file
This diff is collapsed.
'use strict';import{AssertionError,AttributeError,BaseException,DeprecationWarning,Exception,IndexError,IterableError,KeyError,NotImplementedError,RuntimeWarning,StopIteration,UserWarning,ValueError,Warning,__JsIterator__,__PyIterator__,__Terminal__,__add__,__and__,__call__,__class__,__envir__,__eq__,__floordiv__,__ge__,__get__,__getcm__,__getitem__,__getslice__,__getsm__,__gt__,__i__,__iadd__,__iand__,__idiv__,__ijsmod__,__ilshift__,__imatmul__,__imod__,__imul__,__in__,__init__,__ior__,__ipow__,
__irshift__,__isub__,__ixor__,__jsUsePyNext__,__jsmod__,__k__,__kwargtrans__,__le__,__lshift__,__lt__,__matmul__,__mergefields__,__mergekwargtrans__,__mod__,__mul__,__ne__,__neg__,__nest__,__or__,__pow__,__pragma__,__proxy__,__pyUseJsNext__,__rshift__,__setitem__,__setproperty__,__setslice__,__sort__,__specialattrib__,__sub__,__super__,__t__,__terminal__,__truediv__,__withblock__,__xor__,abs,all,any,assert,bool,bytearray,bytes,callable,chr,copy,deepcopy,delattr,dict,dir,divmod,enumerate,filter,float,
getattr,hasattr,input,int,isinstance,issubclass,len,list,map,max,min,object,ord,pow,print,property,py_TypeError,py_iter,py_metatype,py_next,py_reversed,py_typeof,range,repr,round,set,setattr,sorted,str,sum,tuple,zip}from"./org.transcrypt.__runtime__.js";var __name__="package.print_keys";export var print_keys=function(d){return d.py_keys()};
//# sourceMappingURL=package.print_keys.map
\ No newline at end of file
'use strict';import{AssertionError,AttributeError,BaseException,DeprecationWarning,Exception,IndexError,IterableError,KeyError,NotImplementedError,RuntimeWarning,StopIteration,UserWarning,ValueError,Warning,__JsIterator__,__PyIterator__,__Terminal__,__add__,__and__,__call__,__class__,__envir__,__eq__,__floordiv__,__ge__,__get__,__getcm__,__getitem__,__getslice__,__getsm__,__gt__,__i__,__iadd__,__iand__,__idiv__,__ijsmod__,__ilshift__,__imatmul__,__imod__,__imul__,__in__,__init__,__ior__,__ipow__,
__irshift__,__isub__,__ixor__,__jsUsePyNext__,__jsmod__,__k__,__kwargtrans__,__le__,__lshift__,__lt__,__matmul__,__mergefields__,__mergekwargtrans__,__mod__,__mul__,__ne__,__neg__,__nest__,__or__,__pow__,__pragma__,__proxy__,__pyUseJsNext__,__rshift__,__setitem__,__setproperty__,__setslice__,__sort__,__specialattrib__,__sub__,__super__,__t__,__terminal__,__truediv__,__withblock__,__xor__,abs,all,any,assert,bool,bytearray,bytes,callable,chr,copy,deepcopy,delattr,dict,dir,divmod,enumerate,filter,float,
getattr,hasattr,input,int,isinstance,issubclass,len,list,map,max,min,object,ord,pow,print,property,py_TypeError,py_iter,py_metatype,py_next,py_reversed,py_typeof,range,repr,round,set,setattr,sorted,str,sum,tuple,zip}from"./org.transcrypt.__runtime__.js";var __name__="package.print_vals";export var print_vals=function(d){return d.py_values()};
//# sourceMappingURL=package.print_vals.map
\ No newline at end of file
<html>
<head>
<script type="module">
import * as main from './main.js';
// Get fake data from the compiled python file.
var d = main.start_with_json_from_javascript({"moo": "dog", "face": 5});
// Add the fake data to the screen.
document.body.innerHTML = JSON.stringify(d);
</script>
<script>
</script>
</head>
<body>
</body>
</html>
from package import print_keys
from package import print_vals
def obj_to_dict(o):
"""This function takes an object passed from javascript and converts it
into a python dictionary.
:param o: The object from javascript.
:return: A python dictionary.
"""
d = {}
for key in [name for name in dir(o) if not name.startswith('__')]:
d[key] = getattr(o, key)
return d
def start_with_json_from_javascript(obj_from_javascript):
"""A function that takes an object from javascript and processes it to
extract fake data.
:param obj_from_javascript: The object from javascript.
:return: The processed data.
"""
a_dict = obj_to_dict(obj_from_javascript)
k = print_keys.print_keys(a_dict)
v = print_vals.print_vals(a_dict)
data = [k, v]
return data
def print_keys(d):
return d.keys()
def print_vals(d):
return d.values()
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment