店播爬取Python脚本

api_implementation.cc 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include <Python.h>
  31. namespace google {
  32. namespace protobuf {
  33. namespace python {
  34. // Version constant.
  35. // This is either 0 for python, 1 for CPP V1, 2 for CPP V2.
  36. //
  37. // 0 is default and is equivalent to
  38. // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  39. //
  40. // 1 is set with -DPYTHON_PROTO2_CPP_IMPL_V1 and is equivalent to
  41. // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
  42. // and
  43. // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=1
  44. //
  45. // 2 is set with -DPYTHON_PROTO2_CPP_IMPL_V2 and is equivalent to
  46. // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
  47. // and
  48. // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
  49. #ifdef PYTHON_PROTO2_CPP_IMPL_V1
  50. #error "PYTHON_PROTO2_CPP_IMPL_V1 is no longer supported."
  51. #else
  52. #ifdef PYTHON_PROTO2_CPP_IMPL_V2
  53. static int kImplVersion = 2;
  54. #else
  55. #ifdef PYTHON_PROTO2_PYTHON_IMPL
  56. static int kImplVersion = 0;
  57. #else
  58. static int kImplVersion = -1; // -1 means "Unspecified by compiler flags".
  59. #endif // PYTHON_PROTO2_PYTHON_IMPL
  60. #endif // PYTHON_PROTO2_CPP_IMPL_V2
  61. #endif // PYTHON_PROTO2_CPP_IMPL_V1
  62. static const char* kImplVersionName = "api_version";
  63. static const char* kModuleName = "_api_implementation";
  64. static const char kModuleDocstring[] =
  65. "_api_implementation is a module that exposes compile-time constants that\n"
  66. "determine the default API implementation to use for Python proto2.\n"
  67. "\n"
  68. "It complements api_implementation.py by setting defaults using "
  69. "compile-time\n"
  70. "constants defined in C, such that one can set defaults at compilation\n"
  71. "(e.g. with blaze flag --copt=-DPYTHON_PROTO2_CPP_IMPL_V2).";
  72. #if PY_MAJOR_VERSION >= 3
  73. static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
  74. kModuleName,
  75. kModuleDocstring,
  76. -1,
  77. NULL,
  78. NULL,
  79. NULL,
  80. NULL,
  81. NULL};
  82. #define INITFUNC PyInit__api_implementation
  83. #define INITFUNC_ERRORVAL NULL
  84. #else
  85. #define INITFUNC init_api_implementation
  86. #define INITFUNC_ERRORVAL
  87. #endif
  88. extern "C" {
  89. PyMODINIT_FUNC INITFUNC() {
  90. #if PY_MAJOR_VERSION >= 3
  91. PyObject* module = PyModule_Create(&_module);
  92. #else
  93. PyObject* module = Py_InitModule3(const_cast<char*>(kModuleName), NULL,
  94. const_cast<char*>(kModuleDocstring));
  95. #endif
  96. if (module == NULL) {
  97. return INITFUNC_ERRORVAL;
  98. }
  99. // Adds the module variable "api_version".
  100. if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName),
  101. kImplVersion))
  102. #if PY_MAJOR_VERSION < 3
  103. return;
  104. #else
  105. {
  106. Py_DECREF(module);
  107. return NULL;
  108. }
  109. return module;
  110. #endif
  111. }
  112. }
  113. } // namespace python
  114. } // namespace protobuf
  115. } // namespace google