def _json_from_url(url):
 parts = compat.urlparse(url)
 if (parts.scheme in ('', 'file')):
  handle = compat.open_unicode(parts.path)
 elif (len(parts.scheme) == 1):
  handle = compat.open_unicode(url)
 else:
  handle = compat.urlopen(url)
 try:
  desc = json.load(handle)
 except ValueError as e:
  import pdb
  pdb.set_trace()
  raise SyntaxError(('Syntax error in %s: %s' % (url, str(e))))
 finally:
  handle.close()
 return desc

def _json_from_url ( url ) : parts = compat . urlparse ( url ) if ( parts . scheme in ( '' , 'file' ) ) : handle = compat . open_unicode ( parts . path ) elif ( len ( parts . scheme ) == 1 ) : handle = compat . open_unicode ( url ) else : handle = compat . urlopen ( url ) try : desc = json . load ( handle ) except ValueError as e : import pdb pdb . set_trace ( ) raise SyntaxError ( ( 'Syntax error in %s: %s' % ( url , str ( e ) ) ) ) finally : handle . close ( ) return desc
opens resource either as a file with open()or as url with urlopen() .