Skip to content

Commit fb73b7b

Browse files
committed
Converted python2 to python3
1 parent e5d2641 commit fb73b7b

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

convert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from ecg import ECG
3030
from docopt import docopt
31-
from cStringIO import StringIO
31+
from io import BytesIO
3232

3333

3434
def convert(source, layout, outformat, outputfile,
@@ -52,11 +52,11 @@ def convert(source, layout, outformat, outputfile,
5252
interpretation = arguments['--interpretation']
5353

5454
if inputfile:
55-
source = StringIO(open(inputfile).read())
55+
source = BytesIO(open(inputfile, mode='rb').read())
5656
else:
5757
source = {'stu': stu, 'ser': ser, 'obj': obj}
5858

5959
output = convert(source, layout, outformat, outputfile, minor_axis, interpretation)
6060

6161
if output:
62-
print output
62+
print(output)

ecg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from ecg import ECG, i18n
1+
from .ecg import ECG, i18n
22

33
__version__="1.0.1"

ecg/ecg.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import numpy as np
3232
import dicom
3333
import struct
34-
import cStringIO
34+
import io
3535
import requests
36-
import i18n
36+
from . import i18n
3737
import re
3838
from datetime import datetime
3939
from matplotlib import pylab as plt
@@ -134,7 +134,7 @@ def __init__(self, source):
134134
"""
135135

136136
def err(msg):
137-
raise(Exception(msg))
137+
raise Exception
138138

139139
def wadoget(stu, ser, obj):
140140
"""Query the WADO server.
@@ -152,15 +152,15 @@ def wadoget(stu, ser, obj):
152152
headers = {'content-type': 'application/json'}
153153

154154
resp = requests.get(WADOSERVER, params=payload, headers=headers)
155-
return cStringIO.StringIO(resp.content)
155+
return io.StringIO(resp.content)
156156

157157
if isinstance(source, dict):
158158
# dictionary of stu, ser, obj
159159
if set(source.keys()) == set(('stu', 'ser', 'obj')):
160160
inputdata = wadoget(**source)
161161
else:
162162
err("source must be a dictionary of stu, ser and obj")
163-
elif isinstance(source, basestring) or getattr(source, 'getvalue'):
163+
elif isinstance(source, str) or getattr(source, 'getvalue'):
164164
# it is a filename or a (StringIO or cStringIO buffer)
165165
inputdata = source
166166
else:
@@ -171,7 +171,7 @@ def wadoget(stu, ser, obj):
171171
try:
172172
self.dicom = dicom.read_file(inputdata)
173173
"""@ivar: the dicom object."""
174-
except dicom.filereader.InvalidDicomError, err:
174+
except dicom.filereader.InvalidDicomError as err:
175175
raise ECGReadFileError(err)
176176

177177
sequence_item = self.dicom.WaveformSequence[0]
@@ -382,11 +382,11 @@ def interpretation(self):
382382
if not hasattr(self.dicom, 'WaveformAnnotationSequence'):
383383
return ''
384384

385-
ret_str = u''
385+
ret_str = ''
386386
for note in self.dicom.WaveformAnnotationSequence:
387387
if hasattr(note, 'UnformattedTextValue'):
388388
if note.UnformattedTextValue:
389-
ret_str = u"%s\n%s" % (
389+
ret_str = "%s\n%s" % (
390390
ret_str,
391391
note.UnformattedTextValue.decode('ISO-8859-1')
392392
)
@@ -398,9 +398,9 @@ def print_info(self, interpretation):
398398
"""
399399

400400
try:
401-
pat_surname, pat_firstname = self.dicom.PatientName.decode('ISO-8859-1').split('^')
401+
pat_surname, pat_firstname = str(self.dicom.PatientName).split('^')
402402
except ValueError:
403-
pat_surname = self.dicom.PatientName
403+
pat_surname = str(self.dicom.PatientName)
404404
pat_firstname = ''
405405

406406
pat_name = ' '.join((pat_surname, pat_firstname.title()))
@@ -481,7 +481,7 @@ def _save(output):
481481
if outputfile:
482482
_save(outputfile)
483483
else:
484-
output = cStringIO.StringIO()
484+
output = io.StringIO()
485485
_save(output)
486486
return output.getvalue()
487487

@@ -536,7 +536,7 @@ def plot(self, layoutid, mm_mv):
536536
# scaled by mm/mV factor
537537
signal = v_delta + mm_mv * self.signals[signum][left:right]
538538
self.axis.plot(
539-
range(left, right),
539+
list(range(left, right)),
540540
signal,
541541
clip_on=False,
542542
linewidth=0.6,

0 commit comments

Comments
 (0)