Skip to content

Commit

Permalink
Merge pull request #19 from GermanoGuerrini/concurrency
Browse files Browse the repository at this point in the history
Concurrency
  • Loading branch information
ricardo-correa authored Feb 13, 2023
2 parents d0a2eb7 + b67f145 commit ef67235
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
54 changes: 26 additions & 28 deletions hda/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class DownloadSizeError(HDAError):


class FTPRequest:

history = None
is_redirect = False
status_code = 200
Expand All @@ -99,7 +98,6 @@ class FTPRequest:
raw = None

def __init__(self, url):

logger.warning("Downloading from FTP url: %s", url)

parsed = urlparse(url)
Expand All @@ -118,7 +116,6 @@ def close(self):
self._ftp.close()

def iter_content(self, chunk_size):

while True:
chunk = self._transfer.recv(chunk_size)
if not chunk:
Expand Down Expand Up @@ -330,38 +327,41 @@ def __init__(
verify=None,
path=None,
):
dotrc = path or os.environ.get("HDA_RC", os.path.expanduser("~/.hdarc"))
credentials = {
"url": url or BROKER_URL,
"user": None,
"password": None,
"verify": True,
}

if url is None or user is None or password is None:
try:
config = read_config(dotrc)
dotrc = path or os.environ.get("HDA_RC", os.path.expanduser("~/.hdarc"))

if url is None:
url = config.get("url")
if os.path.isfile(dotrc):
config = read_config(dotrc)

if user is None:
user = config.get("user")
for key in credentials.keys():
if config.get(key):
credentials[key] = config.get(key)

if password is None:
password = config.get("password")
if url is not None:
credentials["url"] = url

verify = config.get("verify", True)
if user is not None:
credentials["user"] = user

except FileNotFoundError:
raise ConfigurationError("Missing configuration file: %s" % (dotrc))
if password is not None:
credentials["password"] = password

if url is None:
url = BROKER_URL
if verify is not None:
credentials["verify"] = verify

if user is None or password is None:
raise ConfigurationError(
"Missing/incomplete configuration file: %s" % (dotrc)
)
if credentials["user"] is None or credentials["password"] is None:
raise ConfigurationError("Missing or incomplete configuration")

self.url = url
self.user = user
self.password = password
self.verify = True if verify is None else verify
self.url = credentials["url"]
self.user = credentials["user"]
self.password = credentials["password"]
self.verify = credentials["verify"]


class Client(object):
Expand Down Expand Up @@ -479,7 +479,6 @@ def is_token_expired():
return self._token

def _invalidate_token(self):

self._token_creation_time = None

def get_token(self):
Expand Down Expand Up @@ -735,7 +734,6 @@ def stream(self, target, size, download_dir, *args):
headers = None

while tries < self.retry_max:

r = self.robust(self.session.get)(
full,
stream=True,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_hda.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_custom_password_config():

@pytest.mark.skipif(NO_HDARC, reason="No access to HDA")
def test_custom_path_config():
config = Configuration(path=CUSTOM_HDRRC)
config = Configuration(user=None, password=None, path=CUSTOM_HDRRC)
c = Client(config=config)
assert c.config.url == "TESTURL"
assert c.config.user == "TESTUSER"
Expand All @@ -70,6 +70,7 @@ def test_mixed_config():
assert c.config.password == "TP"


@pytest.mark.skipif(NO_HDARC, reason="No access to HDA")
def test_search_results_slicing():
r = [
{"id": 0, "size": 10},
Expand Down

0 comments on commit ef67235

Please sign in to comment.