aboutsummaryrefslogtreecommitdiffhomepage
path: root/python/google/protobuf/pyext/message_module.cc
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2017-09-12 10:32:01 -0700
committerGravatar Adam Cozzette <acozzette@google.com>2017-09-14 10:03:57 -0700
commit13fd045dbb2b4dacea32be162a41d5a4b0d1802f (patch)
treec219e7eb18b82523e36c6748861c403a14ea66ae /python/google/protobuf/pyext/message_module.cc
parentd1bc27caef8377a710370189675cb0958443e8f1 (diff)
Integrated internal changes from Google
Diffstat (limited to 'python/google/protobuf/pyext/message_module.cc')
-rw-r--r--python/google/protobuf/pyext/message_module.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/python/google/protobuf/pyext/message_module.cc b/python/google/protobuf/pyext/message_module.cc
index d90d9de3..7c4df47f 100644
--- a/python/google/protobuf/pyext/message_module.cc
+++ b/python/google/protobuf/pyext/message_module.cc
@@ -28,8 +28,33 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include <Python.h>
+
#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/message_lite.h>
+
+static PyObject* GetPythonProto3PreserveUnknownsDefault(
+ PyObject* /*m*/, PyObject* /*args*/) {
+ if (google::protobuf::internal::GetProto3PreserveUnknownsDefault()) {
+ Py_RETURN_TRUE;
+ } else {
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject* SetPythonProto3PreserveUnknownsDefault(
+ PyObject* /*m*/, PyObject* arg) {
+ if (!arg || !PyBool_Check(arg)) {
+ PyErr_SetString(
+ PyExc_TypeError,
+ "Argument to SetPythonProto3PreserveUnknownsDefault must be boolean");
+ return NULL;
+ }
+ google::protobuf::internal::SetProto3PreserveUnknownsDefault(PyObject_IsTrue(arg));
+ Py_RETURN_NONE;
+}
+
static const char module_docstring[] =
"python-proto2 is a module that can be used to enhance proto2 Python API\n"
"performance.\n"
@@ -41,6 +66,14 @@ static PyMethodDef ModuleMethods[] = {
{"SetAllowOversizeProtos",
(PyCFunction)google::protobuf::python::cmessage::SetAllowOversizeProtos,
METH_O, "Enable/disable oversize proto parsing."},
+ // DO NOT USE: For migration and testing only.
+ {"GetPythonProto3PreserveUnknownsDefault",
+ (PyCFunction)GetPythonProto3PreserveUnknownsDefault,
+ METH_NOARGS, "Get Proto3 preserve unknowns default."},
+ // DO NOT USE: For migration and testing only.
+ {"SetPythonProto3PreserveUnknownsDefault",
+ (PyCFunction)SetPythonProto3PreserveUnknownsDefault,
+ METH_O, "Enable/disable proto3 unknowns preservation."},
{ NULL, NULL}
};