Skip to content

Commit

Permalink
Bugfix: Conversion from datetime to str is made outside getRoute.
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Quinteros committed Sep 1, 2016
1 parent 4b69395 commit feeabc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 9 additions & 5 deletions routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ def applyFormat(resultRM, outFormat='xml'):
iterObj = []
for datacenter in resultRM:
for item in datacenter['params']:
# FIXME Should I use 'T' in isoformat?
iterObj.append(datacenter['url'] + '?' +
'&'.join([k + '=' + (str(item[k]) if
type(item[k]) is not
type(datetime.datetime.now())
not isinstance(item[k], datetime.datetime)
else item[k].isoformat()) for k in item
if item[k] not in ('', '*') and
k != 'priority']))
Expand All @@ -351,11 +351,13 @@ def applyFormat(resultRM, outFormat='xml'):
iterObj.append(datacenter['url'])
for item in datacenter['params']:
item['loc'] = item['loc'] if len(item['loc']) else '--'
item['end'] = item['end'] if len(item['end']) \
else now.isoformat()
item['end'] = item['end'] if isinstance(item['end'],
datetime.datetime) \
else now
iterObj.append(item['net'] + ' ' + item['sta'] + ' ' +
item['loc'] + ' ' + item['cha'] + ' ' +
item['start'] + ' ' + item['end'])
item['start'].isoformat('T') + ' ' +
item['end'].isoformat('T'))
iterObj.append('')
iterObj = '\n'.join(iterObj)
return iterObj
Expand Down Expand Up @@ -442,6 +444,7 @@ def application(environ, start_response):
verbo = config.get('Service', 'verbosity')
# Warning is the default value
verboNum = getattr(logging, verbo.upper(), 30)
logging.info('Verbosity configured with %s' % verboNum)
logging.basicConfig(level=verboNum)

if routes is None:
Expand Down Expand Up @@ -472,6 +475,7 @@ def application(environ, start_response):
try:
iterObj = makeQuery(form)

# print iterObj
iterObj = applyFormat(iterObj, outForm)

status = '200 OK'
Expand Down
12 changes: 6 additions & 6 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,12 @@ def getRoute(self, n='*', s='*', l='*', c='*', startD=None, endD=None,

# FIXME This could be done in the function that calls getRoute
# That would be more clear.
for r in result:
for p in r['params']:
if isinstance(p['start'], datetime.datetime):
p['start'] = p['start'].isoformat('T')
if isinstance(p['end'], datetime.datetime):
p['end'] = p['end'].isoformat('T')
# for r in result:
# for p in r['params']:
# if isinstance(p['start'], datetime.datetime):
# p['start'] = p['start'].isoformat('T')
# if isinstance(p['end'], datetime.datetime):
# p['end'] = p['end'].isoformat('T')

return result

Expand Down

0 comments on commit feeabc3

Please sign in to comment.