diff options
Diffstat (limited to 'sources/pyside6/PySide6/glue/qtnetwork.cpp')
-rw-r--r-- | sources/pyside6/PySide6/glue/qtnetwork.cpp | 126 |
1 files changed, 80 insertions, 46 deletions
diff --git a/sources/pyside6/PySide6/glue/qtnetwork.cpp b/sources/pyside6/PySide6/glue/qtnetwork.cpp index 277dd6d7c..f635f4671 100644 --- a/sources/pyside6/PySide6/glue/qtnetwork.cpp +++ b/sources/pyside6/PySide6/glue/qtnetwork.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // @snippet qudpsocket-readdatagram Shiboken::AutoArrayPointer<char> data(%ARGUMENT_NAMES); @@ -51,20 +15,28 @@ PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QHostAddress](ha)); PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[quint16](port)); // @snippet qudpsocket-readdatagram -// @snippet qhostinfo-lookuphost-callable -auto *callable = %PYARG_2; -auto cppCallback = [callable](const QHostInfo &hostInfo) +// @snippet qhostinfo-lookuphost-functor +struct QHostInfoFunctor : public Shiboken::PyObjectHolder +{ +public: + using Shiboken::PyObjectHolder::PyObjectHolder; + + void operator()(const QHostInfo &hostInfo); +}; + +void QHostInfoFunctor::operator()(const QHostInfo &hostInfo) { Shiboken::GilState state; Shiboken::AutoDecRef arglist(PyTuple_New(1)); auto *pyHostInfo = %CONVERTTOPYTHON[QHostInfo](hostInfo); PyTuple_SET_ITEM(arglist.object(), 0, pyHostInfo); - Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); - Py_DECREF(callable); -}; + Shiboken::AutoDecRef ret(PyObject_CallObject(object(), arglist)); + release(); // single shot +} +// @snippet qhostinfo-lookuphost-functor -Py_INCREF(callable); -%CPPSELF.%FUNCTION_NAME(%1, cppCallback); +// @snippet qhostinfo-lookuphost-callable +%CPPSELF.%FUNCTION_NAME(%1, QHostInfoFunctor(%PYARG_2)); // @snippet qhostinfo-lookuphost-callable // @snippet qipv6address-len @@ -94,3 +66,65 @@ quint8 item = %CONVERTTOCPP[quint8](_value); %CPPSELF.c[_i] = item; return 0; // @snippet qipv6address-setitem + +// @snippet qrestaccessmanager-functor +class QRestFunctor +{ +public: + explicit QRestFunctor(PyObject *callable) noexcept : m_callable(callable) + { + Py_INCREF(callable); + } + + void operator()(QRestReply &restReply); + +private: + PyObject *m_callable; +}; + +void QRestFunctor::operator()(QRestReply &restReply) +{ + Q_ASSERT(m_callable); + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + auto *restReplyPtr = &restReply; + auto *pyRestReply = %CONVERTTOPYTHON[QRestReply*](restReplyPtr); + PyTuple_SET_ITEM(arglist.object(), 0, pyRestReply); + Shiboken::AutoDecRef ret(PyObject_CallObject(m_callable, arglist)); + Py_DECREF(m_callable); + m_callable = nullptr; +} +// @snippet qrestaccessmanager-functor + +// @snippet qrestaccessmanager-callback +auto *networkReply = %CPPSELF.%FUNCTION_NAME(%1, %2, QRestFunctor(%PYARG_3)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](networkReply); +// @snippet qrestaccessmanager-callback + +// @snippet qrestaccessmanager-data-callback +auto *networkReply = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, QRestFunctor(%PYARG_4)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](networkReply); +// @snippet qrestaccessmanager-data-callback + +// @snippet qrestaccessmanager-method-data-callback +auto *networkReply = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, QRestFunctor(%PYARG_5)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](networkReply); +// @snippet qrestaccessmanager-method-data-callback + +// @snippet qrestreply-readjson +QJsonParseError jsonParseError; +std::optional<QJsonDocument> documentOptional = %CPPSELF.%FUNCTION_NAME(&jsonParseError); + +PyObject *pyDocument{}; +if (documentOptional.has_value()) { + const auto &document = documentOptional.value(); + pyDocument = %CONVERTTOPYTHON[QJsonDocument](document); +} else { + pyDocument = Py_None; + Py_INCREF(Py_None); +} + +%PYARG_0 = PyTuple_New(2); +PyTuple_SetItem(%PYARG_0, 0, pyDocument); +PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QJsonParseError](jsonParseError)); +// @snippet qrestreply-readjson |