Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix. fix UnicodeDecodeError in cx_Oracle #6

Merged
merged 3 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ipydb/asciitable.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ def draw_headings(headings, sizes):
value = value[:max_fieldsize - 5] + '[...]'
value = value.replace('\n', '^')
value = value.replace('\r', '^').replace('\t', ' ')
value = fmt % value
out.write(value)
try:
value = fmt % value
except UnicodeDecodeError:
value = fmt % value.decode('utf8')
out.write(value.encode('utf8'))
out.write(u'|\n')
if not paginate:
heading_line(sizes)
Expand Down
10 changes: 7 additions & 3 deletions ipydb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import codecs
import csv
from io import StringIO
from io import BytesIO as StringIO
import time

from builtins import input
Expand All @@ -23,8 +23,12 @@ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
self.encoder = codecs.getincrementalencoder(encoding)()

def writerow(self, row):
self.writer.writerow([s.encode("utf-8") if isinstance(s, basestring)
else s for s in row])
try:
self.writer.writerow([s.decode('utf8').encode("utf-8") if isinstance(s, basestring)
else s for s in row])
except:
self.writer.writerow([s.encode("utf-8") if isinstance(s, basestring)
else s for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
Expand Down