Skip to content

Commit 569593b

Browse files
committedMay 3, 2017
[server] Python plugins API cleanup part 3
This removes the handleRequest method that returns the headers and body as byte array. This superceeded by the implementation that takes a request and response instances.
1 parent 2afcad2 commit 569593b

10 files changed

+106
-324
lines changed
 

‎python/server/qgsbufferserverrequest.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************************************************************************
22
* This file has been generated automatically from *
33
* *
4-
* ../src/server/qgsbufferserverrequest.h *
4+
* src/server/qgsbufferserverrequest.h *
55
* *
66
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
77
************************************************************************/
@@ -46,7 +46,7 @@ class QgsBufferServerRequest : QgsServerRequest
4646
/************************************************************************
4747
* This file has been generated automatically from *
4848
* *
49-
* ../src/server/qgsbufferserverrequest.h *
49+
* src/server/qgsbufferserverrequest.h *
5050
* *
5151
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
5252
************************************************************************/

‎python/server/qgsbufferserverresponse.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************************************************************************
22
* This file has been generated automatically from *
33
* *
4-
* ../src/server/qgsbufferserverresponse.h *
4+
* src/server/qgsbufferserverresponse.h *
55
* *
66
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
77
************************************************************************/
@@ -141,13 +141,13 @@ class QgsBufferServerResponse: QgsServerResponse
141141

142142

143143
private:
144-
QgsBufferServerResponse(const QgsBufferServerResponse &) ;
144+
QgsBufferServerResponse( const QgsBufferServerResponse & ) ;
145145
};
146146

147147
/************************************************************************
148148
* This file has been generated automatically from *
149149
* *
150-
* ../src/server/qgsbufferserverresponse.h *
150+
* src/server/qgsbufferserverresponse.h *
151151
* *
152152
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
153153
************************************************************************/

‎python/server/qgsserver.sip

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -17,141 +17,6 @@
1717
***************************************************************************/
1818

1919

20-
%MappedType QPair<QByteArray, QByteArray>
21-
{
22-
%TypeHeaderCode
23-
#include <QPair>
24-
#include <QByteArray>
25-
%End
26-
27-
28-
%TypeCode
29-
// Convenience function for converting a QByteArray to a Python str object. (from QtCore/qbytearray.sip)
30-
static PyObject *QByteArrayToPyStr(QByteArray *ba)
31-
{
32-
char *data = ba->data();
33-
34-
if (data)
35-
// QByteArrays may have embedded '\0's so set the size explicitly.
36-
return SIPBytes_FromStringAndSize(data, ba->size());
37-
return SIPBytes_FromString("");
38-
}
39-
40-
%End
41-
42-
43-
%ConvertFromTypeCode
44-
// Create the tuple.
45-
return Py_BuildValue((char *)"OO", QByteArrayToPyStr( &sipCpp->first ), QByteArrayToPyStr( &sipCpp->second ) );
46-
%End
47-
48-
%ConvertToTypeCode
49-
50-
// See if we are just being asked to check the type of the Python
51-
// object.
52-
if (!sipIsErr)
53-
{
54-
// Checking whether or not None has been passed instead of a list
55-
// has already been done.
56-
if (!PyTuple_Check(sipPy) || PyTuple_Size(sipPy) != 2)
57-
return 0;
58-
59-
// Check the type of each element. We specify SIP_NOT_NONE to
60-
// disallow None because it is a list of QPoint, not of a pointer
61-
// to a QPoint, so None isn't appropriate.
62-
for (int i = 0; i < PyTuple_Size(sipPy); ++i)
63-
if (!sipCanConvertToType(PyTuple_GET_ITEM(sipPy, i),
64-
sipType_QByteArray, SIP_NOT_NONE))
65-
return 0;
66-
67-
// The type is valid.
68-
return 1;
69-
}
70-
71-
// Create the instance on the heap.
72-
QPair<QByteArray, QByteArray> *qp = new QPair<QByteArray, QByteArray>;
73-
74-
QByteArray *qba1;
75-
int state;
76-
77-
// Get the address of the element's C++ instance. Note that, in
78-
// this case, we don't apply any ownership changes to the list
79-
// elements, only to the list itself.
80-
qba1 = reinterpret_cast<QByteArray *>(sipConvertToType(
81-
PyTuple_GET_ITEM(sipPy, 0),
82-
sipType_QByteArray, 0,
83-
SIP_NOT_NONE,
84-
&state, sipIsErr));
85-
86-
// Deal with any errors.
87-
if (*sipIsErr)
88-
{
89-
sipReleaseType(qba1, sipType_QByteArray, state);
90-
91-
// Tidy up.
92-
delete qp;
93-
94-
// There is no temporary instance.
95-
return 0;
96-
}
97-
98-
qp->first = *qba1;
99-
100-
// A copy of the QByteArray was assigned to the pair so we no longer
101-
// need it. It may be a temporary instance that should be
102-
// destroyed, or a wrapped instance that should not be destroyed.
103-
// sipReleaseType() will do the right thing.
104-
sipReleaseType(qba1, sipType_QByteArray, state);
105-
106-
/////////////////////////////////////////////
107-
// Second item
108-
109-
QByteArray *qba2;
110-
111-
// Get the address of the element's C++ instance. Note that, in
112-
// this case, we don't apply any ownership changes to the list
113-
// elements, only to the list itself.
114-
qba2 = reinterpret_cast<QByteArray *>(sipConvertToType(
115-
PyTuple_GET_ITEM(sipPy, 1),
116-
sipType_QByteArray, 0,
117-
SIP_NOT_NONE,
118-
&state, sipIsErr));
119-
120-
// Deal with any errors.
121-
if (*sipIsErr)
122-
{
123-
sipReleaseType(qba1, sipType_QByteArray, state);
124-
sipReleaseType(qba2, sipType_QByteArray, state);
125-
126-
// Tidy up.
127-
delete qp;
128-
129-
// There is no temporary instance.
130-
return 0;
131-
}
132-
133-
qp->second = *qba2;
134-
135-
136-
// A copy of the QByteArray was assigned to the pair so we no longer
137-
// need it. It may be a temporary instance that should be
138-
// destroyed, or a wrapped instance that should not be destroyed.
139-
// sipReleaseType() will do the right thing.
140-
sipReleaseType(qba2, sipType_QByteArray, state);
141-
142-
143-
// Return the instance.
144-
*sipCppPtr = qp;
145-
146-
// The instance should be regarded as temporary (and be destroyed as
147-
// soon as it has been used) unless it has been transferred from
148-
// Python. sipGetState() is a convenience function that implements
149-
// this common transfer behavior.
150-
return sipGetState(sipTransferObj);
151-
152-
%End
153-
};
154-
15520
/** \ingroup server
15621
* The QgsServer class provides OGC web services.
15722
*/
@@ -185,18 +50,6 @@ class QgsServer
18550
*/
18651
void handleRequest( QgsServerRequest &request, QgsServerResponse &response );
18752

