本文整理匯總了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