Software /
code /
prosody-modules
Comparison
mod_rest/README.markdown @ 3809:a70f5a6c7f01
mod_rest: Apply Python source formatting on example
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 01 Jan 2020 12:08:25 +0100 |
parent | 3808:02164f8aebac |
child | 3813:aa1ad69c7c10 |
comparison
equal
deleted
inserted
replaced
3808:02164f8aebac | 3809:a70f5a6c7f01 |
---|---|
121 | 121 |
122 ```python | 122 ```python |
123 from flask import Flask, Response, request | 123 from flask import Flask, Response, request |
124 import xml.etree.ElementTree as ET | 124 import xml.etree.ElementTree as ET |
125 | 125 |
126 app = Flask('echobot') | 126 app = Flask("echobot") |
127 | |
127 | 128 |
128 @app.before_request | 129 @app.before_request |
129 def parse(): | 130 def parse(): |
130 request.stanza = ET.fromstring(request.data) | 131 request.stanza = ET.fromstring(request.data) |
131 | 132 |
132 @app.route('/', methods = ['POST']) | 133 |
134 @app.route("/", methods=["POST"]) | |
133 def hello(): | 135 def hello(): |
134 if request.stanza.tag == 'message': | 136 if request.stanza.tag == "message": |
135 return Response('<message><body>Yes this is bot</body></message>', content_type='application/xmpp+xml') | 137 return Response( |
138 "<message><body>Yes this is bot</body></message>", | |
139 content_type="application/xmpp+xml", | |
140 ) | |
136 | 141 |
137 return Response(status = 501) | 142 return Response(status=501) |
138 | 143 |
139 if __name__ == '__main__': | 144 |
145 if __name__ == "__main__": | |
140 app.run() | 146 app.run() |
141 ``` | 147 ``` |
142 | 148 |
143 # Compatibility | 149 # Compatibility |
144 | 150 |