|
1 | 1 | #BINPython By:XINGYUJIE AGPL-V3.0 LECENSE Release |
2 | 2 | #Please follow the LICENSE |
3 | | -ver="0.15-dev" |
| 3 | +ver="0.15-canary" |
4 | 4 | #base import |
5 | 5 | import getopt |
6 | 6 | import sys |
7 | 7 | import platform |
| 8 | +#import for http_server |
| 9 | +import http.server |
| 10 | +import socketserver |
| 11 | +#except ImportError: |
| 12 | + |
8 | 13 | #gui import |
9 | 14 | try: |
10 | 15 | import tkinter |
11 | 16 | import turtle |
12 | 17 | #warning for gui |
13 | | -except: |
| 18 | +except ImportError: |
14 | 19 | print("Warning: Some GUI (graphical) libraries for BINPython do not exist, such as tkinter and turtle. Because they are not built when they are built. If you need to fix this warning, please complete the support libraries imported in the source code at build time (use pip or build it yourself), if your system does not support these libraries, you can remove or change this hint in the source code and rebuild") |
15 | 20 | print("") |
16 | 21 |
|
17 | 22 | #import math |
18 | 23 | try: |
19 | 24 | import fractions |
20 | 25 | import cmath |
21 | | -except: |
| 26 | +except ImportError: |
22 | 27 | print("Warning: Some math or computation libraries for BINPython do not exist, such as fractions and cmath. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild") |
23 | 28 | print("") |
24 | 29 | #rlcompleter |
|
27 | 32 | #str |
28 | 33 | import rlcompleter |
29 | 34 | import array |
30 | | -except: |
| 35 | +except ImportError: |
31 | 36 | print("Warning: Some libraries for functions, data types, etc. for BINPython do not exist, such as rlcomplter and array. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild") |
32 | 37 | print("") |
33 | 38 | try: |
34 | 39 | import filecmp |
35 | 40 | import tempfile |
36 | | -except: |
| 41 | +except ImportError: |
37 | 42 | print("Warning: Some file manipulation libraries for BINPython do not exist, such as filecmp and tempfile. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild") |
38 | 43 | print("") |
39 | 44 | #getopt |
40 | | -opts,args = getopt.getopt(sys.argv[1:],'-h-f:-v',['help','file=','version']) |
| 45 | +opts,args = getopt.getopt(sys.argv[1:],'-h-f:-s:-v',['help','file','server','version']) |
41 | 46 | for opt_name,opt_value in opts: |
42 | 47 | if opt_name in ('-h','--help'): |
43 | 48 | print("[*] Help info") |
44 | 49 | print(""" |
45 | 50 | -h --help View this help |
46 | 51 | -f --file Enter Python Filename and run |
| 52 | +-s. --server Start a simple web server that supports html and file transfer (http.server) |
47 | 53 | -v --version View BINPython Version |
48 | 54 | """) |
49 | 55 | sys.exit() |
|
57 | 63 | exec(f.read()) |
58 | 64 | input("Please enter to continue") |
59 | 65 | sys.exit() |
| 66 | + if opt_name in ('-s','--server'): |
| 67 | + server_port = opt_value |
| 68 | + exec(""" |
| 69 | +
|
| 70 | +PORT = """ + server_port + """ |
| 71 | +
|
| 72 | +Handler = http.server.SimpleHTTPRequestHandler |
| 73 | +
|
| 74 | +with socketserver.TCPServer(("", PORT), Handler) as httpd: |
| 75 | + print("serving at port", PORT) |
| 76 | + httpd.serve_forever() |
| 77 | +""") |
| 78 | + sys.exit() |
60 | 79 | #main BINPython |
61 | 80 |
|
62 | 81 | print("BINPython " + ver + " (Python Version:" + platform.python_version() + ")By:XINGYUJIE https://github.com/xingyujie/binpython[Running on " + platform.platform() + " " + platform.version() + "]") |
|
0 commit comments