Skip to content

Commit

Permalink
fix a case echoing h2o utf8 stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Normoyle committed Oct 19, 2014
1 parent 81b1b61 commit 5e453cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion py/h2o.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ def __init__(self, out):
self._out = out

def write(self, x):
self._out.write(x.replace('\n', '\n[{0}] '.format(str(datetime.datetime.now()))))
# got this with random data to parse.. why? it shows up in our stdout?
# UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 41: ordinal not in range(128)
# could we be getting unicode object, or is it just the bytes
try:
s = x.replace('\n', '\n[{0}] '.format(datetime.datetime.now()))
self._out.write(s)
except:
self._out.write(dst,s.encode('utf8'))

def flush(self):
self._out.flush()
Expand Down
8 changes: 4 additions & 4 deletions py/testdir_single_jvm/test_parse_specific_case6.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def test_parse_specific_case6(self):
print "Parsed with special unichr(%s) which is %s:" % (unicodeNum, unichr(unicodeNum))
print "inspect:", h2o.dump_json(inspect)
numRows = inspect['numRows']
self.assertEqual(numRows, expNumRows, msg='Using unichr(0x%x) Wrong numRows: %s Expected: %s' % \
self.assertEqual(numRows, expNumRows, msg='Using quoted unichr(0x%x) Wrong numRows: %s Expected: %s' % \
(unicodeNum, numRows, expNumRows))
numCols = inspect['numCols']
self.assertEqual(numCols, expNumCols, msg='Using unichr(0x%x) Wrong numCols: %s Expected: %s' % \
self.assertEqual(numCols, expNumCols, msg='Using quoted unichr(0x%x) Wrong numCols: %s Expected: %s' % \
(unicodeNum, numCols, expNumCols))

# this is required for the test setup
Expand All @@ -90,10 +90,10 @@ def test_parse_specific_case6(self):

for k in range(expNumCols):
naCnt = inspect['cols'][k]['naCnt']
self.assertEqual(expNaCnt[k], naCnt, msg='Using unichr(0x%x) col: %s naCnt: %d should be: %s' % \
self.assertEqual(expNaCnt[k], naCnt, msg='Using quoted unichr(0x%x) col: %s naCnt: %d should be: %s' % \
(unicodeNum, k, naCnt, expNaCnt[k]))
stype = inspect['cols'][k]['type']
self.assertEqual(expType[k], stype, msg='Using unichr(0x%x) col: %s type: %s should be: %s' % \
self.assertEqual(expType[k], stype, msg='Using quoted unichr(0x%x) col: %s type: %s should be: %s' % \
(unicodeNum, k, stype, expType[k]))

if __name__ == '__main__':
Expand Down

0 comments on commit 5e453cd

Please sign in to comment.