Go to the documentation of this file.
48 #if PY_MAJOR_VERSION >= 3
49 #define PyInt_FromLong PyLong_FromLong
50 #if PY_VERSION_HEX < 0x03030000
51 #error "Python 3.0 - 3.2 are not supported."
53 #define PyString_AsString(ob) \
54 (PyUnicode_Check(ob)? PyUnicode_AsUTF8(ob): PyBytes_AsString(ob))
62 namespace repeated_scalar_container {
68 for (Py_ssize_t
i = 0;
i < PyList_GET_SIZE(list); ++
i) {
69 PyObject*
value = PyList_GET_ITEM(list,
i);
77 static Py_ssize_t
Len(PyObject* pself) {
82 self->parent_field_descriptor);
91 const FieldDescriptor* field_descriptor =
self->parent_field_descriptor;
99 PyErr_Format(PyExc_IndexError,
100 "list assignment index (%d) out of range",
101 static_cast<int>(
index));
111 if (PySequence_Check(arg) && !(PyBytes_Check(arg) || PyUnicode_Check(arg))) {
112 PyErr_SetString(PyExc_TypeError,
"Value must be scalar");
116 switch (field_descriptor->
cpp_type()) {
154 arg,
message, field_descriptor, reflection,
false,
index)) {
168 if (enum_value !=
NULL) {
174 PyErr_Format(PyExc_ValueError,
"Unknown enum value: %s",
175 PyString_AsString(
s.get()));
184 PyExc_SystemError,
"Adding value to a field of unknown type %d",
191 static PyObject*
Item(PyObject* pself, Py_ssize_t
index) {
196 const FieldDescriptor* field_descriptor =
self->parent_field_descriptor;
204 PyErr_Format(PyExc_IndexError,
205 "list index (%zd) out of range",
210 PyObject* result =
NULL;
211 switch (field_descriptor->
cpp_type()) {
215 result = PyInt_FromLong(
value);
221 result = PyLong_FromLongLong(
value);
227 result = PyLong_FromLongLong(
value);
233 result = PyLong_FromUnsignedLongLong(
value);
239 result = PyFloat_FromDouble(
value);
245 result = PyFloat_FromDouble(
value);
251 result = PyBool_FromLong(
value ? 1 : 0);
256 message->GetReflection()->GetRepeatedEnum(
258 result = PyInt_FromLong(enum_value->
number());
271 "Getting value from a repeated field of unknown type %d",
278 static PyObject*
Subscript(PyObject* pself, PyObject* slice) {
283 Py_ssize_t slicelength;
284 bool return_list =
false;
285 #if PY_MAJOR_VERSION < 3
286 if (PyInt_Check(slice)) {
287 from = to = PyInt_AsLong(slice);
290 if (PyLong_Check(slice)) {
291 from = to = PyLong_AsLong(slice);
292 }
else if (PySlice_Check(slice)) {
294 #if PY_MAJOR_VERSION >= 3
295 if (PySlice_GetIndicesEx(slice,
296 length, &from, &to, &step, &slicelength) == -1) {
298 if (PySlice_GetIndicesEx(
reinterpret_cast<PySliceObject*
>(slice),
299 length, &from, &to, &step, &slicelength) == -1) {
305 PyErr_SetString(PyExc_TypeError,
"list indices must be integers");
310 return Item(pself, from);
313 PyObject* list = PyList_New(0);
326 PyList_Append(list,
s.get());
337 PyList_Append(list,
s.get());
346 const FieldDescriptor* field_descriptor =
self->parent_field_descriptor;
349 switch (field_descriptor->
cpp_type()) {
387 item,
message, field_descriptor, reflection,
true, -1)) {
400 if (enum_value !=
NULL) {
405 PyErr_Format(PyExc_ValueError,
"Unknown enum value: %s",
406 PyString_AsString(
s.get()));
415 PyExc_SystemError,
"Adding value to a field of unknown type %d",
435 Py_ssize_t slicelength;
436 bool create_list =
false;
441 self->parent_field_descriptor;
443 #if PY_MAJOR_VERSION < 3
444 if (PyInt_Check(slice)) {
445 from = to = PyInt_AsLong(slice);
448 if (PyLong_Check(slice)) {
449 from = to = PyLong_AsLong(slice);
450 }
else if (PySlice_Check(slice)) {
453 #if PY_MAJOR_VERSION >= 3
454 if (PySlice_GetIndicesEx(slice,
455 length, &from, &to, &step, &slicelength) == -1) {
457 if (PySlice_GetIndicesEx(
reinterpret_cast<PySliceObject*
>(slice),
458 length, &from, &to, &step, &slicelength) == -1) {
464 PyErr_SetString(PyExc_TypeError,
"list indices must be integers");
477 if (full_slice ==
NULL) {
481 if (new_list ==
NULL) {
484 if (PySequence_SetSlice(new_list.
get(), from, to,
value) < 0) {
495 if (
value == Py_None) {
504 PyErr_SetString(PyExc_TypeError,
"Value must be iterable");
508 while ((
next.reset(PyIter_Next(iter.
get()))) !=
NULL) {
513 if (PyErr_Occurred()) {
541 Py_ssize_t match_index = -1;
542 for (Py_ssize_t
i = 0;
i <
Len(pself); ++
i) {
544 if (PyObject_RichCompareBool(elem.
get(),
value, Py_EQ)) {
549 if (match_index == -1) {
550 PyErr_SetString(PyExc_ValueError,
"remove(x): x not in container");
563 static PyObject*
RichCompare(PyObject* pself, PyObject* other,
int opid) {
564 if (opid != Py_EQ && opid != Py_NE) {
565 Py_INCREF(Py_NotImplemented);
566 return Py_NotImplemented;
574 if (full_slice ==
NULL) {
581 other = other_list_deleter.
get();
588 return PyObject_RichCompare(list.
get(), other, opid);
591 PyObject*
Reduce(PyObject* unused_self, PyObject* unused_other) {
594 "can't pickle repeated message fields, convert to list first");
598 static PyObject*
Sort(PyObject* pself, PyObject*
args, PyObject* kwds) {
602 PyObject* sort_func = PyDict_GetItemString(kwds,
"sort_function");
603 if (sort_func !=
NULL) {
606 if (PyDict_SetItemString(kwds,
"cmp", sort_func) == -1)
608 if (PyDict_DelItemString(kwds,
"sort_function") == -1)
614 if (full_slice ==
NULL) {
637 static PyObject*
Pop(PyObject* pself, PyObject*
args) {
638 Py_ssize_t
index = -1;
639 if (!PyArg_ParseTuple(
args,
"|n", &
index)) {
644 PyErr_Format(PyExc_IndexError,
"list index (%zd) out of range",
index);
653 static PyObject*
ToStr(PyObject* pself) {
655 if (full_slice ==
NULL) {
662 return PyObject_Repr(list.
get());
665 static PyObject*
MergeFrom(PyObject* pself, PyObject* arg) {
683 self->parent = parent;
689 PyObject*
DeepCopy(PyObject* pself, PyObject* arg) {
695 Py_TYPE(pself)->tp_free(pself);
714 {
"__deepcopy__",
DeepCopy, METH_VARARGS,
715 "Makes a deep copy of the class." },
716 {
"__reduce__",
Reduce, METH_NOARGS,
717 "Outputs picklable representation of the repeated field." },
719 "Appends an object to the repeated container." },
721 "Appends objects to the repeated container." },
722 {
"insert",
Insert, METH_VARARGS,
723 "Inserts an object at the specified position in the container." },
724 {
"pop",
Pop, METH_VARARGS,
725 "Removes an object from the repeated container and returns it." },
726 {
"remove",
Remove, METH_O,
727 "Removes an object from the repeated container." },
728 {
"sort", (PyCFunction)
Sort, METH_VARARGS | METH_KEYWORDS,
729 "Sorts the repeated container."},
730 {
"MergeFrom", (PyCFunction)
MergeFrom, METH_O,
731 "Merges a repeated container into the current container." },
751 PyObject_HashNotImplemented,
758 "A Repeated scalar container",
void AddUInt32(Message *message, const FieldDescriptor *field, uint32 value) const
static PyObject * RichCompare(PyObject *pself, PyObject *other, int opid)
PyObject * Extend(RepeatedScalarContainer *self, PyObject *value)
const EnumDescriptor * enum_type() const
#define GOOGLE_CHECK_GET_FLOAT(arg, value, err)
const Descriptor::ReservedRange value
PyObject * PickleError_class
PyObjectStruct * reset(PyObjectStruct *p=NULL)
float GetRepeatedFloat(const Message &message, const FieldDescriptor *field, int index) const
static PyMappingMethods MpMethods
static PyObject * Remove(PyObject *pself, PyObject *value)
GLenum GLuint GLenum GLsizei length
#define GOOGLE_CHECK_GET_BOOL(arg, value, err)
PyObject * ToStringObject(const FieldDescriptor *descriptor, const string &value)
const std::string & GetRepeatedStringReference(const Message &message, const FieldDescriptor *field, int index, std::string *scratch) const
const Reflection * GetReflection() const
PyObjectStruct * get() const
#define GOOGLE_CHECK_GET_INT64(arg, value, err)
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
google::protobuf::python::RepeatedScalarContainer RepeatedScalarContainer
static PyObject * Sort(PyObject *pself, PyObject *args, PyObject *kwds)
PyTypeObject RepeatedScalarContainer_Type
bool SupportsUnknownEnumValues() const
void AddInt32(Message *message, const FieldDescriptor *field, int32 value) const
static PyObject * Insert(PyObject *pself, PyObject *args)
void AddDouble(Message *message, const FieldDescriptor *field, double value) const
static Py_ssize_t Len(PyObject *pself)
static int AssSubscript(PyObject *pself, PyObject *slice, PyObject *value)
#define PyVarObject_HEAD_INIT(type, size)
double GetRepeatedDouble(const Message &message, const FieldDescriptor *field, int index) const
void AddEnum(Message *message, const FieldDescriptor *field, const EnumValueDescriptor *value) const
uint32 GetRepeatedUInt32(const Message &message, const FieldDescriptor *field, int index) const
int32 GetRepeatedInt32(const Message &message, const FieldDescriptor *field, int index) const
static PyObject * ToStr(PyObject *pself)
void AddEnumValue(Message *message, const FieldDescriptor *field, int value) const
void ClearField(Message *message, const FieldDescriptor *field) const
const FieldDescriptor * parent_field_descriptor
void SetRepeatedEnumValue(Message *message, const FieldDescriptor *field, int index, int value) const
void SetRepeatedDouble(Message *message, const FieldDescriptor *field, int index, double value) const
PyObject * Append(RepeatedScalarContainer *self, PyObject *item)
static void Dealloc(PyObject *pself)
int FieldSize(const Message &message, const FieldDescriptor *field) const
int64 GetRepeatedInt64(const Message &message, const FieldDescriptor *field, int index) const
void SetRepeatedUInt32(Message *message, const FieldDescriptor *field, int index, uint32 value) const
int AssureWritable(CMessage *self)
void SetRepeatedInt64(Message *message, const FieldDescriptor *field, int index, int64 value) const
static PyObject * MergeFrom(PyObject *pself, PyObject *arg)
static PyObject * Pop(PyObject *pself, PyObject *args)
static PyObject * AppendMethod(PyObject *self, PyObject *item)
void SetRepeatedInt32(Message *message, const FieldDescriptor *field, int index, int32 value) const
static PyMethodDef Methods[]
static PySequenceMethods SqMethods
PyObject * DeepCopy(PyObject *pself, PyObject *arg)
ScopedPythonPtr< PyObject > ScopedPyObjectPtr
VALUE enum_descriptor(VALUE self)
#define GOOGLE_CHECK_GET_DOUBLE(arg, value, err)
bool CheckFieldBelongsToMessage(const FieldDescriptor *field_descriptor, const Message *message)
void AddFloat(Message *message, const FieldDescriptor *field, float value) const
int DeleteRepeatedField(CMessage *self, const FieldDescriptor *field_descriptor, PyObject *slice)
static int AssignItem(PyObject *pself, Py_ssize_t index, PyObject *arg)
const upb_json_parsermethod * m
void SetRepeatedUInt64(Message *message, const FieldDescriptor *field, int index, uint64 value) const
uint64 GetRepeatedUInt64(const Message &message, const FieldDescriptor *field, int index) const
void AddInt64(Message *message, const FieldDescriptor *field, int64 value) const
static PyObject * ExtendMethod(PyObject *self, PyObject *value)
static PyObject * Item(PyObject *pself, Py_ssize_t index)
PyObject * Reduce(PyObject *unused_self, PyObject *unused_other)
bool CheckAndSetString(PyObject *arg, Message *message, const FieldDescriptor *descriptor, const Reflection *reflection, bool append, int index)
static PyObject * Subscript(PyObject *pself, PyObject *slice)
static size_t next(const upb_table *t, size_t i)
void SetRepeatedBool(Message *message, const FieldDescriptor *field, int index, bool value) const
#define GOOGLE_CHECK_GET_UINT32(arg, value, err)
GLsizei const GLfloat * value
#define GOOGLE_CHECK_GET_INT32(arg, value, err)
void SetRepeatedEnum(Message *message, const FieldDescriptor *field, int index, const EnumValueDescriptor *value) const
bool GetRepeatedBool(const Message &message, const FieldDescriptor *field, int index) const
static int InternalAssignRepeatedField(RepeatedScalarContainer *self, PyObject *list)
#define GOOGLE_CHECK_GET_UINT64(arg, value, err)
void AddBool(Message *message, const FieldDescriptor *field, bool value) const
GLenum GLuint GLenum GLsizei const GLchar * message
void AddUInt64(Message *message, const FieldDescriptor *field, uint64 value) const
RepeatedScalarContainer * NewContainer(CMessage *parent, const FieldDescriptor *parent_field_descriptor)
void SetRepeatedFloat(Message *message, const FieldDescriptor *field, int index, float value) const
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:58