parameters: (type,fn)
docstring: General-purpose load of an arbitrary Klampt object from a file
      or URL.
  
      An exception is raised if there is an error loading or
      parsing the file.  Possible exception types include IOError,
      ValueError, and HTTPError.
  
      Args:
          type (str): a Klamp't type, 'json', or 'auto'
          fn (str): a filename.
  
      Returns: 
          Klamp't object
docstring_summary: General-purpose load of an arbitrary Klampt object from a file
      or URL.
docstring_tokens: General - purpose load of an arbitrary Klampt object from a file or URL .
function: def load(type,fn):
      """General-purpose load of an arbitrary Klampt object from a file
      or URL.
  
      An exception is raised if there is an error loading or
      parsing the file.  Possible exception types include IOError,
      ValueError, and HTTPError.
  
      Args:
          type (str): a Klamp't type, 'json', or 'auto'
          fn (str): a filename.
  
      Returns: 
          Klamp't object
      """
      if type == 'auto':
          type = filenameToType(fn)
      
      global loaders,readers
      cppurl = False
      if type == 'WorldModel' or (type == 'Geometry3D' and fn.find('ros://') >= 0):  #these two types handle URLs in C++ API
          cppurl = True
      if not cppurl and fn.find('://') >= 0:
          import urllib2
          src = None
          data = None
          try:
              src = urllib2.urlopen(fn)
              data = src.read()
              print "klampt.io.loader.load(): Download %s HTTP response code %s, size %d bytes"%(fn,src.getcode(),len(data))
          finally:
              if src:
                  src.close()
          if type in loaders:
              #need to write to temporary file
              import os
              import tempfile
              local_filename = None
              fileName, suffix = os.path.splitext(fn)
              with tempfile.NamedTemporaryFile(delete=False,suffix=suffix) as tmp_file:
                  local_filename = tmp_file.name
                  print "klampt.io.loader.load(): saving data to temp file",local_filename
                  tmp_file.write(data)
                  tmp_file.flush()
              res = loaders[type](local_filename)
              os.remove(local_filename)
          elif type in readers or type == 'json':
              res = readers[type](data)
          else:
              raise ValueError("Loading of type "+type+" is not supported")
          return res
  
      if type in loaders:
          return loaders[type](fn)
      elif type in readers or type == 'json':
          text = None
          with open(fn,'r') as f:
              text = ''.join(f.readlines())
          return read(type,text)
      else:
          raise ValueError("Loading of type "+type+" is not supported")
function_tokens: def load ( type , fn ) : if type == 'auto' : type = filenameToType ( fn ) global loaders , readers cppurl = False if type == 'WorldModel' or ( type == 'Geometry3D' and fn . find ( 'ros://' ) >= 0 ) : #these two types handle URLs in C++ API cppurl = True if not cppurl and fn . find ( '://' ) >= 0 : import urllib2 src = None data = None try : src = urllib2 . urlopen ( fn ) data = src . read ( ) print "klampt.io.loader.load(): Download %s HTTP response code %s, size %d bytes" % ( fn , src . getcode ( ) , len ( data ) ) finally : if src : src . close ( ) if type in loaders : #need to write to temporary file import os import tempfile local_filename = None fileName , suffix = os . path . splitext ( fn ) with tempfile . NamedTemporaryFile ( delete = False , suffix = suffix ) as tmp_file : local_filename = tmp_file . name print "klampt.io.loader.load(): saving data to temp file" , local_filename tmp_file . write ( data ) tmp_file . flush ( ) res = loaders [ type ] ( local_filename ) os . remove ( local_filename ) elif type in readers or type == 'json' : res = readers [ type ] ( data ) else : raise ValueError ( "Loading of type " + type + " is not supported" ) return res if type in loaders : return loaders [ type ] ( fn ) elif type in readers or type == 'json' : text = None with open ( fn , 'r' ) as f : text = '' . join ( f . readlines ( ) ) return read ( type , text ) else : raise ValueError ( "Loading of type " + type + " is not supported" )