Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/google/protobuf/reflection.py
7794 views
# Protocol Buffers - Google's data interchange format1# Copyright 2008 Google Inc. All rights reserved.2# https://developers.google.com/protocol-buffers/3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are6# met:7#8# * Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# * Redistributions in binary form must reproduce the above11# copyright notice, this list of conditions and the following disclaimer12# in the documentation and/or other materials provided with the13# distribution.14# * Neither the name of Google Inc. nor the names of its15# contributors may be used to endorse or promote products derived from16# this software without specific prior written permission.17#18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2930# This code is meant to work on Python 2.4 and above only.3132"""Contains a metaclass and helper functions used to create33protocol message classes from Descriptor objects at runtime.3435Recall that a metaclass is the "type" of a class.36(A class is to a metaclass what an instance is to a class.)3738In this case, we use the GeneratedProtocolMessageType metaclass39to inject all the useful functionality into the classes40output by the protocol compiler at compile-time.4142The upshot of all this is that the real implementation43details for ALL pure-Python protocol buffers are *here in44this file*.45"""4647__author__ = '[email protected] (Will Robinson)'484950from google.protobuf import message_factory51from google.protobuf import symbol_database5253# The type of all Message classes.54# Part of the public interface, but normally only used by message factories.55GeneratedProtocolMessageType = message_factory._GENERATED_PROTOCOL_MESSAGE_TYPE5657MESSAGE_CLASS_CACHE = {}585960# Deprecated. Please NEVER use reflection.ParseMessage().61def ParseMessage(descriptor, byte_str):62"""Generate a new Message instance from this Descriptor and a byte string.6364DEPRECATED: ParseMessage is deprecated because it is using MakeClass().65Please use MessageFactory.GetPrototype() instead.6667Args:68descriptor: Protobuf Descriptor object69byte_str: Serialized protocol buffer byte string7071Returns:72Newly created protobuf Message object.73"""74result_class = MakeClass(descriptor)75new_msg = result_class()76new_msg.ParseFromString(byte_str)77return new_msg787980# Deprecated. Please NEVER use reflection.MakeClass().81def MakeClass(descriptor):82"""Construct a class object for a protobuf described by descriptor.8384DEPRECATED: use MessageFactory.GetPrototype() instead.8586Args:87descriptor: A descriptor.Descriptor object describing the protobuf.88Returns:89The Message class object described by the descriptor.90"""91# Original implementation leads to duplicate message classes, which won't play92# well with extensions. Message factory info is also missing.93# Redirect to message_factory.94return symbol_database.Default().GetPrototype(descriptor)959697