3131import numpy as np
3232import dicom
3333import struct
34- import cStringIO
34+ import io
3535import requests
36- import i18n
36+ from . import i18n
3737import re
3838from datetime import datetime
3939from 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