File: //lib/python3.9/site-packages/google/protobuf/internal/__pycache__/python_message.cpython-39.pyc
a
x��g$� � @ s� d Z dZddlmZ ddlZddlZddlZddlZddlm Z ddl
mZ ddl
mZ ddl
m
Z
dd l
mZ dd
l
mZ ddl
mZ ddl
mZ dd
l
mZ ddl
mZ ddl
mZ ddlmZ ddlmZ ddlmZ ejZdZejZG dd� de �Z!dd� Z"dd� Z#dd� Z$dd� Z%dd� Z&d d!� Z'd"d#� Z(d$d%� Z)d&d'� Z*d(d)� Z+d*d+� Z,d,d-� Z-d.d/� Z.d0d1� Z/d2d3� Z0d4d5� Z1G d6d7� d7e2�Z3d8d9� Z4d:d;� Z5d<d=� Z6d>d?� Z7d@dA� Z8dBdC� Z9dDdE� Z:dFZ;dGZ<dHdI� Z=dJdK� Z>dLdM� Z?dNdO� Z@dPdQ� ZAdRdS� ZBdTdU� ZCdVdW� ZDdXdY� ZEdZd[� ZFd\d]� ZGd^d_� ZHd`da� ZIdbdc� ZJddde� ZKdfdg� ZLdhdi� ZMdjdk� ZNdldm� ZOdndo� ZPdpdq� ZQdrds� ZRdtdu� ZSG dvdw� dweT�ZUG dxdy� dyeU�ZVdS )za
Contains a metaclass and helper functions used to create
protocol message classes from Descriptor objects at runtime.
Recall that a metaclass is the "type" of a class.
(A class is to a metaclass what an instance is to a class.)
In this case, we use the GeneratedProtocolMessageType metaclass
to inject all the useful functionality into the classes
output by the protocol compiler at compile-time.
The upshot of all this is that the real implementation
details for ALL pure-Python protocol buffers are *here in
this file*.
z#robinson@google.com (Will Robinson)� )�BytesION)�range)�api_implementation)�
containers)�decoder)�encoder)�enum_type_wrapper)�extension_dict)�message_listener)�
type_checkers)�well_known_types)�wire_format)�
descriptor��message)�text_formatzgoogle.protobuf.Anyc s0 e Zd ZdZdZ� fdd�Z� fdd�Z� ZS )�GeneratedProtocolMessageTypeaQ Metaclass for protocol message classes created at runtime from Descriptors.
We add implementations for all methods described in the Message class. We
also create properties to allow getting/setting all fields in the protocol
message. Finally, we create slots to prevent users from accidentally
"setting" nonexistent fields in the protocol message, which then wouldn't get
serialized / deserialized properly.
The protocol compiler currently uses this metaclass to create protocol
message classes at runtime. Clients can also manually create their own
classes at runtime, as in this example:
mydescriptor = Descriptor(.....)
factory = symbol_database.Default()
factory.pool.AddDescriptor(mydescriptor)
MyProtoClass = factory.GetPrototype(mydescriptor)
myproto_instance = MyProtoClass()
myproto.foo_field = 23
...
�
DESCRIPTORc s� |t j }t|t�rtd��t|dd�}|r0|S |jtjv rN|tj|j f7 }t ||� t
||� tt | �}|�| |||�}|S )ak Custom allocation for runtime-generated class types.
We override __new__ because this is apparently the only place
where we can meaningfully set __slots__ on the class we're creating(?).
(The interplay between metaclasses and slots is not very well-documented).
Args:
name: Name of the class (ignored, but required by the
metaclass protocol).
bases: Base classes of the class we're constructing.
(Should be message.Message). We ignore this field, but
it's required by the metaclass protocol
dictionary: The class dictionary of the class we're
constructing. dictionary[_DESCRIPTOR_KEY] must contain
a Descriptor object describing this protocol message
type.
Returns:
Newly-allocated class.
Raises:
RuntimeError: Generated code only work with python cpp extension.
z\The generated code only work with python cpp extension, but it is using pure python runtime.�_concrete_classN)
r �_DESCRIPTOR_KEY�
isinstance�str�RuntimeError�getattr� full_namer ZWKTBASES�&_AddClassAttributesForNestedExtensions� _AddSlots�super�__new__)�cls�name�bases�
dictionaryr � new_class�
superclass�� __class__� �K/usr/lib/python3.9/site-packages/google/protobuf/internal/python_message.pyr k s
z$GeneratedProtocolMessageType.__new__c s� |t j }t|dd�}|r4|| u s0J d|j ��dS i | _|jr`|�� jr`t� |�df| jtj
<