Python 2.7 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Python 2.7 應用程式,即使貴機構先前曾使用機構政策重新啟用舊版執行階段的部署作業,也無法部署。現有的 Python 2.7 應用程式在
淘汰日期過後,仍會繼續執行並接收流量。建議您
改用系統支援的最新 Python 版本。
WSGI 服務程式庫
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
這個模型包含會將 Google Protocol RPC 服務以 WSGI 應用程式形式發佈的類別。
protorpc.wsgi.service
套件提供下列函式:
- service_mapping(service_factory, service_path=r'.*', protocols=None)
-
建立處理單一 Google Protocol RPC 服務對應的 WSGI 應用程式。
引數
- service_factory
- 用於建立服務新執行個體的服務類別或服務工廠。如要進一步瞭解服務 Factory,請參閱 remote.Service.new_factory。
- service_path=r'.*'
- 服務所在的路徑。
- protocols=None
- remote.Protocols 例項,用於在伺服器上設定支援的通訊協定。
傳回可處理單一 Google Protocol RPC 服務對應的 WSGI 應用程式。
- service_mappings(services, registry_path=DEFAULT_REGISTRY_PATH)
-
建立與選用登錄服務具有多個服務對應的 WSGI 應用程式。例如:
from protorpc import remote
from protorpc.wsgi import service
package = 'my_package'
class MyService(remote.Service):
...
class MyOtherService(remote.Service):
...
app = service.service_mappings(
[('/my_path', MyService), # Maps to /my_path
('/my_other_path', MyOtherService), # Maps to /my_other_path
])
服務會藉由指定組合 (path, service) 而對應至特定網址路徑;其中,path 是指服務所在的路徑,而 service 是指用於建立服務新執行個體的服務類別或服務 Factory。如要進一步瞭解服務 Factory,請參閱 remote.Service.new_factory。引數
- services
- 元組 (路徑、服務) 清單,其中
path
是服務所在的路徑,而 service
是用於建立服務新執行個體的服務類別或服務工廠。如要進一步瞭解服務 Factory,請參閱 remote.Service.new_factory。
- registry_path=DEFAULT_REGISTRY_PATH
- 提供給登錄檔服務的路徑。使用 None 即可停用登錄服務。
傳回與選用登錄服務具有多個服務對應的 WSGI 應用程式。
提供重複的路徑時,會擲回 ServiceConfigurationError
。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThis module provides tools to publish Google Protocol RPC services as WSGI applications.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eservice_mapping\u003c/code\u003e function creates a WSGI application for a single RPC service, using a service factory or class to instantiate the service.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eservice_mappings\u003c/code\u003e function enables the creation of a WSGI application that hosts multiple services, each mapped to a specific URL path.\u003c/p\u003e\n"],["\u003cp\u003eBoth functions allow the use of service factories for the creation of service instances.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eservice_mappings\u003c/code\u003e function can include an optional registry service and will raise a \u003ccode\u003eServiceConfigurationError\u003c/code\u003e if duplicate paths are given.\u003c/p\u003e\n"]]],[],null,["# WSGI Service Library\n\nThis module contains classes that publish a Google Protocol RPC service as a WSGI application.\n\nThe `protorpc.wsgi.service` package provides the following functions:\n\nservice_mapping(service_factory, service_path=r'.\\*', protocols=None)\n\n: Creates a WSGI application that handles a single Google Protocol RPC service mapping.\n\n **Arguments**\n\n service_factory\n : The service class or service factory for creating new instances of the service. For more information about service factories, please see [remote.Service.new_factory](/appengine/docs/legacy/standard/python/tools/protorpc/remote/serviceclass#new_factory).\n\n service_path=r'.\\*'\n : The path where the service resides.\n\n protocols=None\n : A remote.Protocols instance that configures supported protocols on the server.\n\n Returns a WSGI application that handles a single Google Protocol RPC service mapping.\n\nservice_mappings(services, registry_path=DEFAULT_REGISTRY_PATH)\n\n: Creates a WSGI application with multiple service mappings with an optional registry service. For example:\n\n ```python\n from protorpc import remote\n from protorpc.wsgi import service\n\n package = 'my_package'\n\n class MyService(remote.Service):\n ...\n\n class MyOtherService(remote.Service):\n ...\n\n app = service.service_mappings(\n [('/my_path', MyService), # Maps to /my_path\n ('/my_other_path', MyOtherService), # Maps to /my_other_path\n ])\n ```\n\n Services are mapped to URL paths by specifying a tuple\n (path, service), where path is the path where the service resides, and service is the service class or service factory for creating new instances of the service. For more information about service factories, please see [remote.Service.new_factory](/appengine/docs/legacy/standard/python/tools/protorpc/remote/serviceclass#new_factory).\n\n **Arguments**\n\n services\n : A list of tuples (path, service), where `path` is the path where the service resides, and `service` is the service class or service factory for creating new instances of the service. For more information about service factories, please see [remote.Service.new_factory](/appengine/docs/legacy/standard/python/tools/protorpc/remote/serviceclass#new_factory).\n\n registry_path=DEFAULT_REGISTRY_PATH\n : Path to provide to the registry service. Use None to disable registry service.\n\n Returns a WSGI application with multiple service mappings with an optional registry service.\n\n Raises a `ServiceConfigurationError` when duplicate paths are provided."]]