@@ -357,8 +357,6 @@ def __init__(self, **kwargs):
357357 self .url = url
358358 elif file_obj is not None :
359359 bytestring = file_obj .read ()
360- if isinstance (bytestring , str ):
361- bytestring = bytestring .encode ()
362360 self .url = getattr (file_obj , 'name' , None )
363361 if self .url == '<stdin>' :
364362 self .url = None
@@ -375,6 +373,8 @@ def __init__(self, **kwargs):
375373 else :
376374 raise TypeError (
377375 'No input. Use one of bytestring, file_obj or url.' )
376+ if isinstance (bytestring , str ):
377+ bytestring = bytestring .encode ()
378378 self_is_parent = (
379379 (parent and self .url == parent .url ) or
380380 (url and url .startswith ('#' ) and not self .url ))
@@ -387,8 +387,6 @@ def __init__(self, **kwargs):
387387 if not bytestring :
388388 bytestring = self .fetch_url (
389389 parse_url (self .url ), 'image/svg+xml' )
390- if isinstance (bytestring , str ):
391- bytestring = bytestring .encode ('utf-8' )
392390 if bytestring .startswith (b'\x1f \x8b ' ):
393391 bytestring = gzip .decompress (bytestring )
394392 tree = ElementTree .fromstring (
0 commit comments