Skip to content

Commit 54f265c

Browse files
authored
0.15-canary
Add importError Add webserver
1 parent 6e4c33b commit 54f265c

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

binpython.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
#BINPython By:XINGYUJIE AGPL-V3.0 LECENSE Release
22
#Please follow the LICENSE
3-
ver="0.15-dev"
3+
ver="0.15-canary"
44
#base import
55
import getopt
66
import sys
77
import platform
8+
#import for http_server
9+
import http.server
10+
import socketserver
11+
#except ImportError:
12+
813
#gui import
914
try:
1015
import tkinter
1116
import turtle
1217
#warning for gui
13-
except:
18+
except ImportError:
1419
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")
1520
print("")
1621

1722
#import math
1823
try:
1924
import fractions
2025
import cmath
21-
except:
26+
except ImportError:
2227
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")
2328
print("")
2429
#rlcompleter
@@ -27,23 +32,24 @@
2732
#str
2833
import rlcompleter
2934
import array
30-
except:
35+
except ImportError:
3136
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")
3237
print("")
3338
try:
3439
import filecmp
3540
import tempfile
36-
except:
41+
except ImportError:
3742
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")
3843
print("")
3944
#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'])
4146
for opt_name,opt_value in opts:
4247
if opt_name in ('-h','--help'):
4348
print("[*] Help info")
4449
print("""
4550
-h --help View this help
4651
-f --file Enter Python Filename and run
52+
-s. --server Start a simple web server that supports html and file transfer (http.server)
4753
-v --version View BINPython Version
4854
""")
4955
sys.exit()
@@ -57,6 +63,19 @@
5763
exec(f.read())
5864
input("Please enter to continue")
5965
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()
6079
#main BINPython
6180

6281
print("BINPython " + ver + " (Python Version:" + platform.python_version() + ")By:XINGYUJIE https://github.com/xingyujie/binpython[Running on " + platform.platform() + " " + platform.version() + "]")

0 commit comments

Comments
 (0)