Python 2.7 telah mencapai akhir dukungan
dan akan
dihentikan penggunaannya
pada 31 Januari 2026. Setelah penghentian penggunaan, Anda tidak akan dapat men-deploy aplikasi Python 2.7, meskipun organisasi Anda sebelumnya menggunakan kebijakan organisasi untuk mengaktifkan kembali deployment runtime lama. Aplikasi Python 2.7 yang ada akan terus berjalan dan menerima traffic setelah
tanggal penghentiannya. Sebaiknya Anda
bermigrasi ke versi Python terbaru yang didukung.
Fungsi Modul Pesan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Paket protorpc.messages
menyediakan fungsi utilitas posisi berikut:
- find_definition(name, relative_to=None)
-
Temukan definisi berdasarkan nama di module-space.
Algoritma pencari menemukan definisi menurut nama, relatif terhadap definisi pesan, atau berdasarkan nama yang sepenuhnya memenuhi syarat. Jika tidak ditemukan definisi yang relatif terhadap parameter relative_to
, algoritma akan menelusuri penampung relative_to
. Jika relative_to
adalah Pesan susun bertingkat, algoritma akan menelusuri message_definition(). Jika pesan tersebut tidak memiliki message_definition(), algoritma akan menelusuri modulnya. Jika relative_to
adalah modul, algoritma pencari akan menelusuri modul penampung dan melakukan penelusuran relatif terhadap modul tersebut. Jika modul adalah modul tingkat atas, algoritma pencari akan menelusuri pesan menggunakan nama yang sepenuhnya memenuhi syarat. Jika algoritma tetap tidak menemukan pesan, penelusuran akan gagal dan metode ini akan memunculkan DefinitionNotFoundError.
Misalnya, saat mencari foo.bar.ADefinition
definisi yang relatif terhadap abc.xyz.SomeMessage
definisi pesan sebenarnya:
find_definition('foo.bar.ADefinition', SomeMessage)
Argumen untuk metode ini mengikuti pola yang mirip dengan penelusuran nama yang sepenuhnya memenuhi syarat:
abc.xyz.SomeMessage. foo.bar.ADefinition
abc.xyz. foo.bar.ADefinition
abc. foo.bar.ADefinition
foo.bar.ADefinition
Saat me-resolve nama yang relatif terhadap definisi dan modul Pesan, algoritma akan menelusuri Pesan atau sub-modul apa pun yang ditemukan di jalurnya, dengan mengabaikan nilai non-Pesan.
Nama yang diawali dengan '.'
dianggap sebagai nama yang sepenuhnya memenuhi syarat. Algoritma pencarian akan memulai penelusuran dari paket paling atas. Misalnya, asumsikan dua jenis pesan:
abc.xyz.SomeMessage
xyz.SomeMessage
Menelusuri .xyz.SomeMessage
yang relatif terhadap abc
akan me-resolve ke xyz.SomeMessage
dan bukan abc.xyz.SomeMessage
. Untuk nama jenis ini,
parameter relative_to diabaikan secara efektif dan selalu disetel ke None.
Untuk informasi selengkapnya tentang resolusi nama paket, lihat penentu Paket Buffering Protokol.
Argumen
- nama
- Nama definisi yang akan ditemukan. Mungkin sepenuhnya memenuhi syarat atau relatif.
- relative_to
- Menelusuri definisi yang relatif terhadap definisi atau modul pesan. Jika None, ini akan menyebabkan penelusuran nama yang sepenuhnya memenuhi syarat.
Menampilkan definisi class Enum atau Pesan yang terkait dengan nama.
memunculkan DefinitionNotFoundError jika tidak ada definisi yang ditemukan di jalur penelusuran mana pun.
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-09-04 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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."]]