{ "info": { "author": "Luke Granger-Brown & Alessandro Molina", "author_email": "python@lukegb.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: JavaScript", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "dukpy\n=====\n\n.. image:: https://travis-ci.org/lukegb/dukpy.png?branch=master \n :target: https://travis-ci.org/lukegb/dukpy \n\n.. image:: https://coveralls.io/repos/lukegb/dukpy/badge.png?branch=master\n :target: https://coveralls.io/r/lukegb/dukpy?branch=master \n\nDukPy is a simple javascript interpreter for Python built on top of\nduktape engine **without any external dependency**.\nIt comes with a bunch of common transpilers built-in for convenience:\n\n - *CoffeeScript*\n - *BabelJS*\n - *TypeScript*\n\nDukpy has been tested on **Python 3.4**, dukpy\nis currently not production ready and might actually crash your\nprogram as it is mostly implemented in C.\n\ndukpy-lukegb is a fork of Alessandro Molina's dukpy: https://github.com/amol-/dukpy\n\nCoffeeScript Compiler\n---------------------\n\nUsing the coffeescript compiler is as easy as running::\n\n >>> import dukpy\n >>> dukpy.coffee_compile('''\n ... fill = (container, liquid = \"coffee\") ->\n ... \"Filling the #{container} with #{liquid}...\"\n ... ''')\n '(function() {\\n var fill;\\n\\n fill = function*(container, liquid) {\\n if (liquid == null) {\\n liquid = \"coffee\";\\n }\\n return \"Filling the \" + container + \" with \" + liquid + \"...\";\\n };\\n\\n}).call(this);\\n'\n\nTypeScript Transpiler\n---------------------\n\nThe TypeScript compiler can be used through the ``dukpy.typescript_compile`` function::\n\n >>> import dukpy\n >>> dukpy.typescript_compile('''\n ... class Greeter {\n ... constructor(public greeting: string) { }\n ... greet() {\n ... return \"

\" + this.greeting + \"

\";\n ... }\n ... };\n ...\n ... var greeter = new Greeter(\"Hello, world!\");\n ... ''')\n 'var Greeter = (function () {\\n function Greeter(greeting) {\\n this.greeting = greeting;\\n }\\n Greeter.prototype.greet = function () {\\n return \"

\" + this.greeting + \"

\";\\n };\\n return Greeter;\\n})();\\n;\\nvar greeter = new Greeter(\"Hello, world!\");\\n'\n\nCurrently the compiler has built-in options and doesn't accept additional ones,\n\n\nEcmaScript6 BabelJS Transpiler\n------------------------------\n\nTo compile ES6 code to ES5 for everyday usage you can use ``dukpy.babel_compile``::\n\n >>> import dukpy\n >>> dukpy.babel_compile('''\n ... class Point {\n ... constructor(x, y) {\n ... this.x = x;\n ... this.y = y;\n ... }\n ... toString() {\n ... return '(' + this.x + ', ' + this.y + ')';\n ... }\n ... }\n ... ''')\n '\"use strict\";\\n\\nvar _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };\\n\\nvar _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } };\\n\\nvar Point = (function () {\\n function Point(x, y) {\\n _classCallCheck(this, Point);\\n\\n this.x = x;\\n this.y = y;\\n }\\n\\n _prototypeProperties(Point, null, {\\n toString: {\\n value: function toString() {\\n return \"(\" + this.x + \", \" + this.y + \")\";\\n },\\n writable: true,\\n configurable: true\\n }\\n });\\n\\n return Point;\\n})();\\n'\n\nThe DukPY based BabelJS compiler also provides a WebAssets ( http://webassets.readthedocs.org/en/latest/ ) filter to automatically compile ES6 code in your assets pipeline.\nYou register this filter as ``babeljs`` within WebAssets using::\n\n from webassets.filter import register_filter\n from dukpy.webassets import BabelJS\n \n register_filter(BabelJS)\n\nWhich makes the filter available with the ``babeljs`` name.\n\n**NOTE:** When using the BabelJS compiler for code that needs to run in the browser, make sure to add https://cdnjs.cloudflare.com/ajax/libs/babel-core/4.6.6/browser-polyfill.js dependency.\n\nUsing the JavaScript Interpreter\n--------------------------------\n\nUsing dukpy is as simple as calling the ``dukpy.evaljs`` function with\nthe javascript code::\n\n >>> import dukpy\n >>> dukpy.evaljs(\"var o = {'value': 5}; o['value'] += 3; o\")\n {'value': 8}\n\n\nThe ``evaljs`` function executes the javascript and returns the\nresulting value as far as it is possible to encode it in JSON.\n\nIf execution fails a ``dukpy.JSRuntimeError`` exception is raised\nwith the failure reason.\n\nPassing Arguments\n-----------------\n\nAny argument passed to ``evaljs`` is available in JavaScript inside\nthe ``dukpy`` object in javascript. It must be possible to encode\nthe arguments using JSON for them to be available in Javascript::\n\n >>> import dukpy\n >>>\n >>> def sum3(value):\n ... return dukpy.evaljs(\"dukpy['value'] + 3\", value=value)\n ...\n >>> sum3(7)\n 10\n\nRunning Multiple Scripts\n------------------------\n\nThe ``evaljs`` function supports providing multiple source codes to\nbe executed in the same context.\n\nMultiple script can be passed in a list or tuple::\n\n >>> import dukpy\n >>> dukpy.evaljs([\"var o = {'value': 5}\",\n ... \"o['value'] += 3\",\n ... \"o\"])\n {'value': 8}\n\nThis is useful when your code requires dependencies to work,\nas you can load the dependency and then your code.\n\nThis is actually how the coffeescript compiler is implemented\nby DukPy itself::\n\n def coffee_compile(source):\n with open(COFFEE_COMPILER, 'r') as coffeescript_js:\n return evaljs((coffeescript_js.read(), 'CoffeeScript.compile(dukpy.coffeecode)'),\n coffeecode=source)", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lukegb/dukpy", "keywords": "javascript compiler babeljs coffeescript", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dukpy-lukegb", "package_url": "https://pypi.org/project/dukpy-lukegb/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dukpy-lukegb/", "project_urls": { "Homepage": "https://github.com/lukegb/dukpy" }, "release_url": "https://pypi.org/project/dukpy-lukegb/0.2.2/", "requires_dist": null, "requires_python": "", "summary": "Simple JavaScript interpreter for Python", "version": "0.2.2" }, "last_serial": 1950071, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "378bb213575480178f336fb96694bc64", "sha256": "f8f882aa2013144b7cd0b874b35a3c56e5ad111d63be6b91b2c2d9f99d099219" }, "downloads": -1, "filename": "dukpy-lukegb-0.0.2.tar.gz", "has_sig": true, "md5_digest": "378bb213575480178f336fb96694bc64", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1435117, "upload_time": "2016-01-12T18:54:23", "url": "https://files.pythonhosted.org/packages/78/d7/a3cf4bbc4897cb9cd5ffcbce9df5dcd28c7d3eb8d55ead02ff31ad6ae54d/dukpy-lukegb-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "b4103f015cd11294d62872abea2da1e2", "sha256": "86dcf7aebf58a1774f22a4b6b13d6a15129eab0481ddfabfe55878914b1ed1e7" }, "downloads": -1, "filename": "dukpy-lukegb-0.1.0.tar.gz", "has_sig": true, "md5_digest": "b4103f015cd11294d62872abea2da1e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1597780, "upload_time": "2016-01-13T22:00:48", "url": "https://files.pythonhosted.org/packages/35/46/9bc330c11e1985f03839dfcada17620870b5be8fb56392e5fde075e9b478/dukpy-lukegb-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "aac5050c5ebe85f444624f9d31505af0", "sha256": "766494f8cb8dcc03c67d6540288374dacb059ed36a11ecb58614558072c81b58" }, "downloads": -1, "filename": "dukpy-lukegb-0.2.0.tar.gz", "has_sig": true, "md5_digest": "aac5050c5ebe85f444624f9d31505af0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1600146, "upload_time": "2016-01-15T22:23:15", "url": "https://files.pythonhosted.org/packages/ca/a0/60f9a3301360aa5d098f922decbeb3b35e591af31d8d96e51d47b3cb0df9/dukpy-lukegb-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "a0f56beb6e0957db5af769fe8b81c9a2", "sha256": "9d8f89f085fed963fb8b6878fb2f21350ed62bea771cd2477ca7b52eb3eccf47" }, "downloads": -1, "filename": "dukpy_lukegb-0.2.1-cp27-none-win32.whl", "has_sig": false, "md5_digest": "a0f56beb6e0957db5af769fe8b81c9a2", "packagetype": "bdist_wheel", "python_version": "cp27", "requires_python": null, "size": 892013, "upload_time": "2016-01-17T16:37:35", "url": "https://files.pythonhosted.org/packages/83/a9/5968e07794230e9de8c42841e2db87f06353b8253be23b4fa3eb0dea1c39/dukpy_lukegb-0.2.1-cp27-none-win32.whl" }, { "comment_text": "", "digests": { "md5": "c888d145e071850a7692f00b64bfabab", "sha256": "ae1076cf1db511ec00fd195ef96d90f2f756040a63a46859926365b870605e50" }, "downloads": -1, "filename": "dukpy_lukegb-0.2.1-cp35-none-win32.whl", "has_sig": false, "md5_digest": "c888d145e071850a7692f00b64bfabab", "packagetype": "bdist_wheel", "python_version": "cp35", "requires_python": null, "size": 890716, "upload_time": "2016-01-17T16:37:42", "url": "https://files.pythonhosted.org/packages/cb/ba/7079a3c65c30846fc1ae15eadc43d953a1ea4f5dc8775c3bc07e3cfd70e2/dukpy_lukegb-0.2.1-cp35-none-win32.whl" }, { "comment_text": "", "digests": { "md5": "15a732c29641292574b652abe12db986", "sha256": "d0eaaccd1bff28fcd4f548aafae40722f53d85ec93f997e7acb65c4253968c99" }, "downloads": -1, "filename": "dukpy-lukegb-0.2.1.tar.gz", "has_sig": true, "md5_digest": "15a732c29641292574b652abe12db986", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1600388, "upload_time": "2016-01-15T23:09:24", "url": "https://files.pythonhosted.org/packages/45/19/8b6411077565a686c111c68e94dcaf1758c0ac2eeadf6886611bc45bff72/dukpy-lukegb-0.2.1.tar.gz" }, { "comment_text": "", "digests": { "md5": "80e92720f872aefb06db57dad08f837c", "sha256": "5447be83e2e3ad13bd4e455877aabefc2bd1fc8125a6b907751f66cd10eb679f" }, "downloads": -1, "filename": "dukpy-lukegb-0.2.1.win32-py2.7.msi", "has_sig": false, "md5_digest": "80e92720f872aefb06db57dad08f837c", "packagetype": "bdist_msi", "python_version": "2.7", "requires_python": null, "size": 1032192, "upload_time": "2016-01-17T16:38:14", "url": "https://files.pythonhosted.org/packages/99/34/b40271a8abaf4badeacd6fe062c0a936f5c9e7e94f375e74d36cf070c14f/dukpy-lukegb-0.2.1.win32-py2.7.msi" }, { "comment_text": "", "digests": { "md5": "b847ccef161142c9ce800f22dec8275f", "sha256": "99b2a4ddfd2a09d3497e0b93b6107d5e4ed6d8be76f71637a7f56919ee67f3b2" }, "downloads": -1, "filename": "dukpy-lukegb-0.2.1.win32-py3.5.msi", "has_sig": false, "md5_digest": "b847ccef161142c9ce800f22dec8275f", "packagetype": "bdist_msi", "python_version": "3.5", "requires_python": null, "size": 974848, "upload_time": "2016-01-17T16:38:32", "url": "https://files.pythonhosted.org/packages/3a/01/cddd278bc06397d976ef8901e06823d2813d72a8bad9cb0f7a4aad4a795e/dukpy-lukegb-0.2.1.win32-py3.5.msi" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "f52cd5aebf3deb458bd000319324d0d4", "sha256": "a94b770ccaafb0e0b276ffc719d4aebbc7ddaf10e2333fd8a6fe2aedf1245435" }, "downloads": -1, "filename": "dukpy-lukegb-0.2.2.tar.gz", "has_sig": true, "md5_digest": "f52cd5aebf3deb458bd000319324d0d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1601253, "upload_time": "2016-02-10T21:48:33", "url": "https://files.pythonhosted.org/packages/a9/f7/d7de4ef597198ee017688c2e3a252f3cebcd9d66691d0bfab5507986a6d4/dukpy-lukegb-0.2.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f52cd5aebf3deb458bd000319324d0d4", "sha256": "a94b770ccaafb0e0b276ffc719d4aebbc7ddaf10e2333fd8a6fe2aedf1245435" }, "downloads": -1, "filename": "dukpy-lukegb-0.2.2.tar.gz", "has_sig": true, "md5_digest": "f52cd5aebf3deb458bd000319324d0d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1601253, "upload_time": "2016-02-10T21:48:33", "url": "https://files.pythonhosted.org/packages/a9/f7/d7de4ef597198ee017688c2e3a252f3cebcd9d66691d0bfab5507986a6d4/dukpy-lukegb-0.2.2.tar.gz" } ] }