Using firefox 17.0.1, put the following files in temporary folder
(see content below)
x.html
a.py
brython.js
x.html reports the following messages in the console:
not well-formed @ file:///tmp/zzz/a.py?foo=ot45ebsl:1
ImportError: ImportError: No module named 'a'
Line 1
import a @ file:///tmp/zzz/brython.js:2839
My understanding of the issues is that
- there is no http request issued (local browsing),
and the browser has to guess the type of the file imported
and got it wrong :(
- when the file is loaded, the status of the XMLHttpRequest is not 200,
but 0 (probably because of local browsing)
Patching function $import() this way improve the situation in the given context
--- zzz/brython.js 2012-12-28 19:24:32.661336728 +0100
+++ repos/brython-read-only/brython.js 2012-12-28 11:09:18.849140441 +0100
@@ -272,11 +272,10 @@
}else{
var $xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
+$xmlhttp.overrideMimeType("text/plain")
$xmlhttp.onreadystatechange=function(){
if($xmlhttp.readyState==4){
window.clearTimeout(timer)
-if($xmlhttp.status==200){res=$xmlhttp.responseText}
+if($xmlhttp.status==200 || $xmlhttp.status==0){res=$xmlhttp.responseText}
else{
document.$context=calling.context
document.line_num=calling.line
------------------------------------------------------------------
x.html
------------------------------------------------------------------
<html>
<head>
<title>Test import</title>
<meta charset="utf-8"/>
<script src="brython.js"></script>
</head>
<body onLoad="brython()">
<script type="text/python">
import a
</script>
<p>Test Import</p>
</body>
</html>
------------------------------------------------------------------
a.py
------------------------------------------------------------------
print(1)
Original issue reported on code.google.com by pedro.ro...@gmail.com on 28 Dec 2012 at 6:40
Original issue reported on code.google.com by
pedro.ro...@gmail.com
on 28 Dec 2012 at 6:40