Go to the documentation of this file.
33 #include <unordered_map>
46 #if PY_MAJOR_VERSION >= 3
47 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize
48 #if PY_VERSION_HEX < 0x03030000
49 #error "Python 3.0 - 3.2 are not supported."
51 #define PyString_AsStringAndSize(ob, charpp, sizep) \
52 (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
53 PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
56 : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
65 static std::unordered_map<const DescriptorPool*, PyDescriptorPool*>*
68 namespace cdescriptor_pool {
78 const string&
message)
override {
83 (
"Invalid proto descriptor for file \"" + filename +
"\":\n");
124 PyObject_GC_Track(cpool);
144 std::make_pair(cpool->
pool, cpool)).second) {
146 PyErr_SetString(PyExc_ValueError,
"DescriptorPool already registered");
169 PyErr_SetString(PyExc_ValueError,
"DescriptorPool already registered");
178 PyObject*
args, PyObject* kwargs) {
179 static char* kwlist[] = {
"descriptor_db", 0};
180 PyObject* py_database =
NULL;
181 if (!PyArg_ParseTupleAndKeywords(
args, kwargs,
"|O", kwlist, &py_database)) {
185 if (py_database && py_database != Py_None) {
188 return reinterpret_cast<PyObject*
>(
195 Py_CLEAR(
self->py_message_factory);
196 for (std::unordered_map<const void*, PyObject*>::iterator
it =
197 self->descriptor_options->begin();
198 it !=
self->descriptor_options->end(); ++
it) {
199 Py_DECREF(
it->second);
201 delete self->descriptor_options;
202 delete self->database;
204 delete self->error_collector;
210 Py_VISIT(
self->py_message_factory);
216 Py_CLEAR(
self->py_message_factory);
221 char*
name,
char* error_type) {
224 if (error_collector && !error_collector->
error_message.empty()) {
225 PyErr_Format(PyExc_KeyError,
"Couldn't build file for %s %.200s\n%s",
227 error_collector->
Clear();
230 PyErr_Format(PyExc_KeyError,
"Couldn't find %s %.200s", error_type,
name);
235 Py_ssize_t name_size;
237 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
243 string(
name, name_size));
245 if (message_descriptor ==
NULL) {
259 Py_ssize_t name_size;
261 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
269 if (file_descriptor ==
NULL) {
276 Py_ssize_t name_size;
278 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
283 self->pool->FindFieldByName(
string(
name, name_size));
284 if (field_descriptor ==
NULL) {
297 Py_ssize_t name_size;
299 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
304 self->pool->FindExtensionByName(
string(
name, name_size));
305 if (field_descriptor ==
NULL) {
319 Py_ssize_t name_size;
321 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
326 self->pool->FindEnumTypeByName(
string(
name, name_size));
340 Py_ssize_t name_size;
342 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
347 self->pool->FindOneofByName(
string(
name, name_size));
348 if (oneof_descriptor ==
NULL) {
361 Py_ssize_t name_size;
363 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
369 string(
name, name_size));
370 if (service_descriptor ==
NULL) {
381 Py_ssize_t name_size;
383 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
389 string(
name, name_size));
390 if (method_descriptor ==
NULL) {
401 Py_ssize_t name_size;
403 if (PyString_AsStringAndSize(arg, &
name, &name_size) < 0) {
409 string(
name, name_size));
410 if (file_descriptor ==
NULL) {
421 PyObject* message_descriptor;
423 if (!PyArg_ParseTuple(
args,
"Oi", &message_descriptor, &
number)) {
435 if (extension_descriptor ==
NULL) {
439 if (error_collector && !error_collector->
error_message.empty()) {
440 PyErr_Format(PyExc_KeyError,
"Couldn't build file for Extension %.d\n%s",
442 error_collector->
Clear();
445 PyErr_Format(PyExc_KeyError,
"Couldn't find Extension %d",
number);
459 std::vector<const FieldDescriptor*> extensions;
464 if (result ==
NULL) {
467 for (
int i = 0;
i < extensions.size();
i++) {
489 if (!file_descriptor) {
492 if (file_descriptor !=
494 file_descriptor->
name())) {
495 PyErr_Format(PyExc_ValueError,
496 "The file descriptor %s does not belong to this pool",
497 file_descriptor->
name().c_str());
506 if (!message_descriptor) {
509 if (message_descriptor !=
512 PyErr_Format(PyExc_ValueError,
513 "The message descriptor %s does not belong to this pool",
514 message_descriptor->
full_name().c_str());
529 PyErr_Format(PyExc_ValueError,
530 "The enum descriptor %s does not belong to this pool",
540 if (!extension_descriptor) {
543 if (extension_descriptor !=
546 PyErr_Format(PyExc_ValueError,
547 "The extension descriptor %s does not belong to this pool",
548 extension_descriptor->
full_name().c_str());
557 if (!service_descriptor) {
560 if (service_descriptor !=
563 PyErr_Format(PyExc_ValueError,
564 "The service descriptor %s does not belong to this pool",
565 service_descriptor->
full_name().c_str());
575 Py_ssize_t message_len;
580 "Cannot call Add on a DescriptorPool that uses a DescriptorDatabase. "
581 "Add your file to the underlying database.");
585 if (PyBytes_AsStringAndSize(serialized_pb, &
message_type, &message_len) < 0) {
590 if (!file_proto.ParseFromArray(
message_type, message_len)) {
591 PyErr_SetString(PyExc_TypeError,
"Couldn't parse file content!");
598 if (
self->underlay) {
599 generated_file =
self->underlay->FindFileByName(file_proto.
name());
601 if (generated_file !=
NULL) {
603 generated_file, serialized_pb);
608 self->pool->BuildFileCollectingErrors(file_proto,
611 PyErr_Format(PyExc_TypeError,
612 "Couldn't build proto file into descriptor pool!\n%s",
621 static PyObject*
Add(PyObject*
self, PyObject* file_descriptor_proto) {
623 PyObject_CallMethod(file_descriptor_proto,
"SerializeToString",
NULL));
624 if (serialized_pb ==
NULL) {
631 {
"Add",
Add, METH_O,
632 "Adds the FileDescriptorProto and its types to this pool." },
634 "Adds a serialized FileDescriptorProto to this pool." },
639 "No-op. Add() must have been called before." },
641 "No-op. Add() must have been called before." },
643 "No-op. Add() must have been called before." },
645 "No-op. Add() must have been called before." },
647 "No-op. Add() must have been called before." },
650 "Searches for a file descriptor by its .proto name." },
652 "Searches for a message descriptor by full name." },
654 "Searches for a field descriptor by full name." },
656 "Searches for extension descriptor by full name." },
658 "Searches for enum type descriptor by full name." },
660 "Searches for oneof descriptor by full name." },
662 "Searches for service descriptor by full name." },
664 "Searches for method descriptor by full name." },
667 "Gets the FileDescriptor containing the specified symbol." },
669 "Gets the extension descriptor for the given number." },
671 "Gets all known extensions of the given message descriptor." },
697 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
731 new std::unordered_map<const DescriptorPool*, PyDescriptorPool*>;
761 std::unordered_map<const DescriptorPool*, PyDescriptorPool*>::iterator
it =
764 PyErr_SetString(PyExc_KeyError,
"Unknown descriptor pool");
const std::string & full_name() const
const std::string & name() const
PyObject * FindEnumTypeByName(PyDescriptorPool *self, PyObject *arg)
static PyObject * AddEnumDescriptor(PyObject *self, PyObject *descriptor)
const FileDescriptor * FindFileByName(const std::string &name) const
static PyDescriptorPool * _CreateDescriptorPool()
GLuint const GLchar * name
PyObject * FindOneofByName(PyDescriptorPool *self, PyObject *arg)
static PyObject * FindMessageByName(PyObject *self, PyObject *arg)
const Descriptor::ReservedRange const EnumValueDescriptor const MethodDescriptor extension
static PyObject * FindFileByName(PyObject *self, PyObject *arg)
const std::string & full_name() const
PyObject * PyServiceDescriptor_FromDescriptor(const ServiceDescriptor *service_descriptor)
PyDescriptorPool * GetDefaultDescriptorPool()
PyObjectStruct * get() const
const std::string & full_name() const
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
const FieldDescriptor * PyFieldDescriptor_AsDescriptor(PyObject *obj)
PyObject * PyMethodDescriptor_FromDescriptor(const MethodDescriptor *method_descriptor)
struct google::protobuf::python::PyDescriptorPool PyDescriptorPool
static PyObject * FindEnumTypeByNameMethod(PyObject *self, PyObject *arg)
static PyObject * AddServiceDescriptor(PyObject *self, PyObject *descriptor)
static PyObject * Add(PyObject *self, PyObject *file_descriptor_proto)
static PyDescriptorPool * PyDescriptorPool_NewWithDatabase(DescriptorDatabase *database)
PyObjectStruct * release()
static PyObject * FindServiceByName(PyObject *self, PyObject *arg)
static PyObject * AddSerializedFile(PyObject *pself, PyObject *serialized_pb)
PyObject * PyEnumDescriptor_FromDescriptor(const EnumDescriptor *enum_descriptor)
PyObject * PyFieldDescriptor_FromDescriptor(const FieldDescriptor *field_descriptor)
PyObject * PyMessageDescriptor_FromDescriptor(const Descriptor *message_descriptor)
static PyObject * AddFileDescriptor(PyObject *self, PyObject *descriptor)
static int GcClear(PyObject *pself)
zend_class_entry * message_type
static PyObject * FindFileContainingSymbol(PyObject *self, PyObject *arg)
static PyDescriptorPool * python_generated_pool
static PyObject * FindExtensionByNameMethod(PyObject *self, PyObject *arg)
const DescriptorDatabase * database
static PyObject * FindExtensionByNumber(PyObject *self, PyObject *args)
PyDescriptorPool * GetDescriptorPool_FromPool(const DescriptorPool *pool)
const Descriptor * PyMessageDescriptor_AsDescriptor(PyObject *obj)
#define PyVarObject_HEAD_INIT(type, size)
std::unordered_map< const void *, PyObject * > * descriptor_options
PyObject * FindFieldByName(PyDescriptorPool *self, PyObject *arg)
static PyObject * FindFieldByNameMethod(PyObject *self, PyObject *arg)
PyObject * FindExtensionByName(PyDescriptorPool *self, PyObject *arg)
static PyObject * New(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject * SetErrorFromCollector(DescriptorPool::ErrorCollector *self, char *name, char *error_type)
static PyObject * AddDescriptor(PyObject *self, PyObject *descriptor)
static PyMethodDef Methods[]
static PyObject * FindOneofByNameMethod(PyObject *self, PyObject *arg)
static int GcTraverse(PyObject *pself, visitproc visit, void *arg)
PyTypeObject PyMessageFactory_Type
InternalDescriptorPool * pool
PyTypeObject PyDescriptorPool_Type
PyObject * PyFileDescriptor_FromDescriptor(const FileDescriptor *file_descriptor)
const std::string & name() const
const FileDescriptor * PyFileDescriptor_AsDescriptor(PyObject *obj)
PyMessageFactory * py_message_factory
PyObject * PyOneofDescriptor_FromDescriptor(const OneofDescriptor *oneof_descriptor)
static std::unordered_map< const DescriptorPool *, PyDescriptorPool * > * descriptor_pool_map
static PyDescriptorPool * PyDescriptorPool_NewWithUnderlay(const DescriptorPool *underlay)
VALUE enum_descriptor(VALUE self)
PyMessageFactory * NewMessageFactory(PyTypeObject *type, PyDescriptorPool *pool)
const EnumDescriptor * PyEnumDescriptor_AsDescriptor(PyObject *obj)
PyObject * PyFileDescriptor_FromDescriptorWithSerializedPb(const FileDescriptor *file_descriptor, PyObject *serialized_pb)
bool InitDescriptorPool()
const ServiceDescriptor * PyServiceDescriptor_AsDescriptor(PyObject *obj)
PyObject_HEAD DescriptorPool * pool
static const DescriptorPool * generated_pool()
static PyObject * FindAllExtensions(PyObject *self, PyObject *arg)
DescriptorPool::ErrorCollector * error_collector
static void visit(const upb_refcounted *r, upb_refcounted_visit *v, void *closure)
static PyObject * AddExtensionDescriptor(PyObject *self, PyObject *descriptor)
const DescriptorPool * underlay
static void Dealloc(PyObject *pself)
void AddError(const string &filename, const string &element_name, const Message *descriptor, ErrorLocation location, const string &message) override
BuildFileErrorCollector()
struct DescriptorPool DescriptorPool
GLenum GLuint GLenum GLsizei const GLchar * message
static PyObject * FindMethodByName(PyObject *self, PyObject *arg)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:50