Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
メッセージ モジュール関数
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
protorpc.messages
パッケージは、次の位置ユーティリティ関数を提供します。
- find_definition(name, relative_to=None)
-
モジュール空間内を定義の名前で検索します。
検索アルゴリズムは、メッセージ定義に関連した名前または完全修飾名で定義を検索します。relative_to
パラメータに関連した定義が見つからない場合は、relative_to
のコンテナに対して検索を実行します。relative_to
がネストされた Message である場合は、その Message の message_definition() を検索します。そのメッセージに message_definition() がない場合は、そのメッセージのモジュールを検索します。relative_to
がモジュールの場合、検索アルゴリズムは上位のモジュールを検索し、そのモジュールに対して相対的に検索します。モジュールが最上位モジュールである場合、検索アルゴリズムは完全修飾名を使用してメッセージを検索します。それでもメッセージが見つからない場合、検索は失敗し、メソッドは DefinitionNotFoundError を送出します。
たとえば、次のように、実際のメッセージ定義 abc.xyz.SomeMessage
に対して相対的な定義 foo.bar.ADefinition
を検索するとします。
find_definition('foo.bar.ADefinition', SomeMessage)
このメソッドの引数は、完全修飾名の検索に類似したパターンに従います。
abc.xyz.SomeMessage. foo.bar.ADefinition
abc.xyz. foo.bar.ADefinition
abc. foo.bar.ADefinition
foo.bar.ADefinition
Message 定義とモジュールに相対的な名前を解決する場合、検索アルゴリズムはパス内で見つかった Message またはサブモジュールを検索し、Message 以外の値を無視します。
'.'
で始まる名前は完全修飾名とみなされます。検索アルゴリズムは一番上のパッケージから検索を開始します。たとえば、次の 2 つのメッセージ タイプがあるとします。
abc.xyz.SomeMessage
xyz.SomeMessage
.xyz.SomeMessage
を abc
に対して相対的に検索すると、xyz.SomeMessage
に解決され、abc.xyz.SomeMessage
にはなりません。このような種類の名前の場合、relative_to パラメータは実質的に無視され、常に None に設定されます。
パッケージ名の解決の詳細については、プロトコル バッファ パッケージ指定子をご覧ください。
引数
- name
- 検索する定義の名前。完全修飾名または相対名を指定できます。
- relative_to
- メッセージ定義またはモジュールに対して相対的に定義を検索します。None にすると、完全修飾名の検索になります。
名前に関連付けられた Enum または Message クラス定義を返します。
どの検索パスにも定義が見つからない場合は、DefinitionNotFoundError を送出します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","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 UTC。"],[[["\u003cp\u003eThe \u003ccode\u003efind_definition\u003c/code\u003e function in \u003ccode\u003eprotorpc.messages\u003c/code\u003e locates definitions by name, either relative to a message or module or by a fully qualified name.\u003c/p\u003e\n"],["\u003cp\u003eThe search algorithm for \u003ccode\u003efind_definition\u003c/code\u003e prioritizes searching relative to the \u003ccode\u003erelative_to\u003c/code\u003e parameter, progressing up the module hierarchy if necessary and then falling back to searching by fully qualified name.\u003c/p\u003e\n"],["\u003cp\u003eA name starting with \u003ccode\u003e'.'\u003c/code\u003e in \u003ccode\u003efind_definition\u003c/code\u003e is treated as fully qualified, starting the search from the topmost package and ignoring the \u003ccode\u003erelative_to\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003efind_definition\u003c/code\u003e method requires two arguments: \u003ccode\u003ename\u003c/code\u003e, which can be fully qualified or relative, and \u003ccode\u003erelative_to\u003c/code\u003e, that specifies a definition to start the search from.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003efind_definition\u003c/code\u003e will return an \u003ccode\u003eEnum\u003c/code\u003e or \u003ccode\u003eMessage\u003c/code\u003e class definition, and in case a definition cannot be found, it will raise a \u003ccode\u003eDefinitionNotFoundError\u003c/code\u003e exception.\u003c/p\u003e\n"]]],[],null,["# Messages Module Functions\n\nThe `protorpc.messages` package provides the following positional utility function:\n\nfind_definition(name, relative_to=None)\n\n: Find definition by name in module-space.\n\n The find algorithm finds definitions by name relative to a message definition or by fully qualified name. If no definition is found relative to the `relative_to` parameter, it searches against the container of `relative_to`. If `relative_to` is a nested Message, it searches its message_definition(). If that message has no message_definition(), it searches its module. If `relative_to` is a module, the find algorithm searches for the containing module and searches relative to it. If the module is a top-level module, the find algorithm searches for the a message using a fully qualified name. If it still finds no message, the search fails and the method raises a [DefinitionNotFoundError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#DefinitionNotFoundError).\n\n For example, when looking for any definition `foo.bar.ADefinition` relative to an actual message definition `abc.xyz.SomeMessage`: \n\n ```python\n find_definition('foo.bar.ADefinition', SomeMessage)\n ```\n\n The arguments to this method follow a pattern similar to a search for fully qualified names: \n\n ```python\n abc.xyz.SomeMessage. foo.bar.ADefinition\n abc.xyz. foo.bar.ADefinition\n abc. foo.bar.ADefinition\n foo.bar.ADefinition\n ```\n\n When resolving the name relative to Message definitions and modules, the algorithm searches any Messages or sub-modules found in its path, ignoring non-Message values.\n\n A name that begins with `'.'` is considered to be a fully qualified name. The find algorithm begins searching from the topmost package. For example, assume two message types:\n\n ```python\n abc.xyz.SomeMessage\n xyz.SomeMessage\n ```\n\n Searching for `.xyz.SomeMessage` relative to `abc` resolves to `xyz.SomeMessage` and not `abc.xyz.SomeMessage`. For this kind of name,\n the relative_to parameter is effectively ignored and always set to None.\n\n For more information about package name resolution, please see the [Protocol Buffers Package specifier](https://developers.google.com/protocol-buffers/docs/proto#packages).\n **Arguments**\n\n name\n : Name of a definition to find. May be fully qualified or relative.\n\n relative_to\n : Searches for a definition relative to the message definition or module. If None, causes a fully qualified name search.\n\n Returns an [Enum](/appengine/docs/legacy/standard/python/tools/protorpc/messages/enumclass) or [Message](/appengine/docs/legacy/standard/python/tools/protorpc/messages/messageclass) class definition associated with the name.\n\n raises a [DefinitionNotFoundError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#DefinitionNotFoundError) if no definition is found in any search path."]]