whttpserver 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: whttpserver
3
+ Version: 0.1.0
4
+ Summary: A simple HTTP server like `python -m http.server`
5
+ Home-page: https://www.hohode.com
6
+ Author: Wang Junbo
7
+ Author-email: wjbhnu@gmail.com
8
+ Classifier: Programming Language :: Python :: 2
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=2.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
File without changes
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="whttpserver", # PyPI 上的包名
5
+ version="0.1.0", # 版本号
6
+ packages=find_packages(), # 自动发现包
7
+ entry_points={
8
+ "console_scripts": [
9
+ "whttpserver=whttpserver.__main__:main", # 命令行工具
10
+ ],
11
+ },
12
+ install_requires=[], # 依赖项(如需要 Flask,可填 ["flask"])
13
+ author="Wang Junbo",
14
+ author_email="wjbhnu@gmail.com",
15
+ description="A simple HTTP server like `python -m http.server`",
16
+ long_description=open("README.md").read(),
17
+ long_description_content_type="text/markdown",
18
+ url="https://www.hohode.com",
19
+ classifiers=[ # PyPI 分类标签
20
+ "Programming Language :: Python :: 2",
21
+ "Programming Language :: Python :: 3",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ ],
25
+ python_requires=">=2.7", # Python 版本要求
26
+ )
File without changes
File without changes
@@ -0,0 +1,86 @@
1
+ from flask import Flask, request, send_from_directory
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+ app.config['UPLOAD_FOLDER'] = '/data/'
6
+
7
+ def list_files(directory):
8
+ try:
9
+ return [{'name': f, 'is_dir': os.path.isdir(os.path.join(directory, f))} for f in os.listdir(directory)]
10
+ except OSError:
11
+ return []
12
+
13
+ @app.route('/', defaults={'req_path': ''})
14
+ @app.route('/<path:req_path>')
15
+ def dir_listing(req_path):
16
+ if req_path and not req_path.endswith('/'):
17
+ req_path += '/'
18
+
19
+ abs_path = os.path.join(app.config['UPLOAD_FOLDER'], req_path)
20
+
21
+ if not os.path.exists(abs_path):
22
+ return 'Path not found'
23
+
24
+ files = list_files(abs_path)
25
+
26
+ if os.path.isfile(abs_path):
27
+ return send_from_directory(app.config['UPLOAD_FOLDER'], req_path, as_attachment=True)
28
+
29
+ return '''
30
+ <!doctype html>
31
+ <title>Directory listing for {}</title>
32
+ <h1>Directory listing for {}</h1>
33
+ <ul style="list-style-type: decimal;">
34
+ '''.format(req_path, req_path) + ''.join(
35
+ '<li><a href="/{}{}" style="color:blue;">{}</a></li>'.format(req_path, f['name'], f['name']) if f['is_dir'] else '<li><a href="/download/{}{}" style="color:green;">{}</a></li>'.format(req_path, f['name'], f['name']) for f in files) + '''
36
+ </ul>
37
+ <iframe name="hidden_iframe" id="hidden_iframe" style="display:none;"></iframe>
38
+ <form method="post" action="/upload?path='''+req_path+'''" enctype="multipart/form-data" target="hidden_iframe" onsubmit="return addMessage();">
39
+ <input type=file name=file>
40
+ <input type=submit value=Upload onclick="showUploadingMessage();">
41
+ </form>
42
+ <div id="messages"></div>
43
+ <div id="uploadingMessage" style="display:none;">Uploading...</div>
44
+ <script type="text/javascript">
45
+ function showUploadingMessage() {
46
+ document.getElementById('uploadingMessage').style.display = 'block';
47
+ }
48
+
49
+ function addMessage() {
50
+ var iframe = document.getElementById('hidden_iframe');
51
+ iframe.onload = function() {
52
+ var content = iframe.contentDocument || iframe.contentWindow.document;
53
+ var message = content.body.innerHTML;
54
+ var messagesDiv = document.getElementById('messages');
55
+ messagesDiv.innerHTML += '<p>' + message + '</p>';
56
+ document.getElementById('uploadingMessage').style.display = 'none';
57
+ };
58
+ return true;
59
+ }
60
+ </script>
61
+ '''
62
+
63
+ @app.route('/download/<path:req_path>')
64
+ def download_file(req_path):
65
+ return send_from_directory(app.config['UPLOAD_FOLDER'], req_path, as_attachment=True)
66
+
67
+ @app.route('/upload', methods=['POST'])
68
+ def upload_file():
69
+ req_path = request.args.get('path', '')
70
+ abs_path = os.path.join(app.config['UPLOAD_FOLDER'], req_path)
71
+
72
+ if not os.path.exists(abs_path):
73
+ os.makedirs(abs_path)
74
+
75
+ if 'file' not in request.files:
76
+ return 'No file part'
77
+ file = request.files['file']
78
+ if file.filename == '':
79
+ return 'No selected file'
80
+ if file:
81
+ filename = file.filename
82
+ file.save(os.path.join(abs_path, filename))
83
+ return 'File uploaded successfully to: {}'.format(os.path.join(abs_path, filename))
84
+
85
+ if __name__ == '__main__':
86
+ app.run(host='0.0.0.0', port=25000, debug=True)
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: whttpserver
3
+ Version: 0.1.0
4
+ Summary: A simple HTTP server like `python -m http.server`
5
+ Home-page: https://www.hohode.com
6
+ Author: Wang Junbo
7
+ Author-email: wjbhnu@gmail.com
8
+ Classifier: Programming Language :: Python :: 2
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=2.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ whttpserver/__init__.py
5
+ whttpserver/__main__.py
6
+ whttpserver/server.py
7
+ whttpserver.egg-info/PKG-INFO
8
+ whttpserver.egg-info/SOURCES.txt
9
+ whttpserver.egg-info/dependency_links.txt
10
+ whttpserver.egg-info/entry_points.txt
11
+ whttpserver.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ whttpserver = whttpserver.__main__:main
@@ -0,0 +1 @@
1
+ whttpserver