|
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 | import bottle |
4 | 4 | import json |
| 5 | +import xmltodict |
5 | 6 | from bottle import route, run, response |
6 | 7 | from CepTracker import CepTracker |
7 | 8 | import requests |
@@ -36,6 +37,12 @@ def format_result(result): |
36 | 37 | # checa se foi solicitada resposta em JSONP |
37 | 38 | js_func_name = bottle.request.query.get(jsonp_query_key) |
38 | 39 |
|
| 40 | + #checa se foi solicitado xml |
| 41 | + format = bottle.request.query.get('format') |
| 42 | + if format == 'xml': |
| 43 | + response.content_type = 'application/xml' |
| 44 | + return xmltodict.unparse({'result': result}) |
| 45 | + |
39 | 46 | if js_func_name: |
40 | 47 | # se a resposta vai ser JSONP, o content type deve ser js e seu |
41 | 48 | # conteudo deve ser JSON |
@@ -71,7 +78,6 @@ def verifica_cep(cep): |
71 | 78 | result = db.get_one(cep, fields={'_id': False, 'v_date': False}) |
72 | 79 |
|
73 | 80 | if result: |
74 | | - |
75 | 81 | response.headers['Cache-Control'] = 'public, max-age=2592000' |
76 | 82 | return format_result(result) |
77 | 83 | else: |
@@ -110,9 +116,12 @@ def track_pack(provider, track): |
110 | 116 | else: |
111 | 117 | response.status = '404 O Servico %s nao pode ser encontrado' % provider |
112 | 118 |
|
113 | | - |
114 | 119 | bottle.mount('/v1', app_v1) |
115 | 120 |
|
116 | 121 |
|
117 | 122 | def _standalone(port=9876): |
118 | | - run(host='localhost', port=port) |
| 123 | + run(host='0.0.0.0', port=port) |
| 124 | + |
| 125 | + |
| 126 | +if __name__ == "__main__": |
| 127 | + _standalone() |
0 commit comments