Skip to content

Commit 96ac36d

Browse files
committed
updated brython version
discvered how to add extra modules through js + added the option of setting the input handler while still keeping the default behavior of calling the brython built in input method. - made it so that should input change during debug session run to just immidiatly call the input handler > this is because otherwise reruning the code would never end as stdin gets reset + added a flag noInputTrace for running code without injecting input trace calls - made it so that runNoTrace resets the dbugger
1 parent de0829e commit 96ac36d

File tree

27 files changed

+1353
-663
lines changed

27 files changed

+1353
-663
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
"""Record of phased-in incompatible language changes.
2+
3+
Each line is of the form:
4+
5+
FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
6+
CompilerFlag ")"
7+
8+
where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
9+
of the same form as sys.version_info:
10+
11+
(PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
12+
PY_MINOR_VERSION, # the 1; an int
13+
PY_MICRO_VERSION, # the 0; an int
14+
PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
15+
PY_RELEASE_SERIAL # the 3; an int
16+
)
17+
18+
OptionalRelease records the first release in which
19+
20+
from __future__ import FeatureName
21+
22+
was accepted.
23+
24+
In the case of MandatoryReleases that have not yet occurred,
25+
MandatoryRelease predicts the release in which the feature will become part
26+
of the language.
27+
28+
Else MandatoryRelease records when the feature became part of the language;
29+
in releases at or after that, modules no longer need
30+
31+
from __future__ import FeatureName
32+
33+
to use the feature in question, but may continue to use such imports.
34+
35+
MandatoryRelease may also be None, meaning that a planned feature got
36+
dropped.
37+
38+
Instances of class _Feature have two corresponding methods,
39+
.getOptionalRelease() and .getMandatoryRelease().
40+
41+
CompilerFlag is the (bitfield) flag that should be passed in the fourth
42+
argument to the builtin function compile() to enable the feature in
43+
dynamically compiled code. This flag is stored in the .compiler_flag
44+
attribute on _Future instances. These values must match the appropriate
45+
#defines of CO_xxx flags in Include/compile.h.
46+
47+
No feature line is ever to be deleted from this file.
48+
"""
49+
50+
all_feature_names = [
51+
"nested_scopes",
52+
"generators",
53+
"division",
54+
"absolute_import",
55+
"with_statement",
56+
"print_function",
57+
"unicode_literals",
58+
"barry_as_FLUFL",
59+
]
60+
61+
__all__ = ["all_feature_names"] + all_feature_names
62+
63+
# The CO_xxx symbols are defined here under the same names used by
64+
# compile.h, so that an editor search will find them here. However,
65+
# they're not exported in __all__, because they don't really belong to
66+
# this module.
67+
CO_NESTED = 0x0010 # nested_scopes
68+
CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
69+
CO_FUTURE_DIVISION = 0x2000 # division
70+
CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
71+
CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
72+
CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
73+
CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals
74+
CO_FUTURE_BARRY_AS_BDFL = 0x40000
75+
76+
class _Feature:
77+
def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
78+
self.optional = optionalRelease
79+
self.mandatory = mandatoryRelease
80+
self.compiler_flag = compiler_flag
81+
82+
def getOptionalRelease(self):
83+
"""Return first release in which this feature was recognized.
84+
85+
This is a 5-tuple, of the same form as sys.version_info.
86+
"""
87+
88+
return self.optional
89+
90+
def getMandatoryRelease(self):
91+
"""Return release in which this feature will become mandatory.
92+
93+
This is a 5-tuple, of the same form as sys.version_info, or, if
94+
the feature was dropped, is None.
95+
"""
96+
97+
return self.mandatory
98+
99+
def __repr__(self):
100+
return "_Feature" + repr((self.optional,
101+
self.mandatory,
102+
self.compiler_flag))
103+
104+
nested_scopes = _Feature((2, 1, 0, "beta", 1),
105+
(2, 2, 0, "alpha", 0),
106+
CO_NESTED)
107+
108+
generators = _Feature((2, 2, 0, "alpha", 1),
109+
(2, 3, 0, "final", 0),
110+
CO_GENERATOR_ALLOWED)
111+
112+
division = _Feature((2, 2, 0, "alpha", 2),
113+
(3, 0, 0, "alpha", 0),
114+
CO_FUTURE_DIVISION)
115+
116+
absolute_import = _Feature((2, 5, 0, "alpha", 1),
117+
(3, 0, 0, "alpha", 0),
118+
CO_FUTURE_ABSOLUTE_IMPORT)
119+
120+
with_statement = _Feature((2, 5, 0, "alpha", 1),
121+
(2, 6, 0, "alpha", 0),
122+
CO_FUTURE_WITH_STATEMENT)
123+
124+
print_function = _Feature((2, 6, 0, "alpha", 2),
125+
(3, 0, 0, "alpha", 0),
126+
CO_FUTURE_PRINT_FUNCTION)
127+
128+
unicode_literals = _Feature((2, 6, 0, "alpha", 2),
129+
(3, 0, 0, "alpha", 0),
130+
CO_FUTURE_UNICODE_LITERALS)
131+
132+
barry_as_FLUFL = _Feature((3, 1, 0, "alpha", 2),
133+
(3, 9, 0, "alpha", 0),
134+
CO_FUTURE_BARRY_AS_BDFL)

