店播爬取Python脚本

descriptor_pool.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
  31. #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
  32. #include <Python.h>
  33. #include <unordered_map>
  34. #include <google/protobuf/descriptor.h>
  35. namespace google {
  36. namespace protobuf {
  37. namespace python {
  38. struct PyMessageFactory;
  39. // The (meta) type of all Messages classes.
  40. struct CMessageClass;
  41. // Wraps operations to the global DescriptorPool which contains information
  42. // about all messages and fields.
  43. //
  44. // There is normally one pool per process. We make it a Python object only
  45. // because it contains many Python references.
  46. //
  47. // "Methods" that interacts with this DescriptorPool are in the cdescriptor_pool
  48. // namespace.
  49. typedef struct PyDescriptorPool {
  50. PyObject_HEAD;
  51. // The C++ pool containing Descriptors.
  52. const DescriptorPool* pool;
  53. // True if we should free the pointer above.
  54. bool is_owned;
  55. // True if this pool accepts new proto definitions.
  56. // In this case it is allowed to const_cast<DescriptorPool*>(pool).
  57. bool is_mutable;
  58. // The error collector to store error info. Can be NULL. This pointer is
  59. // owned.
  60. DescriptorPool::ErrorCollector* error_collector;
  61. // The C++ pool acting as an underlay. Can be NULL.
  62. // This pointer is not owned and must stay alive.
  63. const DescriptorPool* underlay;
  64. // The C++ descriptor database used to fetch unknown protos. Can be NULL.
  65. // This pointer is owned.
  66. const DescriptorDatabase* database;
  67. // The preferred MessageFactory to be used by descriptors.
  68. // TODO(amauryfa): Don't create the Factory from the DescriptorPool, but
  69. // use the one passed while creating message classes. And remove this member.
  70. PyMessageFactory* py_message_factory;
  71. // Cache the options for any kind of descriptor.
  72. // Descriptor pointers are owned by the DescriptorPool above.
  73. // Python objects are owned by the map.
  74. std::unordered_map<const void*, PyObject*>* descriptor_options;
  75. } PyDescriptorPool;
  76. extern PyTypeObject PyDescriptorPool_Type;
  77. namespace cdescriptor_pool {
  78. // The functions below are also exposed as methods of the DescriptorPool type.
  79. // Looks up a field by name. Returns a PyFieldDescriptor corresponding to
  80. // the field on success, or NULL on failure.
  81. //
  82. // Returns a new reference.
  83. PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* name);
  84. // Looks up an extension by name. Returns a PyFieldDescriptor corresponding
  85. // to the field on success, or NULL on failure.
  86. //
  87. // Returns a new reference.
  88. PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg);
  89. // Looks up an enum type by name. Returns a PyEnumDescriptor corresponding
  90. // to the field on success, or NULL on failure.
  91. //
  92. // Returns a new reference.
  93. PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg);
  94. // Looks up a oneof by name. Returns a COneofDescriptor corresponding
  95. // to the oneof on success, or NULL on failure.
  96. //
  97. // Returns a new reference.
  98. PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg);
  99. } // namespace cdescriptor_pool
  100. // Retrieves the global descriptor pool owned by the _message module.
  101. // This is the one used by pb2.py generated modules.
  102. // Returns a *borrowed* reference.
  103. // "Default" pool used to register messages from _pb2.py modules.
  104. PyDescriptorPool* GetDefaultDescriptorPool();
  105. // Retrieves an existing python descriptor pool owning the C++ descriptor pool.
  106. // Returns a *borrowed* reference.
  107. PyDescriptorPool* GetDescriptorPool_FromPool(const DescriptorPool* pool);
  108. // Wraps a C++ descriptor pool in a Python object, creates it if necessary.
  109. // Returns a new reference.
  110. PyObject* PyDescriptorPool_FromPool(const DescriptorPool* pool);
  111. // Initialize objects used by this module.
  112. bool InitDescriptorPool();
  113. } // namespace python
  114. } // namespace protobuf
  115. } // namespace google
  116. #endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__