Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if sys.version_info.major == 2:
urllib_urlopen = urllib2.urlopen
urllib_httperror = urllib2.HTTPError
else:
urllib_urlopen = urllib.request.urlopen
urllib_httperror = urllib.error.HTTPError
try:
urlfile = urllib_urlopen(locn)
content = urlfile.read()
urlfile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
except urllib_httperror:
msg = "Can't find file %s referenced in %s." % (
locn, params.parent_url, )
raise SchemaIOError(msg)
else:
if os.path.exists(locn):
infile = open(locn)
unencoded_content = infile.read()
if sys.version_info.major == 2:
content = unencoded_content
else:
content = unencoded_content.encode()
infile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
if content is None:
msg = "Can't find file %s referenced in %s." % (
locn, params.parent_url, )
raise SchemaIOError(msg)
## if content is None:
raise SchemaIOError(msg)
else:
if os.path.exists(locn):
infile = open(locn)
unencoded_content = infile.read()
if sys.version_info.major == 2:
content = unencoded_content
else:
content = unencoded_content.encode()
infile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
if content is None:
msg = "Can't find file %s referenced in %s." % (
locn, params.parent_url, )
raise SchemaIOError(msg)
## if content is None:
## msg = "Can't find file %s referenced in %s." % (
## locn, params.parent_url, )
## raise SchemaIOError(msg)
return content