sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Regression due to refactoring of importing a .py modules #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Tested with FF 17.0.1 / Linux with Brython-20130108-223010.zip

1. In function $import(module):
when failing to import the module as JS, PY version is not tried
because in on my version of FF the error returned does not match the
expected one

< if(err.name==="NotFoundError"){

---
> if(err.name==="NotFoundError" || err.name==="NS_ERROR_DOM_BAD_URI"){

2. In function $import_py(module)
the following line seems to be missing

 }
 $xmlhttp.open('GET',module+'.py'+fake_qs,false)
+if('overrideMimeType' in $xmlhttp {
+ $xmlhttp.overrideMimeType("text/plain")}
 $xmlhttp.send()
 if(res.constructor===Error){throw res}

3. with those fixes, importing the following module fails

print("xxx")

def f(x):
    pass

with an error:
ExecutionError: this.list[i] is undefined
module '__main__' line 1
import a @ file:///mnt/prz/tools/snipsets/kanban/brython.js:3445

simply commenting out "f" declaration works fine, "print" is done
It seems that indentation screw analysis of imported module

Original issue reported on code.google.com by pedro.ro...@gmail.com on 9 Jan 2013 at 9:36

GoogleCodeExporter commented 9 years ago
The second bug is fixed in rev 392. It was because of a bad counting of opening 
and closing brackets...
I couldn't reproduce the first bug in the latest version so I leave the issue 
open in case it's still not fixed

Original comment by pierre.q...@gmail.com on 9 Jan 2013 at 10:09

GoogleCodeExporter commented 9 years ago
rev 392 seems to only contain a white space removal at end of a comment

Original comment by pedro.ro...@gmail.com on 9 Jan 2013 at 10:44

GoogleCodeExporter commented 9 years ago
With version // version 1.0.20130111-000752
1. Without the patch adding the test of NS_ERROR_DOM_BAD_URI,
   I cannot import a module with FF 17.0.1

2. Without the patch setting the mime type to "text/plain",
   a simple module with print("whatever") succeeds,
   but the navigator reports also a "not well formed" error
   probably because it tried to import it as xml by default

3. This error does not appear anymore

Original comment by pedro.ro...@gmail.com on 11 Jan 2013 at 9:55

GoogleCodeExporter commented 9 years ago
NS_ERROR_DOM_BAD_URI is often the result if you try to do AJAX calls from a 
file opened with the file:// protocol in Firefox.
Seeing NS_ERROR_DOM_BAD_URI might not be limited to just this case, I don't 
think it would be a good idea to assume that means the same as NotFoundError.

Instead you should host the files in a web server and access them through that.

Original comment by hekses...@gmail.com on 15 Apr 2013 at 10:35

GoogleCodeExporter commented 9 years ago
@kekses...
Web server was not an option since I wanted light client side only bryth-lets.

You're certainly right about the fact that this error does not exactly means
NotFoundError. 

My understanding is, that it could also be raised due to security issues (cross 
domain looking).

But still in the end, at the time the issue was raised, the lookup mechanism 
was supposed to be trying another file (.py) that will have succeeded and it 
didn't.

Possibly catching something like "ImportFailedError" (as if it was some base 
class for "NotFoundError") could have been better.

But since the project has moved quite a lot since then, I don't know if this 
issue is still meaningful and should probably closed.

Original comment by pedro.ro...@gmail.com on 18 Apr 2013 at 4:35