MCPcopy Index your code
hub / github.com/modelscope/modelscope / urlretrieve

Function urlretrieve

modelscope/utils/plugins.py:503–528  ·  view source on GitHub ↗
(url, filename, data=None, auth=None)

Source from the content-addressed store, hash-verified

501 from packaging.requirements import Requirement
502
503 def urlretrieve(url, filename, data=None, auth=None):
504 if auth is not None:
505 # https://docs.python.org/2.7/howto/urllib2.html#id6
506 password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
507
508 # Add the username and password.
509 # If we knew the realm, we could use it instead of None.
510 username, password = auth
511 top_level_url = urlparse(url).netloc
512 password_mgr.add_password(None, top_level_url, username, password)
513
514 handler = urllib2.HTTPBasicAuthHandler(password_mgr)
515
516 # create "opener" (OpenerDirector instance)
517 opener = urllib2.build_opener(handler)
518 else:
519 opener = urllib2.build_opener()
520
521 res = opener.open(url, data=data)
522
523 headers = res.info()
524
525 with open(filename, 'wb') as fp:
526 fp.write(res.read())
527
528 return filename, headers
529
530 def compute_checksum(target, algorithm='sha256', blocksize=2**13):
531 hashtype = getattr(hashlib, algorithm)

Callers 1

_download_distFunction · 0.85

Calls 4

openMethod · 0.80
infoMethod · 0.80
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…