* This is *temporary* pending properly implementing utilising the Legacy
CAPI host.
* Check in the EDMarketConnector.EDApp.capi_request_data() function *and*
also in some companion.session functions. But not absolutely all possible
entry points because we'll be undoing it when we implement Legacy support.
This *is* sufficient for the current core code entry points. If any plugin
is invoking its own CAPI requests, well it shouldn't be.
This allows you to force use of an expired token so as to test the code
paths for that without waiting up to 4 hours for the current one to
expire.
NB: The Access Token is *only* stored in the headers of the `requests`
object.
In general, doing things like this on import is bad, but this was
changed specifically to remove a bug that causes
--force-localserver-auth to do nothing.
That is caused because while we were careful not to import protocol
until after we were done doing arg things, we did not check to make sure
something else didn't. Companion imports protocol, which thus always
instantiates WindowsProtocolHandler before we can modify some config
state to indicate that we want LinuxProtocolHandler.
* Session.profile() was unused (used to be called from stats.py, but
that uses cached data now).
* Session.query() was unused, other than by itself. Normal calls will
currently be via companion.Session.station(). Future CAPI queries
like `/fleetcarrier` might add their own companion.Session function.
* And in doing so get --capi-pretend-down working again.
* Small tweak to EDMarketConnector to not throw extra exception if there
was a CAPI query exception.
NB: We can't use a generator here to make a python object of the data,
to then use json.dumps() on because the raw_data is a *string* (decoded
from what we received from the CAPI service), and thus it will get
encoded as such, i.e.
"raw_data": "{\"id\":322...
when we want:
"raw_data": {"id":322...
We do not want to json.loads() that string only to then json.dumps() it
because the whole point is that this is the **raw** data to help
diagnose any issues with the CAPI service/data. Such a conversion and
back could either throw an exception we don't want here (because we want
the raw data) or possibly distort things from what was actually
received.
I keep observing it take 3-4s to update the UI after a manual CAPI
request. This showed up as mostly *in*
AppWindow.capi_handle_response(), but the moment I ran it under PyCharm
profile that went down to 400ms.
* The 'EDMC' prefix on all these classes is to make it clear they're for
internal passing around of requests/responses, rather than holding the
literal raw CAPI request and response.
* The request and response queues are now commented, including the
detail that the response queue is created by the caller and then set
'here' by Session.set_capi_response_queue().
* It's no use `dict(CAPIData)` if that contains other `CAPIData`. So,
rather than write something to do that recursively just implement a
simple JSON Encoder class and specify its use.
EDMC.py will also need to make CAPI queries using the new threaded
method, but it has no tkinter, thus we need to pass in the event name
when we expect one to be generated, and only generate it if this is not
None.
It will write a file containing JSON that has a top level dict with a
key per endpoint we have data for, and within each of those a dict with
keys for query_time and the raw_data.
Everything from the opening `{` in that raw_data value until the
matching closing `}` is the raw data from the CAPI service.
The whole file happily goes through `jq -S -C '.'` to examine the
output.
* Using global dict on class CAPIDataRaw as there should only ever be
one of these. *Any* querying of CAPI should record the response data
in this single place.
* But as there'll be multiple endpoints recorded, class
CAPIDataRawEndpoint uses instance variables.
* It is the raw string from
`requests.Response.content.decode(encoding='utf-8')` that is recorded,
not the result of JSON decoding.
* The recording happens in the worker capi_single_query() so it's as
close as possible to where the data came back. The query_time is
allowed to take on the default utc_now() value, rather than matching
the nominal query_time of the request as passed in.
* Base the following on common EDMCCAPIReturn: EDMCFailedrequest,
EDMCCAPIRequest, EDMCCAPIResponse. This saves repeating a bunch of
variable types and comments.
* Use the above throughout the 'Update' button flow.
* Still need to address 'Save Raw Data', i.e. AppWindow.save_raw().