Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def urlopenstub(url):
if url.find("readthedocs.org") != -1:
host = url.split("/")[2]
package = host.split(".")[0]
# Faking the docs:
if package in ("distribute", "complete"):
return FakeResponse(200)
else:
# This package doesn't have docs on pythonhosted.org:
return FakeResponse(404)
if url.startswith("http://pypi.org/project"):
filename = url[len("http://pypi.org/project/") :]
# Faking PyPI package
datafile = resource_filename(
__name__, os.path.join("testdata", "xmlrpcdata", filename + ".html")
)
return FakeResponse(200, datafile)
if url.startswith("http://pypi.python.org/packages"):
filename = [x for x in url.split("/") if x][-1]
# Faking PyPI file downloads
datafile = resource_filename(
__name__, os.path.join("testdata", "distributions", filename)
)
return FakeResponse(200, datafile)
if url.startswith("http://pypi.org/project"):
filename = url[len("http://pypi.org/project/") :]
# Faking PyPI package
datafile = resource_filename(
__name__, os.path.join("testdata", "xmlrpcdata", filename + ".html")
)
return FakeResponse(200, datafile)
if url.startswith("http://pypi.python.org/packages"):
filename = [x for x in url.split("/") if x][-1]
# Faking PyPI file downloads
datafile = resource_filename(
__name__, os.path.join("testdata", "distributions", filename)
)
return FakeResponse(200, datafile)
raise ValueError("Don't know how to stub " + url)
def urlopenstub(url):
if url.find("readthedocs.org") != -1:
host = url.split("/")[2]
package = host.split(".")[0]
# Faking the docs:
if package in ("distribute", "complete"):
return FakeResponse(200)
else:
# This package doesn't have docs on pythonhosted.org:
return FakeResponse(404)
if url.startswith("http://pypi.org/project"):
filename = url[len("http://pypi.org/project/") :]
# Faking PyPI package
datafile = resource_filename(
__name__, os.path.join("testdata", "xmlrpcdata", filename + ".html")
)
return FakeResponse(200, datafile)
if url.startswith("http://pypi.python.org/packages"):
filename = [x for x in url.split("/") if x][-1]
# Faking PyPI file downloads
datafile = resource_filename(