188-
/** Handles the request from query string
189-
* The query string is normally read from environment
190-
* but can be also passed in args and in this case overrides the environment
191-
* variable.
192-
*
193-
* \param urlstr QString containing the request url (simple quely string must be preceded by '?')
194-
* \param requestMethod QgsServerRequest::Method that indicates the method. Only "GET" or "POST" are supported.
195-
* \param data array of bytes containing post data
196-
* \param map of request headers
197-
* \returns the response headers and body QPair of QByteArray
198-
*/
199-
QPair<QByteArray, QByteArray> handleRequest( const QString &urlstr, const QgsServerRequest::Method requestMethod = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers(), const char *data = nullptr );
20053

20154
/** Returns a pointer to the server interface */
20255
QgsServerInterface *serverInterface();

‎src/server/qgsserver.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -427,49 +427,6 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
427427
}
428428
}
429429

430-
QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString &urlstr, const QgsServerRequest::Method requestMethod, const QgsServerRequest::Headers &headers, const char *data )
431-
{
432-
433-
QUrl url( urlstr );
434-
435-
QByteArray ba;
436-
437-
if ( requestMethod == QgsServerRequest::PostMethod )
438-
{
439-
if ( data )
440-
{
441-
ba.append( data );
442-
}
443-
}
444-
else if ( requestMethod != QgsServerRequest::GetMethod )
445-
{
446-
throw QgsServerException( QStringLiteral( "Invalid method in handleRequest(): only GET or POST is supported" ) );
447-
}
448-
449-
QgsBufferServerRequest request( url, requestMethod, headers, &ba );
450-
QgsBufferServerResponse response;
451-
452-
handleRequest( request, response );
453-
454-
/*
455-
* XXX For compatibility only:
456-
* We should return a (moved) QgsBufferServerResponse instead
457-
*/
458-
QByteArray headerBuffer;
459-
QMap<QString, QString>::const_iterator it;
460-
for ( it = response.headers().constBegin(); it != response.headers().constEnd(); ++it )
461-
{
462-
headerBuffer.append( it.key().toUtf8() );
463-
headerBuffer.append( ": " );
464-
headerBuffer.append( it.value().toUtf8() );
465-
headerBuffer.append( "\n" );
466-
}
467-
headerBuffer.append( "\n" );
468-
469-
// TODO: check that this is not an evil bug!
470-
return QPair<QByteArray, QByteArray>( headerBuffer, response.body() );
471-
472-
}
473430

474431
#ifdef HAVE_SERVER_PYTHON_PLUGINS
475432
void QgsServer::initPython()

‎src/server/qgsserver.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ class SERVER_EXPORT QgsServer
7373
*/
7474
void handleRequest( QgsServerRequest &request, QgsServerResponse &response );
7575

76-
/** Handles the request from query string
77-
* The query string is normally read from environment
78-
* but can be also passed in args and in this case overrides the environment
79-
* variable.
80-
*
81-
* \param urlstr QString containing the request url (simple quely string must be preceded by '?')
82-
* \param requestMethod QgsServerRequest::Method that indicates the method. Only "GET" or "POST" are supported.
83-
* \param data array of bytes containing post data
84-
* \param map of request headers
85-
* \returns the response headers and body QPair of QByteArray
86-
*/
87-
QPair<QByteArray, QByteArray> handleRequest( const QString &urlstr, const QgsServerRequest::Method requestMethod = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers(), const char *data = nullptr );
8876

8977
//! Returns a pointer to the server interface
9078
QgsServerInterfaceImpl *serverInterface() { return sServerInterface; }

0 commit comments

Comments
 (0)
Please sign in to comment.