本文整理汇总了Python中http.server.SimpleHTTPRequestHandler.do_GET方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleHTTPRequestHandler.do_GET方法的具体用法?Python SimpleHTTPRequestHandler.do_GET怎么用?Python SimpleHTTPRequestHandler.do_GET使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.server.SimpleHTTPRequestHandler
的用法示例。
在下文中一共展示了SimpleHTTPRequestHandler.do_GET方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
# Check For URL Stream "http://IPADDRESS/Notify?"
if "/Notify?" in self.path:
self._set_headers()
preurl, notification = self.path.split("?")
# Add some error handling for chrome looping
redir = "<html><head><meta http-equiv='refresh' content='0;url=.\' /></head><body><h1>Notification Sent! <br>"+notification+"</h1></body></html>"
print(redir)
self.wfile.write(redir.encode())
self.notify(str(notification))
return
elif "/HelloWorld" in self.path:
self._set_headers()
print("Hello World Test")
self.notify("Hello+World")
return
else:
SimpleHTTPRequestHandler.do_GET(self)
# POST is for submitting data
示例2: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
if self.path.endswith('/plain_text'):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'This is text/plain')
elif re.search(r'/set_cookie', self.path):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.send_header('Set-Cookie', 'monster=1')
self.end_headers()
self.wfile.write(b"<html>C is for cookie, it's good enough for me</html>")
elif not re.search(r'.*\.\w+$', self.path):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
else:
SimpleHTTPRequestHandler.do_GET(self)
示例3: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
global MAP_OVERRIDE
path_end = self.path.rsplit('/', 1)[1]
if path_end in ['FRANCE', 'INNSBRUCK', 'LONDON', 'NEWYORK', 'PARIS', 'RICHMOND', 'WATOPIA', 'YORKSHIRE']:
MAP_OVERRIDE = path_end
self.send_response(302)
self.send_header('Location', 'https://secure.zwift.com/ride')
self.end_headers()
return
if MAP_OVERRIDE and self.path == '/gameassets/MapSchedule_v2.xml':
self.send_response(200)
self.send_header('Content-type', 'text/xml')
self.end_headers()
output = '<MapSchedule><appointments><appointment map="%s" start="%s"/></appointments><VERSION>1</VERSION></MapSchedule>' % (MAP_OVERRIDE, datetime.now().strftime("%Y-%m-%dT00:01-04"))
self.wfile.write(output.encode())
MAP_OVERRIDE = None
return
elif self.path == '/gameassets/MapSchedule_v2.xml' and os.path.exists(PROXYPASS_FILE):
# PROXYPASS_FILE existence indicates we know what we're doing and
# we can try to obtain the official map schedule. This can only work
# if we're running on a different machine than the Zwift client.
try:
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'http://cdn.zwift.com/gameassets/MapSchedule_v2.xml')
self.send_response(200)
self.send_header('Content-type', 'text/xml')
self.end_headers()
self.wfile.write(r.data)
return
except:
pass # fallthrough to return zoffline version
if path_end.startswith('saveghost?'):
self.send_response(200)
self.end_headers()
saveGhost(rec.player_id, path_end[10:])
return
SimpleHTTPRequestHandler.do_GET(self)
示例4: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
if self.path == '/ip':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write('ip adresiniz %s' % self.client_address[0])
return
else:
return SimpleHTTPRequestHandler.do_GET(self)
示例5: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
url = urlparse(self.path)
print("url: '%s' url.path: '%s'" % (url, url.path))
if url.path == "" or url.path == "/":
self.redirect("/login.html")
if url.path == "/authenticate":
self.redirect("/homepage.html")
return
if url.path == '/admin/shutdown':
print("server shutdown has been requested")
os.kill(os.getpid(), signal.SIGHUP)
return SimpleHTTPRequestHandler.do_GET(self)
示例6: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
parsed_path = urllib.parse.urlparse(self.path)
if parsed_path.path.startswith("/echo"):
message = '\n'.join(
[
'CLIENT VALUES:',
'client_address=%s (%s)' % (self.client_address, self.address_string()),
'command=%s' % self.command,
'path=%s' % self.path,
'real path=%s' % parsed_path.path,
'query=%s' % parsed_path.query,
'request_version=%s' % self.request_version,
'',
'HEADERS:',
'%s' % self.headers,
]
)
self.send_response(200)
self.end_headers()
self.wfile.write(message.encode('utf-8'))
elif parsed_path.path.startswith("/redirect"):
self.send_response(301)
self.send_header('Location', "/echo")
self.end_headers()
else:
SimpleHTTPRequestHandler.do_GET(self)
return
示例7: do_GET
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_GET(self):
if self.server.auth and not self.checkAuthentication():
return
if self.headers.get('Upgrade', None) == 'websocket':
self._handshake()
#This handler is in websocket mode now.
#do_GET only returns after client close or socket error.
self._read_messages()
else:
SimpleHTTPRequestHandler.do_GET(self)
示例8: do_POST
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_GET [as 别名]
def do_POST(self):
self.do_GET()