Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit 2f837a4

Browse files
committed
Cleaning up before release
1 parent 2ea6587 commit 2f837a4

3 files changed

Lines changed: 305 additions & 6 deletions

File tree

brython_legal.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9+
10+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

console.html

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython.min.js"></script>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython_stdlib.js"></script>
6+
</head>
7+
<body onload="brython(1);">
8+
<style>
9+
textarea.codearea {
10+
position: absolute;
11+
width: 100%;
12+
height: 100%;
13+
resize: none;
14+
top: 0px;
15+
right: 0px;
16+
left: 0px;
17+
bottom: 0px;
18+
background-color: #1d1d1d;
19+
color: #ffffff;
20+
}
21+
</style>
22+
<textarea class="codearea" id="code" spellcheck="false"></textarea>
23+
<!--
24+
Copy of /www/tests/console.py from GitHub repository brython-dev/brython below, in <script> tag.
25+
See brython_legal.txt for more info.
26+
-->
27+
<script type="text/python3">
28+
import sys
29+
import tb as traceback
30+
31+
from browser import document as doc
32+
from browser import window, alert, console
33+
34+
_credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
35+
for supporting Python development. See www.python.org for more information."""
36+
37+
_copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
38+
All Rights Reserved.
39+
Copyright (c) 2001-2013 Python Software Foundation.
40+
All Rights Reserved.
41+
Copyright (c) 2000 BeOpen.com.
42+
All Rights Reserved.
43+
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
44+
All Rights Reserved.
45+
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
46+
All Rights Reserved."""
47+
48+
_license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
49+
All rights reserved.
50+
Redistribution and use in source and binary forms, with or without
51+
modification, are permitted provided that the following conditions are met:
52+
Redistributions of source code must retain the above copyright notice, this
53+
list of conditions and the following disclaimer. Redistributions in binary
54+
form must reproduce the above copyright notice, this list of conditions and
55+
the following disclaimer in the documentation and/or other materials provided
56+
with the distribution.
57+
Neither the name of the <ORGANIZATION> nor the names of its contributors may
58+
be used to endorse or promote products derived from this software without
59+
specific prior written permission.
60+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
61+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
64+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
65+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
66+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
67+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
68+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70+
POSSIBILITY OF SUCH DAMAGE.
71+
"""
72+
73+
CODE_ELT = doc['code']
74+
75+
def credits():
76+
print(_credits)
77+
credits.__repr__ = lambda:_credits
78+
79+
def copyright():
80+
print(_copyright)
81+
copyright.__repr__ = lambda:_copyright
82+
83+
def license():
84+
print(_license)
85+
license.__repr__ = lambda:_license
86+
87+
class Trace:
88+
89+
def __init__(self):
90+
self.buf = ""
91+
92+
def write(self, data):
93+
self.buf += str(data)
94+
95+
def format(self):
96+
"""Remove calls to function in this script from the traceback."""
97+
lines = self.buf.split("\n")
98+
stripped = [lines[0]]
99+
for i in range(1, len(lines), 2):
100+
if __file__ in lines[i]:
101+
continue
102+
stripped += lines[i: i+2]
103+
return "\n".join(stripped)
104+
105+
def print_tb():
106+
trace = Trace()
107+
traceback.print_exc(file=trace)
108+
CODE_ELT.value += trace.format()
109+
110+
def syntax_error(args):
111+
info, filename, lineno, offset, line = args
112+
print(f" File {filename}, line {lineno}")
113+
print(" " + line)
114+
print(" " + offset * " " + "^")
115+
print("SyntaxError:", info)
116+
flush()
117+
118+
OUT_BUFFER = ''
119+
120+
def write(data):
121+
global OUT_BUFFER
122+
OUT_BUFFER += str(data)
123+
124+
def flush():
125+
global CODE_ELT, OUT_BUFFER
126+
CODE_ELT.value += OUT_BUFFER
127+
OUT_BUFFER = ''
128+
129+
sys.stdout.write = sys.stderr.write = write
130+
sys.stdout.__len__ = sys.stderr.__len__ = lambda: len(OUT_BUFFER)
131+
132+
history = []
133+
current = 0
134+
_status = "main" # or "block" if typing inside a block
135+
136+
# execution namespace
137+
editor_ns = {'credits':credits,
138+
'copyright':copyright,
139+
'license':license,
140+
'__name__':'__main__'}
141+
142+
def cursorToEnd(*args):
143+
pos = len(doc['code'].value)
144+
doc['code'].setSelectionRange(pos, pos)
145+
doc['code'].scrollTop = doc['code'].scrollHeight
146+
147+
def get_col(area):
148+
# returns the column num of cursor
149+
sel = doc['code'].selectionStart
150+
lines = doc['code'].value.split('\n')
151+
for line in lines[:-1]:
152+
sel -= len(line) + 1
153+
return sel
154+
155+
def myKeyPress(event):
156+
global _status, current
157+
if event.keyCode == 9: # tab key
158+
event.preventDefault()
159+
doc['code'].value += " "
160+
elif event.keyCode == 13: # return
161+
src = doc['code'].value
162+
if _status == "main":
163+
currentLine = src[src.rfind('>>>') + 4:]
164+
elif _status == "3string":
165+
currentLine = src[src.rfind('>>>') + 4:]
166+
currentLine = currentLine.replace('\n... ', '\n')
167+
else:
168+
currentLine = src[src.rfind('...') + 4:]
169+
if _status == 'main' and not currentLine.strip():
170+
doc['code'].value += '\n>>> '
171+
event.preventDefault()
172+
return
173+
doc['code'].value += '\n'
174+
history.append(currentLine)
175+
current = len(history)
176+
if _status == "main" or _status == "3string":
177+
try:
178+
_ = editor_ns['_'] = eval(currentLine, editor_ns)
179+
flush()
180+
if _ is not None:
181+
write(repr(_)+'\n')
182+
flush()
183+
doc['code'].value += '>>> '
184+
_status = "main"
185+
except IndentationError:
186+
doc['code'].value += '... '
187+
_status = "block"
188+
except SyntaxError as msg:
189+
if str(msg) == 'invalid syntax : triple string end not found' or \
190+
str(msg).startswith('Unbalanced bracket'):
191+
doc['code'].value += '... '
192+
_status = "3string"
193+
elif str(msg) == 'eval() argument must be an expression':
194+
try:
195+
exec(currentLine, editor_ns)
196+
except:
197+
print_tb()
198+
flush()
199+
doc['code'].value += '>>> '
200+
_status = "main"
201+
elif str(msg) == 'decorator expects function':
202+
doc['code'].value += '... '
203+
_status = "block"
204+
else:
205+
syntax_error(msg.args)
206+
doc['code'].value += '>>> '
207+
_status = "main"
208+
except:
209+
# the full traceback includes the call to eval(); to
210+
# remove it, it is stored in a buffer and the 2nd and 3rd
211+
# lines are removed
212+
print_tb()
213+
doc['code'].value += '>>> '
214+
_status = "main"
215+
elif currentLine == "": # end of block
216+
block = src[src.rfind('>>>') + 4:].splitlines()
217+
block = [block[0]] + [b[4:] for b in block[1:]]
218+
block_src = '\n'.join(block)
219+
# status must be set before executing code in globals()
220+
_status = "main"
221+
try:
222+
_ = exec(block_src, editor_ns)
223+
if _ is not None:
224+
print(repr(_))
225+
except:
226+
print_tb()
227+
flush()
228+
doc['code'].value += '>>> '
229+
else:
230+
doc['code'].value += '... '
231+
232+
cursorToEnd()
233+
event.preventDefault()
234+
235+
def myKeyDown(event):
236+
global _status, current
237+
if event.keyCode == 37: # left arrow
238+
sel = get_col(doc['code'])
239+
if sel < 5:
240+
event.preventDefault()
241+
event.stopPropagation()
242+
elif event.keyCode == 36: # line start
243+
pos = doc['code'].selectionStart
244+
col = get_col(doc['code'])
245+
doc['code'].setSelectionRange(pos - col + 4, pos - col + 4)
246+
event.preventDefault()
247+
elif event.keyCode == 38: # up
248+
if current > 0:
249+
pos = doc['code'].selectionStart
250+
col = get_col(doc['code'])
251+
# remove current line
252+
doc['code'].value = doc['code'].value[:pos - col + 4]
253+
current -= 1
254+
doc['code'].value += history[current]
255+
event.preventDefault()
256+
elif event.keyCode == 40: # down
257+
if current < len(history) - 1:
258+
pos = doc['code'].selectionStart
259+
col = get_col(doc['code'])
260+
# remove current line
261+
doc['code'].value = doc['code'].value[:pos - col + 4]
262+
current += 1
263+
doc['code'].value += history[current]
264+
event.preventDefault()
265+
elif event.keyCode == 8: # backspace
266+
src = doc['code'].value
267+
lstart = src.rfind('\n')
268+
if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6):
269+
event.preventDefault()
270+
event.stopPropagation()
271+
elif event.ctrlKey and event.keyCode == 65: # ctrl+a
272+
src = doc['code'].value
273+
pos = doc['code'].selectionStart
274+
col = get_col(doc['code'])
275+
doc['code'].setSelectionRange(pos - col + 4, len(src))
276+
event.preventDefault()
277+
elif event.keyCode in [33, 34]: # page up, page down
278+
event.preventDefault()
279+
280+
281+
doc['code'].bind('keypress', myKeyPress)
282+
doc['code'].bind('keydown', myKeyDown)
283+
doc['code'].bind('click', cursorToEnd)
284+
v = sys.implementation.version
285+
doc['code'].value = "Brython %s.%s.%s on %s %s\n>>> " % (
286+
v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion)
287+
#doc['code'].value += 'Type "copyright", "credits" or "license" for more information.'
288+
doc['code'].focus()
289+
cursorToEnd()
290+
</script>
291+
</body>
292+
</html>

installguide.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ After that disk should look like that:
3232
```
3333
a
3434
└ Py93
35-
├ brython
36-
│ ├ console.html
37-
│ └ some other files and folders...
3835
├ LICENSE
3936
├ README.md
4037
├ installguide.md
@@ -50,10 +47,10 @@ Reboot your Windows 93 PC.
5047

5148
### **Finished!**
5249

53-
Now you can open `console.html` in `/Py93/brython` to open **Py93 Shell** or write `py93 c help` in the Windows 93 terminal to see `py93compile` (Py93 Compiler) usage.
50+
Now you can open `console.html` in `/Py93/` to open **Py93 Shell** or write `py93 c help` in the Windows 93 terminal to see `py93compile` (Py93 Compiler) usage.
5451

5552
Also, don't forget to check out [Brython documentation](https://brython.info/static_doc/en/intro.html?lang=en)!
56-
Brython has it's own [`browser`](https://https://brython.info/static_doc/en/browser.html) package and some differences from Python.
53+
Brython has it's own [`browser`](https://https://brython.info/static_doc/en/browser.html) package and some differences between Python.
5754
For example: built-in function `input()` in Python lets you to type your input right into the console, but in Brython `input()` uses JavaScript's `prompt()` function, and instead of normal Pythonic behavior `input()` opens a standart browser window with a prompt.
5855

59-
> *Last updated: April 30, 2020*
56+
> *Last updated: May 3, 2020*

0 commit comments

Comments
 (0)