client/scripts/brython/www/src/Lib/_struct.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# this module 'borrowed' from
99
# https://bitbucket.org/pypy/pypy/src/18626459a9b2/lib_pypy/_struct.py?at=py3k-listview_str
10+
# with many bug fixes
1011

1112
"""Functions to convert between Python values and C structs.
1213
Python strings are used to hold the data representing the C struct
@@ -109,18 +110,18 @@ def isnan(v):
109110
def pack_float(x, size, le):
110111
unsigned = float_pack(x, size)
111112
result = []
112-
for i in range(8):
113+
for i in range(size):
113114
result.append((unsigned >> (i * 8)) & 0xFF)
114115
if le == "big":
115116
result.reverse()
116117
return bytes(result)
117118

118119
def unpack_float(data, index, size, le):
119-
binary = [data[i] for i in range(index, index + 8)]
120+
binary = [data[i] for i in range(index, index + size)]
120121
if le == "big":
121122
binary.reverse()
122123
unsigned = 0
123-
for i in range(8):
124+
for i in range(size):
124125
unsigned |= binary[i] << (i * 8)
125126
return float_unpack(unsigned, size, le)
126127

@@ -268,11 +269,14 @@ def float_pack(x, size):
268269
def getmode(fmt):
269270
try:
270271
formatdef,endianness = formatmode[fmt[0]]
272+
alignment = fmt[0] not in formatmode or fmt[0]=='@'
271273
index = 1
272274
except (IndexError, KeyError):
273275
formatdef,endianness = formatmode['@']
276+
alignment = True
274277
index = 0
275-
return formatdef,endianness,index
278+
return formatdef,endianness,index,alignment
279+
276280
def getNum(fmt,i):
277281
num=None
278282
cur = fmt[i]
@@ -290,7 +294,7 @@ def calcsize(fmt):
290294
Return size of C struct described by format string fmt.
291295
See struct.__doc__ for more on format strings."""
292296

