Skip to content

Commit 324c983

Browse files
committed
Added format=xml support
1 parent 194efac commit 324c983

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

PostmonServer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
import bottle
44
import json
5+
import xmltodict
56
from bottle import route, run, response
67
from CepTracker import CepTracker
78
import requests
@@ -36,6 +37,12 @@ def format_result(result):
3637
# checa se foi solicitada resposta em JSONP
3738
js_func_name = bottle.request.query.get(jsonp_query_key)
3839

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+
3946
if js_func_name:
4047
# se a resposta vai ser JSONP, o content type deve ser js e seu
4148
# conteudo deve ser JSON
@@ -71,7 +78,6 @@ def verifica_cep(cep):
7178
result = db.get_one(cep, fields={'_id': False, 'v_date': False})
7279

7380
if result:
74-
7581
response.headers['Cache-Control'] = 'public, max-age=2592000'
7682
return format_result(result)
7783
else:

0 commit comments

Comments
 (0)