Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logger.info(
f"Requesting run of {query} at {connection.url}/api/{connection.api_version}"
)
r = connection.post_json(route="run", data=query)
if r.status_code == 202:
query_id = r.headers["Location"].split("/").pop()
logger.info(
f"Accepted {query} at {connection.url}/api/{connection.api_version} with id {query_id}"
)
return query_id
else:
try:
error = r.json()["msg"]
except (ValueError, KeyError):
error = "Unknown error."
raise FlowclientConnectionError(
f"Error running the query: {error}. Status code: {r.status_code}."
)
def get_versions():
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some
# py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
# case we can only use expanded keywords.
cfg = get_config()
verbose = cfg.verbose
try:
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
except NotThisMethod:
pass
try:
root = os.path.realpath(__file__)
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split("/"):
root = os.path.dirname(root)
except NameError:
return {
"version": "0+unknown",
"full-revisionid": None,
"dirty": None,
"error": "unable to find root of source tree",
"date": None,
if not keywords:
raise NotThisMethod("no keywords at all, weird")
date = keywords.get("date")
if date is not None:
# git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
# datestamp. However we prefer "%ci" (which expands to an "ISO-8601
# -like" string, which we must then edit to make compliant), because
# it's been around since git-1.5.3, and it's too difficult to
# discover which version we're using, or to work around using an
# older one.
date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
refnames = keywords["refnames"].strip()
if refnames.startswith("$Format"):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
# expansion behaves like git log --decorate=short and strips out the
# refs/heads/ and refs/tags/ prefixes that would let us distinguish
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r"\d", r)])
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
elif response.status_code in {401, 403}:
try:
error = response.json()["msg"]
except (ValueError, KeyError):
error = "Unknown access denied error"
raise FlowclientConnectionError(error)
else:
try:
error = response.json()["msg"]
except (ValueError, KeyError):
error = "Unknown error"
try:
status = response.json()["status"]
except (ValueError, KeyError):
status = "Unknown status"
raise FlowclientConnectionError(
f"Something went wrong: {error}. API returned with status code: {response.status_code} and status '{status}'"
)
else:
try:
error_msg = response.json()["msg"]
try:
returned_payload = response.json()["payload"]
payload_info = (
"" if not returned_payload else f" Payload: {returned_payload}"
)
except KeyError:
payload_info = ""
except ValueError:
# Happens if the response body does not contain valid JSON
# (see http://docs.python-requests.org/en/master/api/#requests.Response.json)
error_msg = f"the response did not contain valid JSON"
payload_info = ""
raise FlowclientConnectionError(
f"Something went wrong. API returned with status code {response.status_code}. Error message: '{error_msg}'.{payload_info}"
)
Returns
-------
pandas.DataFrame
Dataframe containing the result
"""
response = connection.get_url(route=location)
if response.status_code != 200:
try:
msg = response.json()["msg"]
more_info = f" Reason: {msg}"
except KeyError:
more_info = ""
raise FlowclientConnectionError(
f"Could not get result. API returned with status code: {response.status_code}.{more_info}"
)
result = response.json()
logger.info(f"Got {connection.url}/api/{connection.api_version}/{location}")
return pd.DataFrame.from_records(result["query_result"])
except ConnectionError as e:
error_msg = f"Unable to connect to FlowKit API at {self.url}: {e}"
logger.info(error_msg)
raise FlowclientConnectionError(error_msg)
if response.status_code in {202, 200, 303}:
return response
elif response.status_code == 404:
raise FileNotFoundError(
f"{self.url}/api/{self.api_version}/{route} not found."
)
elif response.status_code in {401, 403}:
try:
error = response.json()["msg"]
except (ValueError, KeyError):
error = "Unknown access denied error"
raise FlowclientConnectionError(error)
else:
try:
error = response.json()["msg"]
except (ValueError, KeyError):
error = "Unknown error"
try:
status = response.json()["status"]
except (ValueError, KeyError):
status = "Unknown status"
raise FlowclientConnectionError(
f"Something went wrong: {error}. API returned with status code: {response.status_code} and status '{status}'"
)
-------
dict
Available dates in the format {event_type: [list of dates]}
"""
logger.info(
f"Getting {connection.url}/api/{connection.api_version}/available_dates"
)
response = connection.get_url(route=f"available_dates")
if response.status_code != 200:
try:
msg = response.json()["msg"]
more_info = f" Reason: {msg}"
except KeyError:
more_info = ""
raise FlowclientConnectionError(
f"Could not get available dates. API returned with status code: {response.status_code}.{more_info}"
)
result = response.json()["available_dates"]
logger.info(f"Got {connection.url}/api/{connection.api_version}/available_dates")
if event_types is None:
return result
else:
return {k: v for k, v in result.items() if k in event_types}
Identifier of the query to retrieve
Returns
-------
str
"Finished" or "Running"
"""
ready, reply = query_is_ready(connection=connection, query_id=query_id)
if ready:
return "Finished"
else:
try:
return reply.json()["status"]
except (KeyError, TypeError):
raise FlowclientConnectionError(f"No status reported.")
"""
logger.info(
f"Polling server on {connection.url}/api/{connection.api_version}/poll/{query_id}"
)
reply = connection.get_url(route=f"poll/{query_id}")
if reply.status_code == 303:
logger.info(
f"{connection.url}/api/{connection.api_version}/poll/{query_id} ready."
)
return True, reply # Query is ready, so exit the loop
elif reply.status_code == 202:
return False, reply
else:
raise FlowclientConnectionError(
f"Something went wrong: {reply}. API returned with status code: {reply.status_code}"
)