本文整理汇总了Python中qgis.server.QgsServerResponse类的典型用法代码示例。如果您正苦于以下问题:Python QgsServerResponse类的具体用法?Python QgsServerResponse怎么用?Python QgsServerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsServerResponse类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pdf
def get_pdf(self, params: Dict[str,str], response: QgsServerResponse ) -> None:
""" Get PDF files previously exported
"""
ptoken = params.get('TOKEN')
if not ptoken:
raise CadastreError(400,"Missing parameter: token")
path = self.cachedir / ('%s.pdf' % ptoken)
if self.debugMode:
QgsMessageLog.logMessage("GetPDF = path is %s" % path.as_posix(),'cadastre', Qgis.Debug)
if not path.exists():
raise CadastreError(404,"PDF not found")
# Send PDF
response.setHeader('Content-type', 'application/pdf')
response.setStatusCode(200)
try:
response.write(path.read_bytes())
path.unlink()
except:
QgsMessageLog.logMessage("Error occured while reading PDF file",'cadastre',QGis.Critical)
raise
示例2: __init__
def __init__( self ):
QgsServerResponse.__init__(self)
self._buffer = QBuffer()
self._buffer.open(QIODevice.ReadWrite)
示例3: formatResponse
def formatResponse(self, response: QgsServerResponse) -> None:
""" Format error response
"""
body = { 'status': 'fail', 'message': self.msg }
response.clear()
write_json_response(body, response, self.code)
示例4: write_json_response
def write_json_response( data: Dict[str,str], response: QgsServerResponse, code: int=200) -> None:
""" Write data as json response
"""
response.setStatusCode(code)
response.setHeader("Content-Type", "application/json")
response.write(json.dumps(data))