店播爬取Python脚本

repeated_composite_container.cc 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. // Author: anuraag@google.com (Anuraag Agrawal)
  31. // Author: tibell@google.com (Johan Tibell)
  32. #include <google/protobuf/pyext/repeated_composite_container.h>
  33. #include <memory>
  34. #include <google/protobuf/stubs/logging.h>
  35. #include <google/protobuf/stubs/common.h>
  36. #include <google/protobuf/descriptor.h>
  37. #include <google/protobuf/dynamic_message.h>
  38. #include <google/protobuf/message.h>
  39. #include <google/protobuf/pyext/descriptor.h>
  40. #include <google/protobuf/pyext/descriptor_pool.h>
  41. #include <google/protobuf/pyext/message.h>
  42. #include <google/protobuf/pyext/message_factory.h>
  43. #include <google/protobuf/pyext/scoped_pyobject_ptr.h>
  44. #include <google/protobuf/reflection.h>
  45. #include <google/protobuf/stubs/map_util.h>
  46. #if PY_MAJOR_VERSION >= 3
  47. #define PyInt_Check PyLong_Check
  48. #define PyInt_AsLong PyLong_AsLong
  49. #define PyInt_FromLong PyLong_FromLong
  50. #endif
  51. namespace google {
  52. namespace protobuf {
  53. namespace python {
  54. namespace repeated_composite_container {
  55. // ---------------------------------------------------------------------
  56. // len()
  57. static Py_ssize_t Length(PyObject* pself) {
  58. RepeatedCompositeContainer* self =
  59. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  60. Message* message = self->parent->message;
  61. return message->GetReflection()->FieldSize(*message,
  62. self->parent_field_descriptor);
  63. }
  64. // ---------------------------------------------------------------------
  65. // add()
  66. PyObject* Add(RepeatedCompositeContainer* self, PyObject* args,
  67. PyObject* kwargs) {
  68. if (cmessage::AssureWritable(self->parent) == -1) return nullptr;
  69. Message* message = self->parent->message;
  70. Message* sub_message =
  71. message->GetReflection()->AddMessage(
  72. message,
  73. self->parent_field_descriptor,
  74. self->child_message_class->py_message_factory->message_factory);
  75. CMessage* cmsg = self->parent->BuildSubMessageFromPointer(
  76. self->parent_field_descriptor, sub_message, self->child_message_class);
  77. if (cmessage::InitAttributes(cmsg, args, kwargs) < 0) {
  78. message->GetReflection()->RemoveLast(
  79. message, self->parent_field_descriptor);
  80. Py_DECREF(cmsg);
  81. return nullptr;
  82. }
  83. return cmsg->AsPyObject();
  84. }
  85. static PyObject* AddMethod(PyObject* self, PyObject* args, PyObject* kwargs) {
  86. return Add(reinterpret_cast<RepeatedCompositeContainer*>(self), args, kwargs);
  87. }
  88. // ---------------------------------------------------------------------
  89. // append()
  90. static PyObject* AddMessage(RepeatedCompositeContainer* self, PyObject* value) {
  91. cmessage::AssureWritable(self->parent);
  92. PyObject* py_cmsg;
  93. Message* message = self->parent->message;
  94. const Reflection* reflection = message->GetReflection();
  95. py_cmsg = Add(self, nullptr, nullptr);
  96. if (py_cmsg == nullptr) return nullptr;
  97. CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
  98. if (ScopedPyObjectPtr(cmessage::MergeFrom(cmsg, value)) == nullptr) {
  99. reflection->RemoveLast(
  100. message, self->parent_field_descriptor);
  101. Py_DECREF(cmsg);
  102. return nullptr;
  103. }
  104. return py_cmsg;
  105. }
  106. static PyObject* AppendMethod(PyObject* pself, PyObject* value) {
  107. RepeatedCompositeContainer* self =
  108. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  109. ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
  110. if (py_cmsg == nullptr) {
  111. return nullptr;
  112. }
  113. Py_RETURN_NONE;
  114. }
  115. // ---------------------------------------------------------------------
  116. // insert()
  117. static PyObject* Insert(PyObject* pself, PyObject* args) {
  118. RepeatedCompositeContainer* self =
  119. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  120. Py_ssize_t index;
  121. PyObject* value;
  122. if (!PyArg_ParseTuple(args, "nO", &index, &value)) {
  123. return nullptr;
  124. }
  125. ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
  126. if (py_cmsg == nullptr) {
  127. return nullptr;
  128. }
  129. // Swap the element to right position.
  130. Message* message = self->parent->message;
  131. const Reflection* reflection = message->GetReflection();
  132. const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
  133. Py_ssize_t length = reflection->FieldSize(*message, field_descriptor) - 1;
  134. Py_ssize_t end_index = index;
  135. if (end_index < 0) end_index += length;
  136. if (end_index < 0) end_index = 0;
  137. for (Py_ssize_t i = length; i > end_index; i --) {
  138. reflection->SwapElements(message, field_descriptor, i, i - 1);
  139. }
  140. Py_RETURN_NONE;
  141. }
  142. // ---------------------------------------------------------------------
  143. // extend()
  144. PyObject* Extend(RepeatedCompositeContainer* self, PyObject* value) {
  145. cmessage::AssureWritable(self->parent);
  146. ScopedPyObjectPtr iter(PyObject_GetIter(value));
  147. if (iter == nullptr) {
  148. PyErr_SetString(PyExc_TypeError, "Value must be iterable");
  149. return nullptr;
  150. }
  151. ScopedPyObjectPtr next;
  152. while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
  153. if (!PyObject_TypeCheck(next.get(), CMessage_Type)) {
  154. PyErr_SetString(PyExc_TypeError, "Not a cmessage");
  155. return nullptr;
  156. }
  157. ScopedPyObjectPtr new_message(Add(self, nullptr, nullptr));
  158. if (new_message == nullptr) {
  159. return nullptr;
  160. }
  161. CMessage* new_cmessage = reinterpret_cast<CMessage*>(new_message.get());
  162. if (ScopedPyObjectPtr(cmessage::MergeFrom(new_cmessage, next.get())) ==
  163. nullptr) {
  164. return nullptr;
  165. }
  166. }
  167. if (PyErr_Occurred()) {
  168. return nullptr;
  169. }
  170. Py_RETURN_NONE;
  171. }
  172. static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
  173. return Extend(reinterpret_cast<RepeatedCompositeContainer*>(self), value);
  174. }
  175. PyObject* MergeFrom(RepeatedCompositeContainer* self, PyObject* other) {
  176. return Extend(self, other);
  177. }
  178. static PyObject* MergeFromMethod(PyObject* self, PyObject* other) {
  179. return MergeFrom(reinterpret_cast<RepeatedCompositeContainer*>(self), other);
  180. }
  181. // This function does not check the bounds.
  182. static PyObject* GetItem(RepeatedCompositeContainer* self, Py_ssize_t index,
  183. Py_ssize_t length = -1) {
  184. if (length == -1) {
  185. Message* message = self->parent->message;
  186. const Reflection* reflection = message->GetReflection();
  187. length = reflection->FieldSize(*message, self->parent_field_descriptor);
  188. }
  189. if (index < 0 || index >= length) {
  190. PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
  191. return nullptr;
  192. }
  193. Message* message = self->parent->message;
  194. Message* sub_message = message->GetReflection()->MutableRepeatedMessage(
  195. message, self->parent_field_descriptor, index);
  196. return self->parent
  197. ->BuildSubMessageFromPointer(self->parent_field_descriptor, sub_message,
  198. self->child_message_class)
  199. ->AsPyObject();
  200. }
  201. PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* item) {
  202. Message* message = self->parent->message;
  203. const Reflection* reflection = message->GetReflection();
  204. Py_ssize_t length =
  205. reflection->FieldSize(*message, self->parent_field_descriptor);
  206. if (PyIndex_Check(item)) {
  207. Py_ssize_t index;
  208. index = PyNumber_AsSsize_t(item, PyExc_IndexError);
  209. if (index == -1 && PyErr_Occurred()) return nullptr;
  210. if (index < 0) index += length;
  211. return GetItem(self, index, length);
  212. } else if (PySlice_Check(item)) {
  213. Py_ssize_t from, to, step, slicelength, cur, i;
  214. PyObject* result;
  215. #if PY_MAJOR_VERSION >= 3
  216. if (PySlice_GetIndicesEx(item,
  217. length, &from, &to, &step, &slicelength) == -1) {
  218. #else
  219. if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item),
  220. length, &from, &to, &step, &slicelength) == -1) {
  221. #endif
  222. return nullptr;
  223. }
  224. if (slicelength <= 0) {
  225. return PyList_New(0);
  226. } else {
  227. result = PyList_New(slicelength);
  228. if (!result) return nullptr;
  229. for (cur = from, i = 0; i < slicelength; cur += step, i++) {
  230. PyList_SET_ITEM(result, i, GetItem(self, cur, length));
  231. }
  232. return result;
  233. }
  234. } else {
  235. PyErr_Format(PyExc_TypeError, "indices must be integers, not %.200s",
  236. item->ob_type->tp_name);
  237. return nullptr;
  238. }
  239. }
  240. static PyObject* SubscriptMethod(PyObject* self, PyObject* slice) {
  241. return Subscript(reinterpret_cast<RepeatedCompositeContainer*>(self), slice);
  242. }
  243. int AssignSubscript(RepeatedCompositeContainer* self,
  244. PyObject* slice,
  245. PyObject* value) {
  246. if (value != nullptr) {
  247. PyErr_SetString(PyExc_TypeError, "does not support assignment");
  248. return -1;
  249. }
  250. return cmessage::DeleteRepeatedField(self->parent,
  251. self->parent_field_descriptor, slice);
  252. }
  253. static int AssignSubscriptMethod(PyObject* self, PyObject* slice,
  254. PyObject* value) {
  255. return AssignSubscript(reinterpret_cast<RepeatedCompositeContainer*>(self),
  256. slice, value);
  257. }
  258. static PyObject* Remove(PyObject* pself, PyObject* value) {
  259. RepeatedCompositeContainer* self =
  260. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  261. Py_ssize_t len = Length(reinterpret_cast<PyObject*>(self));
  262. for (Py_ssize_t i = 0; i < len; i++) {
  263. ScopedPyObjectPtr item(GetItem(self, i, len));
  264. if (item == nullptr) {
  265. return nullptr;
  266. }
  267. int result = PyObject_RichCompareBool(item.get(), value, Py_EQ);
  268. if (result < 0) {
  269. return nullptr;
  270. }
  271. if (result) {
  272. ScopedPyObjectPtr py_index(PyLong_FromSsize_t(i));
  273. if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
  274. return nullptr;
  275. }
  276. Py_RETURN_NONE;
  277. }
  278. }
  279. PyErr_SetString(PyExc_ValueError, "Item to delete not in list");
  280. return nullptr;
  281. }
  282. static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
  283. RepeatedCompositeContainer* self =
  284. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  285. if (!PyObject_TypeCheck(other, &RepeatedCompositeContainer_Type)) {
  286. PyErr_SetString(PyExc_TypeError,
  287. "Can only compare repeated composite fields "
  288. "against other repeated composite fields.");
  289. return nullptr;
  290. }
  291. if (opid == Py_EQ || opid == Py_NE) {
  292. // TODO(anuraag): Don't make new lists just for this...
  293. ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
  294. if (full_slice == nullptr) {
  295. return nullptr;
  296. }
  297. ScopedPyObjectPtr list(Subscript(self, full_slice.get()));
  298. if (list == nullptr) {
  299. return nullptr;
  300. }
  301. ScopedPyObjectPtr other_list(
  302. Subscript(reinterpret_cast<RepeatedCompositeContainer*>(other),
  303. full_slice.get()));
  304. if (other_list == nullptr) {
  305. return nullptr;
  306. }
  307. return PyObject_RichCompare(list.get(), other_list.get(), opid);
  308. } else {
  309. Py_INCREF(Py_NotImplemented);
  310. return Py_NotImplemented;
  311. }
  312. }
  313. static PyObject* ToStr(PyObject* pself) {
  314. ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
  315. if (full_slice == nullptr) {
  316. return nullptr;
  317. }
  318. ScopedPyObjectPtr list(Subscript(
  319. reinterpret_cast<RepeatedCompositeContainer*>(pself), full_slice.get()));
  320. if (list == nullptr) {
  321. return nullptr;
  322. }
  323. return PyObject_Repr(list.get());
  324. }
  325. // ---------------------------------------------------------------------
  326. // sort()
  327. static void ReorderAttached(RepeatedCompositeContainer* self,
  328. PyObject* child_list) {
  329. Message* message = self->parent->message;
  330. const Reflection* reflection = message->GetReflection();
  331. const FieldDescriptor* descriptor = self->parent_field_descriptor;
  332. const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
  333. // We need to rearrange things to match python's sort order. Because there
  334. // was already an O(n*log(n)) step in python and a bunch of reflection, we
  335. // expect an O(n**2) step in C++ won't hurt too much.
  336. for (Py_ssize_t i = 0; i < length; ++i) {
  337. Message* child_message =
  338. reinterpret_cast<CMessage*>(PyList_GET_ITEM(child_list, i))->message;
  339. for (Py_ssize_t j = i; j < length; ++j) {
  340. if (child_message ==
  341. &reflection->GetRepeatedMessage(*message, descriptor, j)) {
  342. reflection->SwapElements(message, descriptor, i, j);
  343. break;
  344. }
  345. }
  346. }
  347. }
  348. // Returns 0 if successful; returns -1 and sets an exception if
  349. // unsuccessful.
  350. static int SortPythonMessages(RepeatedCompositeContainer* self,
  351. PyObject* args,
  352. PyObject* kwds) {
  353. ScopedPyObjectPtr child_list(
  354. PySequence_List(reinterpret_cast<PyObject*>(self)));
  355. if (child_list == nullptr) {
  356. return -1;
  357. }
  358. ScopedPyObjectPtr m(PyObject_GetAttrString(child_list.get(), "sort"));
  359. if (m == nullptr) return -1;
  360. if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == nullptr)
  361. return -1;
  362. ReorderAttached(self, child_list.get());
  363. return 0;
  364. }
  365. static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
  366. RepeatedCompositeContainer* self =
  367. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  368. // Support the old sort_function argument for backwards
  369. // compatibility.
  370. if (kwds != nullptr) {
  371. PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
  372. if (sort_func != nullptr) {
  373. // Must set before deleting as sort_func is a borrowed reference
  374. // and kwds might be the only thing keeping it alive.
  375. PyDict_SetItemString(kwds, "cmp", sort_func);
  376. PyDict_DelItemString(kwds, "sort_function");
  377. }
  378. }
  379. if (SortPythonMessages(self, args, kwds) < 0) {
  380. return nullptr;
  381. }
  382. Py_RETURN_NONE;
  383. }
  384. // ---------------------------------------------------------------------
  385. // reverse()
  386. // Returns 0 if successful; returns -1 and sets an exception if
  387. // unsuccessful.
  388. static int ReversePythonMessages(RepeatedCompositeContainer* self) {
  389. ScopedPyObjectPtr child_list(
  390. PySequence_List(reinterpret_cast<PyObject*>(self)));
  391. if (child_list == nullptr) {
  392. return -1;
  393. }
  394. if (ScopedPyObjectPtr(
  395. PyObject_CallMethod(child_list.get(), "reverse", nullptr)) == nullptr)
  396. return -1;
  397. ReorderAttached(self, child_list.get());
  398. return 0;
  399. }
  400. static PyObject* Reverse(PyObject* pself) {
  401. RepeatedCompositeContainer* self =
  402. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  403. if (ReversePythonMessages(self) < 0) {
  404. return nullptr;
  405. }
  406. Py_RETURN_NONE;
  407. }
  408. // ---------------------------------------------------------------------
  409. static PyObject* Item(PyObject* pself, Py_ssize_t index) {
  410. RepeatedCompositeContainer* self =
  411. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  412. return GetItem(self, index);
  413. }
  414. static PyObject* Pop(PyObject* pself, PyObject* args) {
  415. RepeatedCompositeContainer* self =
  416. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  417. Py_ssize_t index = -1;
  418. if (!PyArg_ParseTuple(args, "|n", &index)) {
  419. return nullptr;
  420. }
  421. Py_ssize_t length = Length(pself);
  422. if (index < 0) index += length;
  423. PyObject* item = GetItem(self, index, length);
  424. if (item == nullptr) {
  425. return nullptr;
  426. }
  427. ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
  428. if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
  429. return nullptr;
  430. }
  431. return item;
  432. }
  433. PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
  434. return reinterpret_cast<RepeatedCompositeContainer*>(pself)->DeepCopy();
  435. }
  436. // The private constructor of RepeatedCompositeContainer objects.
  437. RepeatedCompositeContainer *NewContainer(
  438. CMessage* parent,
  439. const FieldDescriptor* parent_field_descriptor,
  440. CMessageClass* child_message_class) {
  441. if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
  442. return nullptr;
  443. }
  444. RepeatedCompositeContainer* self =
  445. reinterpret_cast<RepeatedCompositeContainer*>(
  446. PyType_GenericAlloc(&RepeatedCompositeContainer_Type, 0));
  447. if (self == nullptr) {
  448. return nullptr;
  449. }
  450. Py_INCREF(parent);
  451. self->parent = parent;
  452. self->parent_field_descriptor = parent_field_descriptor;
  453. Py_INCREF(child_message_class);
  454. self->child_message_class = child_message_class;
  455. return self;
  456. }
  457. static void Dealloc(PyObject* pself) {
  458. RepeatedCompositeContainer* self =
  459. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  460. self->RemoveFromParentCache();
  461. Py_CLEAR(self->child_message_class);
  462. Py_TYPE(self)->tp_free(pself);
  463. }
  464. static PySequenceMethods SqMethods = {
  465. Length, /* sq_length */
  466. nullptr, /* sq_concat */
  467. nullptr, /* sq_repeat */
  468. Item /* sq_item */
  469. };
  470. static PyMappingMethods MpMethods = {
  471. Length, /* mp_length */
  472. SubscriptMethod, /* mp_subscript */
  473. AssignSubscriptMethod, /* mp_ass_subscript */
  474. };
  475. static PyMethodDef Methods[] = {
  476. {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
  477. {"add", reinterpret_cast<PyCFunction>(AddMethod),
  478. METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container."},
  479. {"append", AppendMethod, METH_O,
  480. "Appends a message to the end of the repeated container."},
  481. {"insert", Insert, METH_VARARGS,
  482. "Inserts a message before the specified index."},
  483. {"extend", ExtendMethod, METH_O, "Adds objects to the repeated container."},
  484. {"pop", Pop, METH_VARARGS,
  485. "Removes an object from the repeated container and returns it."},
  486. {"remove", Remove, METH_O,
  487. "Removes an object from the repeated container."},
  488. {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
  489. "Sorts the repeated container."},
  490. {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
  491. "Reverses elements order of the repeated container."},
  492. {"MergeFrom", MergeFromMethod, METH_O,
  493. "Adds objects to the repeated container."},
  494. {nullptr, nullptr}};
  495. } // namespace repeated_composite_container
  496. PyTypeObject RepeatedCompositeContainer_Type = {
  497. PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
  498. ".RepeatedCompositeContainer", // tp_name
  499. sizeof(RepeatedCompositeContainer), // tp_basicsize
  500. 0, // tp_itemsize
  501. repeated_composite_container::Dealloc, // tp_dealloc
  502. #if PY_VERSION_HEX >= 0x03080000
  503. 0, // tp_vectorcall_offset
  504. #else
  505. nullptr, // tp_print
  506. #endif
  507. nullptr, // tp_getattr
  508. nullptr, // tp_setattr
  509. nullptr, // tp_compare
  510. repeated_composite_container::ToStr, // tp_repr
  511. nullptr, // tp_as_number
  512. &repeated_composite_container::SqMethods, // tp_as_sequence
  513. &repeated_composite_container::MpMethods, // tp_as_mapping
  514. PyObject_HashNotImplemented, // tp_hash
  515. nullptr, // tp_call
  516. nullptr, // tp_str
  517. nullptr, // tp_getattro
  518. nullptr, // tp_setattro
  519. nullptr, // tp_as_buffer
  520. Py_TPFLAGS_DEFAULT, // tp_flags
  521. "A Repeated scalar container", // tp_doc
  522. nullptr, // tp_traverse
  523. nullptr, // tp_clear
  524. repeated_composite_container::RichCompare, // tp_richcompare
  525. 0, // tp_weaklistoffset
  526. nullptr, // tp_iter
  527. nullptr, // tp_iternext
  528. repeated_composite_container::Methods, // tp_methods
  529. nullptr, // tp_members
  530. nullptr, // tp_getset
  531. nullptr, // tp_base
  532. nullptr, // tp_dict
  533. nullptr, // tp_descr_get
  534. nullptr, // tp_descr_set
  535. 0, // tp_dictoffset
  536. nullptr, // tp_init
  537. };
  538. } // namespace python
  539. } // namespace protobuf
  540. } // namespace google