qpynetwork_qmap.sip 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // This is the SIP interface definition for the QMap and QMultiMap based mapped
  2. // types specific to the QtNetwork module.
  3. //
  4. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  5. //
  6. // This file is part of PyQt6.
  7. //
  8. // This file may be used under the terms of the GNU General Public License
  9. // version 3.0 as published by the Free Software Foundation and appearing in
  10. // the file LICENSE included in the packaging of this file. Please review the
  11. // following information to ensure the GNU General Public License version 3.0
  12. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  13. //
  14. // If you do not wish to use this file under the terms of the GPL version 3.0
  15. // then you may purchase a commercial license. For more information contact
  16. // info@riverbankcomputing.com.
  17. //
  18. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  19. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. %If (PyQt_SSL)
  21. %MappedType QMultiMap<QSsl::AlternativeNameEntryType, QString>
  22. /TypeHintOut="Dict[QSsl.AlternativeNameEntryType, List[QString]]",
  23. TypeHintValue="[]"/
  24. {
  25. %TypeHeaderCode
  26. #include <qmap.h>
  27. #include <qssl.h>
  28. %End
  29. %ConvertFromTypeCode
  30. // Get the enum member objects that are the dictionary keys.
  31. static PyObject *email_entry = 0;
  32. if (!email_entry)
  33. {
  34. email_entry = sipConvertFromEnum(static_cast<int>(QSsl::EmailEntry),
  35. sipType_QSsl_AlternativeNameEntryType);
  36. if (!email_entry)
  37. return 0;
  38. }
  39. static PyObject *dns_entry = 0;
  40. if (!dns_entry)
  41. {
  42. dns_entry = sipConvertFromEnum(static_cast<int>(QSsl::DnsEntry),
  43. sipType_QSsl_AlternativeNameEntryType);
  44. if (!dns_entry)
  45. return 0;
  46. }
  47. static PyObject *ip_address_entry = 0;
  48. if (!ip_address_entry)
  49. {
  50. ip_address_entry = sipConvertFromEnum(
  51. static_cast<int>(QSsl::IpAddressEntry),
  52. sipType_QSsl_AlternativeNameEntryType);
  53. if (!ip_address_entry)
  54. return 0;
  55. }
  56. // Create the dictionary.
  57. PyObject *d = PyDict_New();
  58. if (!d)
  59. return 0;
  60. QList<QString> vl;
  61. // Handle the Qssl::EmailEntry key.
  62. vl = sipCpp->values(QSsl::EmailEntry);
  63. if (!vl.isEmpty())
  64. {
  65. PyObject *vlobj = PyList_New(vl.count());
  66. if (!vlobj)
  67. {
  68. Py_DECREF(d);
  69. return 0;
  70. }
  71. int rc = PyDict_SetItem(d, email_entry, vlobj);
  72. Py_DECREF(vlobj);
  73. if (rc < 0)
  74. {
  75. Py_DECREF(d);
  76. return 0;
  77. }
  78. for (int i = 0; i < vl.count(); ++i)
  79. {
  80. QString *s = new QString(vl.at(i));
  81. PyObject *vobj = sipConvertFromNewType(s, sipType_QString,
  82. sipTransferObj);
  83. if (!vobj)
  84. {
  85. delete s;
  86. Py_DECREF(d);
  87. return 0;
  88. }
  89. PyList_SetItem(vlobj, i, vobj);
  90. }
  91. }
  92. // Handle the Qssl::DnsEntry key.
  93. vl = sipCpp->values(QSsl::DnsEntry);
  94. if (!vl.isEmpty())
  95. {
  96. PyObject *vlobj = PyList_New(vl.count());
  97. if (!vlobj)
  98. {
  99. Py_DECREF(d);
  100. return 0;
  101. }
  102. int rc = PyDict_SetItem(d, dns_entry, vlobj);
  103. Py_DECREF(vlobj);
  104. if (rc < 0)
  105. {
  106. Py_DECREF(d);
  107. return 0;
  108. }
  109. for (int i = 0; i < vl.count(); ++i)
  110. {
  111. QString *s = new QString(vl.at(i));
  112. PyObject *vobj = sipConvertFromNewType(s, sipType_QString,
  113. sipTransferObj);
  114. if (!vobj)
  115. {
  116. delete s;
  117. Py_DECREF(d);
  118. return 0;
  119. }
  120. PyList_SetItem(vlobj, i, vobj);
  121. }
  122. }
  123. // Handle the Qssl::IpAddressEntry key.
  124. vl = sipCpp->values(QSsl::IpAddressEntry);
  125. if (!vl.isEmpty())
  126. {
  127. PyObject *vlobj = PyList_New(vl.count());
  128. if (!vlobj)
  129. {
  130. Py_DECREF(d);
  131. return 0;
  132. }
  133. int rc = PyDict_SetItem(d, ip_address_entry, vlobj);
  134. Py_DECREF(vlobj);
  135. if (rc < 0)
  136. {
  137. Py_DECREF(d);
  138. return 0;
  139. }
  140. for (int i = 0; i < vl.count(); ++i)
  141. {
  142. QString *s = new QString(vl.at(i));
  143. PyObject *vobj = sipConvertFromNewType(s, sipType_QString,
  144. sipTransferObj);
  145. if (!vobj)
  146. {
  147. delete s;
  148. Py_DECREF(d);
  149. return 0;
  150. }
  151. PyList_SetItem(vlobj, i, vobj);
  152. }
  153. }
  154. return d;
  155. %End
  156. %ConvertToTypeCode
  157. if (!sipIsErr)
  158. return PyDict_Check(sipPy);
  159. PyErr_SetString(PyExc_NotImplementedError,
  160. "converting to QMultiMap<QSsl::AlternativeNameEntryType, QString> is unsupported");
  161. return 0;
  162. %End
  163. };
  164. %End