本文整理汇总了Python中http.server.server_port方法的典型用法代码示例。如果您正苦于以下问题:Python server.server_port方法的具体用法?Python server.server_port怎么用?Python server.server_port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.server
的用法示例。
在下文中一共展示了server.server_port方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_smart_module_server
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import server_port [as 别名]
def start_smart_module_server(download_url):
"""Serve documentation and module requests at the same URL."""
# pylint:disable=g-import-not-at-top
if sys.version_info[0] == 2:
import BaseHTTPServer
import SimpleHTTPServer
import urlparse
class HTTPServerV6(BaseHTTPServer.HTTPServer):
address_family = socket.AF_INET6
class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
parsed_url = urlparse.urlparse(self.path)
qs = urlparse.parse_qs(parsed_url.query)
if qs["tf-hub-format"][0] == "compressed":
_do_redirect(self, download_url)
else:
_do_documentation(self)
server = HTTPServerV6(("", 0), RequestHandler)
server_port = server.server_port
else:
import http.server
import socketserver
import urllib
class TCPServerV6(socketserver.TCPServer):
address_family = socket.AF_INET6
class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
parsed_url = urllib.parse.urlparse(self.path)
qs = urllib.parse.parse_qs(parsed_url.query)
if qs["tf-hub-format"][0] == "compressed":
_do_redirect(self, download_url)
else:
_do_documentation(self)
server = TCPServerV6(("", 0), RequestHandler)
_, server_port, _, _ = server.server_address
# pylint:disable=g-import-not-at-top
thread = threading.Thread(target=server.serve_forever)
thread.daemon = True
thread.start()
return server_port
示例2: start_http_server
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import server_port [as 别名]
def start_http_server(redirect=None):
"""Returns the port of the newly started HTTP server."""
# Start HTTP server to serve TAR files.
# pylint:disable=g-import-not-at-top
if sys.version_info[0] == 2:
import BaseHTTPServer
import SimpleHTTPServer
class HTTPServerV6(BaseHTTPServer.HTTPServer):
address_family = socket.AF_INET6
class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
_do_redirect(self, redirect)
server = HTTPServerV6(("", 0), RedirectHandler if redirect else
SimpleHTTPServer.SimpleHTTPRequestHandler)
server_port = server.server_port
else:
import http.server
import socketserver
class TCPServerV6(socketserver.TCPServer):
address_family = socket.AF_INET6
class RedirectHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
_do_redirect(self, redirect)
server = TCPServerV6(("", 0), RedirectHandler if redirect else
http.server.SimpleHTTPRequestHandler)
_, server_port, _, _ = server.server_address
# pylint:disable=g-import-not-at-top
thread = threading.Thread(target=server.serve_forever)
thread.daemon = True
thread.start()
return server_port