from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .onnx_pb2 import *

import sys

def load(obj):
    '''
    Loads a binary protobuf that stores onnx graph

    @params
    Takes a file-like object (has to implement fileno that returns a file descriptor)
    or a string containing a file name
    @return ONNX ModelProto object
    '''
    model = ModelProto()
    if isinstance(obj, str) or (sys.version_info[0] == 2 and
                                isinstance(obj, unicode_literals.unicode_or_str)):
        with open(obj, 'rb') as f:
            model.ParseFromString(f.read())
    else:
        model.ParseFromString(obj.read())
    return model

@@ -305,58 +305,23 @@
 has 
-to implement fileno that returns a file descriptor
+%22read%22 function
 )%0A  
@@ -436,143 +436,103 @@
  if 
-isinstance(obj, str) or (sys.version_info%5B0%5D == 2 and%0A                                isinstance(obj, unicode_literals.unicode_or_str))
+hasattr(obj, 'read') and callable(obj.read):%0A        model.ParseFromString(obj.read())%0A    else
 :%0A  
@@ -612,60 +612,8 @@
 ())%0A
-    else:%0A        model.ParseFromString(obj.read())%0A
     

Fix string/file-like object detection in onnx.load