brython-dev / brython Goto Github PK
View Code? Open in Web Editor NEWBrython (Browser Python) is an implementation of Python 3 running in the browser
License: BSD 3-Clause "New" or "Revised" License
Brython (Browser Python) is an implementation of Python 3 running in the browser
License: BSD 3-Clause "New" or "Revised" License
After seeing your announcement in comp.lang.python, I tried out the console briefly, looking to see how the system identified itself. I noticed that "import platform" failed with this error (after an extremely long pause):
Apologies for the screen grab. The region wouldn't stay selected long enough for me to copy it (Chrome v38.0.2125.122 on Mac OS X 10.9.5).
Copied from old github repo:
Couple issues I noticed using datetime and time:
In general, there are some string formatting issues. I will work on it opening small issues. This one is related with signed integer decimals using old string formatting.
Some of the following tests fail:
assert "%5d" % 3 == ' 3'
assert "%5d" % 3.3 == ' 3'
assert "%5.2d" % 3 == ' 03'
assert "%+5d" % 3 == ' +3'
assert "%-5d" % 3 == '3 '
assert "%#5d" % 3 == ' 3'
assert "%05d" % 3 == '00003'
assert "%+05d" % 3 == '+0003'
assert "%5i" % 3 == ' 3'
assert "%5i" % 3.3 == ' 3'
assert "%5.2i" % 3 == ' 03'
assert "%+5i" % 3 == ' +3'
assert "%-5i" % 3 == '3 '
assert "%#5i" % 3 == ' 3'
assert "%05i" % 3 == '00003'
assert "%+05i" % 3 == '+0003'
I will try to work on it during the following days. And when finished I will open new isues regarding this topic (string formatting).
Kind regards.
Slice implementation fails for some cases, like the following:
print([1,2,3][:3])
Brython -> [1, 2, 3]
CPython 3.4 -> The same
print([1,2,3][:4])
Brython -> [1, 2, 3, None]
CPython 3.4 -> [1,2,3]
print([1,2,3][2:6])
Brython -> [3, None, None, None]
CPython 3.4 -> [3]
print([1,2,3][3:0:-1])
Brython -> [None, 3, 2, 1]
CPython 3.4 -> [3,2]
It seems that the "None"s should not be included, however the last case fails by including the 1 when should be stopped before..
There is a stack overflow answer where one can base the fix (http://stackoverflow.com/a/12216257), which is based on this CPython implementation (https://hg.python.org/cpython/file/3d4d52e47431/Objects/sliceobject.c#l132)..
I'll see if I can fix it myself..
class ToDir:
def init(self):
pass
instanceToDir = ToDir()
dictToDir=({k: getattr(instanceToDir,k) for k in dir(instanceToDir) if '__' not in k})
castdictToDir=({str(k): getattr(instanceToDir,k) for k in dir(instanceToDir) if '__' not in k})
assert 'init' in castdictToDir, 'init not in castdictToDir: %s' % list(dictToDir.keys())
assert castdictToDir["init"]==instanceToDir.init , 'init not init method: %s' % castdictToDir["init"]
assert 'init' in dictToDir, 'init not in dictToDir: %s' % list(dictToDir.keys())
assert dictToDir["init"]==instanceToDir.init , 'init not init method: %s' % dictToDir["init"]
pass the assertions
Traceback (most recent call last):
module __main__ line 11
assert dictToDir["init"]==instanceToDir.init , 'init not init method: %s' % dictToDir["init"]
KeyError: init
<completed in 93.00 ms>
Brython version: 2.2.1 (online Brython.info)
Ubuntu Gnome 14.04 - Firefox 32
Works ok in Python 3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class ToDir:
... def init(self):
... pass
...
>>> instanceToDir = ToDir()
>>> dictToDir=({k: getattr(instanceToDir,k) for k in dir(instanceToDir) if '__' not in k})
>>> castdictToDir=({str(k): getattr(instanceToDir,k) for k in dir(instanceToDir) if '__' not in k})
>>> assert 'init' in castdictToDir, 'init not in castdictToDir: %s' % list(dictToDir.keys())
>>> assert castdictToDir["init"]==instanceToDir.init , 'init not init method: %s' % castdictToDir["init"]
>>> assert 'init' in dictToDir, 'init not in dictToDir: %s' % list(dictToDir.keys())
>>> assert dictToDir["init"]==instanceToDir.init , 'init not init method: %s' % dictToDir["init"]
>>>
Hi,
I only recently tested Brython and am pretty amazed - thanks for providing this implementation!
While experimentig in the interactive mode, I noticed an unexpected behaviour for larger ints, which may indicate silent overflows; floats are more sensible in this case. cf. the following results (using Opera 27 dev on win 7):
Brython 3.0.0 on Netscape 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2188.2 Safari/537.36 OPR/27.0.1683.0 (Edition developer)
[(x,2x) for x in range(68,80)]
[(68, 295147905179352830000), (69, 590295810358705700000), (70, 1), (71, 2), (72, 4), (73, 9), (74, 1), (75, 3), (76, 7), (77, 1), (78, 3), (79, 6)]
[(x,2.0x) for x in range(68,80)]
[(68, 295147905179352830000.0), (69, 590295810358705700000.0), (70, 1.1805916207174113e+21), (71, 2.3611832414348226e+21), (72, 4.722366482869645e+21), (73, 9.44473296573929e+21), (74, 1.888946593147858e+22), (75, 3.777893186295716e+22), (76, 7.555786372591432e+22), (77, 1.5111572745182865e+23), (78, 3.022314549036573e+23), (79, 6.044629098073146e+23)]Some oddities also appear at the bounds of the float type - the integers start to appear as NaNs:
[(x,2x) for x in range(1020,1030)]
[(1020, 1), (1021, 2), (1022, 4), (1023, 8), (1024, NaN), (1025, NaN), (1026, NaN), (1027, NaN), (1028, NaN), (1029, NaN)]
[(x,2.0x) for x in range(1020,1030)]
[(1020, 1.1235582092889474e+307), (1021, 2.247116418577895e+307), (1022, 4.49423283715579e+307), (1023, 8.98846567431158e+307), (1024, inf), (1025, inf), (1026, inf), (1027, inf), (1028, inf), (1029, inf)]
I currently don't have usecases for such calculations in Brython, but I'd prefer a more transparent handling of these cases; probably raising an exception (as the generally unlimited precission of int in python probably isn't available in the underlying javascript).
regards,
vbr
Its a wide spread convention to use .min.js
for Libraries for Web,
I think its a good idea to use a shorter and more common URL,
we leave the old one for compatibility purposes but start using the new one, I suggest:
http://brython.info/src/brython_dist.js
to http://brython.info/brython.min.js
That can be done on the server, what do you think @PierreQuentel ?, can you do it ?
I can change the Docs to reflect that.
Please, have a look to brython-dev/brython-in-the-classroom#11
If you think it is a good idea I could include that also in the 'official' Brython editor
C:\Users\Andre\reeborg\src\libraries\brython3\Lib\site-packages>python3
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_sp
>>> a = {'x': 1}
>>> test_sp.__dict__.update(a)
>>> print(test_sp.x)
1
From doing the same with Brython 3.0.0
import test_sp
a = {'x': 1}
test_sp.__dict__.update(a)
print(test_sp.x)
The result is
Traceback (most recent call last):
module __main__ line 4
print(test_sp.x)
AttributeError: 'module' object has no attribute 'x'
<completed in 7.00 ms>
The following code does not work with Brython 3 :
class MatrixError(BaseException):
pass
The performance is really suboptimal. Looking at the code, it quickly becomes clear why: To find an object, the whole dictionary is searched in a loop (i.e.
Line 68 in e1dc7b4
From a standard Python session:
C:\Users\Andre\reeborg\src\libraries\brython\Lib\site-packages>python3
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_sp
>>> print(test_sp.test)
site package
>>> s = 'a=3'
>>> exec(s, test_sp.__dict__)
>>> print(test_sp.a)
3
Using Brython 3.0.0 from http://brython.info/tests/editor.html
import test_sp
print(test_sp.test)
s = 'a=3'
exec(s, test_sp.__dict__)
print(test_sp.a)
======== output is below
site package
Traceback (most recent call last):
module __main__ line 18
print(test_sp.a)
AttributeError: 'module' object has no attribute 'a'
<completed in 26.00 ms>
in http://brython.info/tests/console.html, running the following shows the docstring as "output"
>>> def a():
... '''doc_string'''
... return 1
...
'doc_string' <--- should not be there
>>>
code:
import inspect
result:
Traceback (most recent call last):
module importlib line 21
_bootstrap._setup(sys, _imp)
module importlib._bootstrap line 1721
builtin_module = BuiltinImporter.load_module(builtin_name)
module importlib._bootstrap line 495
module = fxn(_args, *_kwargs)
module importlib._bootstrap line 508
module = fxn(self, _args, *_kwargs)
module importlib._bootstrap line 1131
module = _call_with_frames_removed(_imp.load_dynamic,
AttributeError: 'BuiltinImporter' object has no attribute 'path'
<completed in 1155.00 ms>
๐
As per the discussion on google groups, this is the issue to alter how brython code is compiled to javascript, which isolates javascript keywords from brython. Javascript defined variables and functions would be accessed via browser.window
.
Note that this may require tweaking JSObject
behavior before this can be used since this would be a breaking change for all javascript external library interaction.
The change would be to fundamentally change how things are compiled:
a = null
would become (paraphrased):
modules['__main__']['a'] = modules['__main__']['null']
Acceptance:
null
, true
, false
, localStorage
, etc should raise a NameError
i = 5
def foo():
def bar():
print(i)
for i in range(5):
pass
bar()
Brython 2.2 [1] on Netscape 5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36
>>> 5 < 10 < 5 * 10 < 100
TypeError: Cannot read property 'to_js' of undefined
module '__main__' line 56
_ = exec(currentLine,editor_ns)
>>> 5 < 10 < 5 * 10
True
>>> 10 < 5 * 10 < 100
True
>>> 5 < 10 < 100
True
>>>
Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux
>>> 5 < 10 < 5 * 10 < 100
True
>>> 5 < 10 < 5 * 10
True
>>> 10 < 5 * 10 < 100
True
>>> 5 < 10 < 100
True
>>>
๐ฃ ๐ณ
It appears that using a built-in function after a range statement results in "TypeError: undefined is not a function"
for i in range(2):
print(i)
print("here")
0
1
RuntimeError: TypeError: undefined is not a function
Inserting a pass statement afterwards works around it
for i in range(2):
print(i)
pass
print("here")
tested with print
, eval
, exec
, and type
built in functions
<script type='text/python3'>
print(foo)
</script>
expected:
print(foo)
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
print(foo)
NameError: name 'foo' is not defined
actual:
arg 0 undef in print
Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux
>>> slice()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: slice expected at least 1 arguments, got 0
>>> slice( , )
File "<stdin>", line 1
slice( , )
^
SyntaxError: invalid syntax
>>> slice(1, )
slice(None, 1, None)
>>>
Brython 2.2 [1] on Netscape 5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36
>>>
>>> slice()
slice(0,0)
>>> slice( , )
slice(0,0)
>>> slice(1, )
slice(0,1)
>>>
๐ฃ ๐ฅ
Code is available at https://bitbucket.org/olemis/brython/src. Visit the Brython site for demos and documentation
Uncomment the following else clause to see the error.
if eval("1+1"):
print("ok")
#else:
#print("not ok")
this is with Brython version 2.2.1 as tested on http://brython.info/tests/editor.html (Note: indentating is shown incorrectly here.)
Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux
>>>
>>> print(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255)
File "<stdin>", line 1
SyntaxError: more than 255 arguments
>>>
Brython 2.2 [1] on Netscape 5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36
>>>
>>> print(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
>>>
You can review the code here, to see its fully intended that way:
Basically:
๐
Brython 3.0.0 on Netscape 5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/38.0.2125.111 Chrome/38.0.2125.111 Safari/537.36
>>> from browser import document, svg
>>> document["main"] <= svg.svg(id="test")
>>> document["test"] <= svg.text("testing", stroke="red", stroke_width="9")
Returns Broken attributes, invalid as SVG XML:
<text stroke="red" stroke_width="9">testing</text>
(stroke_width its not working)
This should be:
<text stroke="red" stroke-width="9">testing</text>
๐ซ
Hi everyone,
Many thanks for the great implementation, I'm very impressed with Brython,
I've attempted to replicate the HighStocks demo found here in Brython, with some success ( gist, jfiddle). However I've encountered two issues which may be related.
First, dates in the tooltip are displayed in JSON time not "Weekday, Month, Day, Year" format. This appears to occurs for small views only. For instance, if one selects the entire time series, the tooltip dates are displayed correctly.
Second, some odd behavior occurs with the size of the data array passed to the chart. For instance, if I truncate the data array to size 1000 (or less), then the dates are erroneously displayed around the UNIX epoch. See the following: gist, jfiddle.
Neither of these problems occur in the pure javascript version (see here), so I'm lead to believe that the issue lies with Brython. Can anyone clarify why this happens? The help would be really appreciated...
Thanks!
zipfile.py from the std lib (at ~ line 1290) contains the following lines of code, which is currently generating a syntax error in brython:
with self.open(member, pwd=pwd) as source, \
open(targetpath, "wb") as target:
shutil.copyfileobj(source, target)
return targetpath
file1:
import brythontest2
brythontest2.xxx = 123
print(brythontest2.xxx)
print(brythontest2.yyy())
brythontest2.py:
def yyy():
return xxx*2
...
"123
" brython.js:4851
"RuntimeError: ReferenceError: xxx is not defined
Traceback (most recent call last):
module brythontest2 line 2
return xxx*2" brython.js:4849
Context:
5c5c44e#commitcomment-8631942
๐
This isssue is likely related to issue #62
C:\Users\Andre\reeborg\src\libraries\brython\Lib\site-packages>python3
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_sp
>>> test_sp.__dict__['a'] = 3
>>> test_sp.a
3
Using Brython 3.0 from http://brython.info/tests/editor.html
import test_sp
test_sp.__dict__['a'] = 3
print(test_sp.a)
====== output
Traceback (most recent call last):
module __main__ line 13
print(test_sp.a)
AttributeError: 'module' object has no attribute 'a'
Enter the following inhttp://brython.info/tests/editor.html
def a():
'''doc'''
return 1
help(a) # initially takes 8.7 seconds and always returns incorrect info
Expected output:
>>> help(a)
Help on function a in module __main__:
a()
doc
>>>
Observed output:
no Python documentation found for 'a'
<completed in ... ms>
from collections import abc
...
Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost:8000/sec_shit/brython-test.py". jello.html:5
Error: unknown encoding: windows-1250 for module collections.abc brython.js:7137
info Traceback (most recent call last):
module collections.abc line 28
bytes_iterator = type(iter(b'')) brython.js:7138
message unknown encoding: windows-1250
happens in my chrome but not in my firefox, adding case 'windows-1250':
somewhere in brython.js is easy, but no idea what the implications are.
again. a small issue
class Number(object):
pass
assert Number.__name__ == 'Number'
this and my previous issue ( object 'super' has no attribute 'init' ) arent really showstoppers tho
I've found what I think is a precedence bug in Brython:
The expression
a if b else c*d
should be parsed as
a if b else (c*d)
and it is in CPython (2 and 3), but in Brython it seems to be parsed as
(a if b else c)*d
Example:
print(1 if True else 2*3, 1 if False else 2*3)
prints
CPython: (1,6)
Brython: (3,6)
Assignment isn't allowed with eval. Brython currently accepts it.
eval("a = 5")
Expected:
>>> eval("a = 5")
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
eval("a = 5")
File "<string>", line 1
a = 5
^
SyntaxError: invalid syntax
Arguably this is low priority.
TypeError
with or without capitalized *args.Brython 3.0.0 on Netscape 5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/38.0.2125.111 Chrome/38.0.2125.111 Safari/537.36
>>> from browser import html
>>> html.P("test").html
'test'
>>> html.P("test", style="color:white").html
TypeError: Cannot read property 'length' of undefined
module 'exec-t4fzjolc' line 1
html.P("test", style="color:white").html
module 'exec-t4fzjolc' line 1
html.P("test", style="color:white").html
>>> html.P("test", Style="color:white").html
TypeError: Cannot read property 'length' of undefined
module 'exec-xqs5klx9' line 1
html.P("test", Style="color:white").html
module 'exec-xqs5klx9' line 1
html.P("test", Style="color:white").html
>>>
Dict implementation is not compliant with CPython on some cases, for instance:
Brython
a = {[1,2]: 2}
print(a[[1,2]])2
CPython
a = {[1,2]: 2}
TypeError: unhashable type: 'list'
print(a[[1,2]])
TypeError: string indices must be integers
Also, the dict implementation is quite slow by being based on JS Arrays. This jsperf (http://jsperf.com/dict-vs-array-lookup) compares array lookup vs direct dict lookups and dict lookups is almost 2000% faster for a case of a key not in the beginning of the keys array. This indicates that an approach based on JS dicts would take advantage of proportional increases in speed.
I am willing to implement something like this, but would need to discuss it because I'm not fully aware of some of Brython's internal mechanisms.
I can not truly confirm the following since I simply applied a patch "by hand" to my local brython.js file so as to reproduce the fix for issue 62 and 63. However, if I do:
import my_lib
my_lib.__dict__['a'] = 42
del my_lib.__dict__['a']
print(my_lib.a)
I get 42 as output instead of AttributeError
Comes from: #52 (comment)
I like the look of these pages, and the font, but there are a couple of problems with the background :
assert(__debug__)
AssertionError: AssertionError
Traceback (most recent call last):
module __main__ line 1
assert(__debug__)
from python docs:
The simple form, assert expression, is equivalent to
if __debug__:
if not expression: raise AssertionError
again, not a biggie:)
Lists behave like javascript lists in Brython
>>> l = list()
>>> l[3] = "hello"
>>> print(l)
[None, None, None, 'hello']
As suggested by @jameshutchinson and in order to allow users use custom tags the following could be added to the html module:
from browser.html import CustomTag
mytag = CustomTag('EXPERIMENTALHTML5TAG')
Ideas, suggestions, pros, cons,...?
Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help
Type help() for interactive help, or help(object) for help about object.
>>> copyright()
Copyright (c) 2001-2014 Python Software Foundation.
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.
>>> credits()
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information.
>>>
Brython 2.2 [1] on Netscape 5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36
>>>
>>> help()
Define the builtin 'help'.
This is a wrapper around pydoc.help (with a twist).
>>> license()
NameError: license is not defined
module 'editor_ns' line 1
>>> credits()
NameError: credits is not defined
module 'editor_ns' line 1
>>> copyright()
NameError: copyright is not defined
module 'editor_ns' line 1
copyright
>>> credits()
NameError: credits is not defined
module 'editor_ns' line 1
credits
>>>
๐ฃ ๐ฅ
I think we should have two repos, one for brython source, and the site
tests, unit tests, code coverage, etc (developer stuff).
The second one should be all the other stuff under site (gallery, examples,
documentation, editor, console, etc). (user stuff).
( Moved from Original Bug at https://github.com/PierreQuentel/brython/issues/9 )
The re module results in a very large performance hit when it's imported. It also fails this regex I encountered:
import re
a = 'hello() abcdefg'
re.match('''(.*?)(\S+)\Z''', a)
This should match the string given but it doesn't.
I want to implement this Markup:
<picture>
<source media="(min-width: 40em)" srcset="big.jpg 1x, big-hd.jpg 2x">
<source srcset="small.jpg 1x, small-hd.jpg 2x">
<img src="fallback.jpg">
</picture>
Brython Traceback:
>>> from browser import html
>>> html.PICTURE()
Traceback (most recent call last):
module editor_ns line 1
html.PICTURE()
AttributeError: 'module' object has no attribute 'PICTURE'
Links:
Although the message says github, the link leads to bitbucket repository
Brython is not respecting the "count" parameter in str.replace. Str.replace has the following signature (https://docs.python.org/3/library/stdtypes.html#str.replace):
str.replace(old, new[, count])
In CPython 3.4:
"AAA".replace("A","B",1)
"BAA"
In Brython:
"AAA".replace("A","B",1)
"BBB"
Another bad behavior in Brython :
l = []
l[1] = "test"
The above snippet of code is correct in JS but not in Python.
It is also abnormaly accepted by Brython.
Submitted by Nicolas Pinaul on google groups discussion 'javascript vs python namespaces' on 9/22/2014
This seems like it is necessary for #16
Presently, javascript objects can be referenced directly from Brython, but must be cast to a JSObject in order to be interacted with.
Example:
from javascript import JSObject
jq = JSObject(jQuery.noConflict(true))
This does not work, for one reason or another:
from browser import window
jq = window.jQuery.noConflict(True)
Ideally, the second situation should work, since it would be pure Python. It seems like in order to accomplish this, JSObject needs to automatically convert attributes to Python and convert arguments from Python to javascript.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.