Loading JavaScript library in Python using PyV8

I am trying to use some functions of the leaflet.js library in my Python code. And to execute JS commands in code, I use PyV8. But I can not load the leaflet.js library into the PyV8 context. When i do this

ctxt.eval(open("leaflet.js").read())

I get an error message:

ReferenceError: window is not defined (  @ 9 : 68 )  -> of t.coords[c]&&(u[c]=t.coords[c]);this.fire("locationfound",u)}})}(window,doc

I even tried downloading the jquery library before I thought that leaflets depend on it. But then I get an error,

TypeError: Cannot read property 'defaultView' of undefined (  @ 2 : 68 )  -> :!1},k=db.setDocument=function(a){var b,e=a?a.ownerDocument||a:t,g=e.defaultVi

Can I load the JS library successfully?

+4
source share
1 answer

, DOM, , , . mustache.js.

Edit: , , -, DOM - DOM, : https://github.com/rclark/server-side-leaflet. . , PyV8, .

Edit2: : , PyV8, javascript. , "" "", V8 . DOM , "", . rclark node.js , PyV8 .

DOM javascript, PyV8: https://github.com/andreasgal/dom.js/. js, PyV8, - , spidermonkey, V8. .

, , ( / ):

  • -, -, python , , -, OTR - . github . , . GPS
  • , , .
  • node.js rclark.
  • - DOM PyV8, , andreasgal, .
  • , DOM ( -, / , - if (typeof(window) === 'object' && window !== null){...}. , , .
+3

Source: https://habr.com/ru/post/1536704/


All Articles