Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
285914f044 | ||
|
|
da2c779bcd | ||
|
|
7259509d9e | ||
|
|
b085e13c4e | ||
|
|
59e84426af | ||
|
|
97f93ebd8e | ||
|
|
35c8889e77 | ||
|
|
dca7e9d599 | ||
|
|
ce856e5626 | ||
|
|
072032e80e | ||
|
|
235e7b5268 | ||
|
|
22fa096271 | ||
|
|
13eb12bf69 | ||
|
|
efa189d0b6 | ||
|
|
111f551a39 | ||
|
|
e0fd81dc1d | ||
|
|
420194ef54 | ||
|
|
632448c249 | ||
|
|
c3405d56e5 |
@@ -0,0 +1,100 @@
|
||||
# A quick brain teaser
|
||||
print('What has a head and a tail but no body?')
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# A coin
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0593e529",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from urllib.parse import urlparse\n",
|
||||
"\n",
|
||||
"class JPEGRequestHandler:\n",
|
||||
" def __init__(self, app):\n",
|
||||
" self.app = app\n",
|
||||
"\n",
|
||||
" def __call__(self, environ, start_response):\n",
|
||||
" url = urlparse(environ['REQUEST_URI'])\n",
|
||||
" path = url.path\n",
|
||||
"\n",
|
||||
" if path.endswith('.jpg'):\n",
|
||||
" file_path = path[1:]\n",
|
||||
"\n",
|
||||
" if os.path.isfile(file_path):\n",
|
||||
" with open(file_path, 'rb') as file:\n",
|
||||
" response_body = file.read()\n",
|
||||
" status = '200 OK'\n",
|
||||
" headers = [('Content-type', 'image/jpeg'),\n",
|
||||
" ('Content-Length', str(len(response_body)))]\n",
|
||||
"\n",
|
||||
" start_response(status, headers)\n",
|
||||
" return [response_body]\n",
|
||||
" else:\n",
|
||||
" status = '404 Not Found'\n",
|
||||
" headers = [('Content-type', 'text/plain'),\n",
|
||||
" ('Content-Length', '0')]\n",
|
||||
"\n",
|
||||
" start_response(status, headers)\n",
|
||||
" return []\n",
|
||||
" else:\n",
|
||||
" status = '403 Forbidden'\n",
|
||||
" headers = [('Content-type', 'text/plain'),\n",
|
||||
" ('Content-Length', '0')]\n",
|
||||
"\n",
|
||||
" start_response(status, headers)\n",
|
||||
" return []\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" from werkzeug.serving import run_simple\n",
|
||||
" from werkzeug.middleware.dispatcher import DispatcherMiddleware\n",
|
||||
"\n",
|
||||
" app = DispatcherMiddleware(JPEGRequestHandler(app), {'/': app})\n",
|
||||
" run_simple('0.0.0.0', 8000, app, use_reloader=True)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
|
||||
class JPEGRequestHandler:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
url = urlparse(environ['REQUEST_URI'])
|
||||
path = url.path
|
||||
|
||||
if path.endswith('.jpg'):
|
||||
file_path = path[1:]
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
with open(file_path, 'rb') as file:
|
||||
response_body = file.read()
|
||||
status = '200 OK'
|
||||
headers = [('Content-type', 'image/jpeg'),
|
||||
('Content-Length', str(len(response_body)))]
|
||||
|
||||
start_response(status, headers)
|
||||
return [response_body]
|
||||
else:
|
||||
status = '404 Not Found'
|
||||
headers = [('Content-type', 'text/plain'),
|
||||
('Content-Length', '0')]
|
||||
|
||||
start_response(status, headers)
|
||||
return []
|
||||
else:
|
||||
status = '403 Forbidden'
|
||||
headers = [('Content-type', 'text/plain'),
|
||||
('Content-Length', '0')]
|
||||
|
||||
start_response(status, headers)
|
||||
return []
|
||||
|
||||
if __name__ == '__main__':
|
||||
from werkzeug.serving import run_simple
|
||||
from werkzeug.middleware.dispatcher import DispatcherMiddleware
|
||||
|
||||
app = DispatcherMiddleware(JPEGRequestHandler(app), {'/': app})
|
||||
run_simple('0.0.0.0', 8000, app, use_reloader=True)
|
||||
@@ -0,0 +1,3 @@
|
||||
hi,this is a test commit.hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit.
|
||||
hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit.
|
||||
hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit. hi,this is a test commit.
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user