293-
formatdef,endianness,i = getmode(fmt)
297+
formatdef,endianness,i,alignment = getmode(fmt)
294298
num = 0
295299
result = 0
296300
while i<len(fmt):
@@ -303,6 +307,10 @@ def calcsize(fmt):
303307
if num != None :
304308
result += num*format['size']
305309
else:
310+
# if formatdef is native, alignment is native, so we count a
311+
# number of padding bytes until result is a multiple of size
312+
if alignment:
313+
result += format['size'] - result % format['size']
306314
result += format['size']
307315
num = 0
308316
i += 1
@@ -312,7 +320,7 @@ def pack(fmt,*args):
312320
"""pack(fmt, v1, v2, ...) -> string
313321
Return string containing values v1, v2, ... packed according to fmt.
314322
See struct.__doc__ for more on format strings."""
315-
formatdef,endianness,i = getmode(fmt)
323+
formatdef,endianness,i,alignment = getmode(fmt)
316324
args = list(args)
317325
n_args = len(args)
318326
result = []
@@ -357,6 +365,10 @@ def pack(fmt,*args):
357365
if len(args) < num:
358366
raise StructError("insufficient arguments to pack")
359367
for var in args[:num]:
368+
# pad with 0 until position is a multiple of size
369+
if len(result) and alignment:
370+
padding = format['size'] - len(result) % format['size']
371+
result += [bytes([0])]*padding
360372
result += [format['pack'](var,format['size'],endianness)]
361373
args=args[num:]
362374
num = None
@@ -370,7 +382,7 @@ def unpack(fmt,data):
370382
Unpack the string, containing packed C structure data, according
371383
to fmt. Requires len(string)==calcsize(fmt).
372384
See struct.__doc__ for more on format strings."""
373-
formatdef,endianness,i = getmode(fmt)
385+
formatdef,endianness,i,alignment = getmode(fmt)
374386
j = 0
375387
num = 0
376388
result = []
@@ -401,6 +413,10 @@ def unpack(fmt,data):
401413
result.append(data[j+1:j+n+1])
402414
j += num
403415
else:
416+
# skip padding bytes until we get at a multiple of size
417+
if j>0 and alignment:
418+
padding = format['size'] - j % format['size']
419+
j += padding
404420
for n in range(num):
405421
result += [format['unpack'](data,j,format['size'],endianness)]
406422
j += format['size']
@@ -409,11 +425,11 @@ def unpack(fmt,data):
409425

410426
def pack_into(fmt, buf, offset, *args):
411427
data = pack(fmt, *args)
412-
buffer(buf)[offset:offset+len(data)] = data
428+
buf[offset:offset+len(data)] = data
413429

414430
def unpack_from(fmt, buf, offset=0):
415431
size = calcsize(fmt)
416-
data = buffer(buf)[offset:offset+size]
432+
data = buf[offset:offset+size]
417433
if len(data) != size:
418434
raise error("unpack_from requires a buffer of at least %d bytes"
419435
% (size,))
@@ -422,3 +438,11 @@ def unpack_from(fmt, buf, offset=0):
422438
def _clearcache():
423439
"Clear the internal cache."
424440
# No cache in this implementation
441+
442+
if __name__=='__main__':
443+
t = pack('Bf',1,2)
444+
print(t, len(t))
445+
print(unpack('Bf', t))
446+
print(calcsize('Bf'))
447+
448+

client/scripts/brython/www/src/Lib/_weakref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def getweakrefs(obj):
2828
return obj
2929

3030

31-
def proxy(obj,callback):
31+
def proxy(obj,callback=None):
3232
return ProxyType(obj)
3333

client/scripts/brython/www/src/Lib/binascii.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def triples_gen(s):
221221
if final_length == 0:
222222
snippet = ''
223223
elif final_length == 1:
224-
a = ord(final[0])
224+
a = final[0]
225225
snippet = table_b2a_base64[(a >> 2 ) & 0x3F] + \
226226
table_b2a_base64[(a << 4 ) & 0x3F] + '=='
227227
else:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../__future__.py

client/scripts/brython/www/src/Lib/site-packages/header.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'menu_doc':{'en':'Documentation','es':'Documentación','fr':'Documentation', 'pt':'Documentação'},
99
'menu_download':{'en':'Download','es':'Descargas','fr':'Téléchargement', 'pt':'Download'},
1010
'menu_dev':{'en':'Development','es':'Desarrollo','fr':'Développement', 'pt':'Desenvolvimento'},
11-
'menu_groups':{'en':'Social','es':'Social','fr':'Social', 'pt':'Social'}
11+
'menu_groups':{'en':'Community','es':'Comunidad','fr':'Communauté', 'pt':'Comunidade'}
1212
}
1313
links = {'home':'index.html',
1414
'console':'tests/console.html',
@@ -65,4 +65,3 @@ def show(prefix='', language=None):
6565
_banner <= cell
6666

6767
return qs_lang,language
68-

0 commit comments

Comments
 (0)