def perform_test_ssl(self, test, args=None): if os.path.exists(TMPFILE): os.remove(TMPFILE) if args is None: args = [] arg_key = " ".join(args) if arg_key in self.report_json: return self.report_json[arg_key] else: try: ret = subprocess.run([ CONFIG.TEST_SSL_BASH, "testssl/testssl.sh", "--jsonfile", TMPFILE, "--warnings", "off", "--openssl-timeout", str(CONFIG.HTTP_TIMEOUT), "--add-ca", CONFIG.CERT_TRUST_ROOT_CA ] + args + [ "{}:{}".format(self.apis[SECURE_API_KEY]["hostname"], self.apis[SECURE_API_KEY]["port"]) ]) if ret.returncode == 0: with open(TMPFILE) as tls_data: self.report_json[arg_key] = json.load(tls_data) return self.report_json[arg_key] except Exception as e: raise NMOSTestException( test.DISABLED( "Unable to execute testssl.sh. Please see the README for " "installation instructions: {}".format(e))) return None
def __init__(self, auth_callback=None, session=None, client_id=None, client_secret=None, access_token=None, access_token_cache_file=None): self._res = {} self.auth_callback = auth_callback self.pin = None self._access_token_cache_file = access_token_cache_file self._client_id = client_id self._client_secret = client_secret self._access_token = access_token if (access_token_cache_file is not None and access_token is None and os.path.exists(access_token_cache_file)): with open(access_token_cache_file, 'r') as f: self._res = json.load(f) self._callback(self._res) if session is not None: session = weakref.ref(session) self._session = session self._adapter = adapters.HTTPAdapter()
def json_load(folder, filename, **kwargs): """ json.load 函数的封装 """ file = os.path.join(folder, filename) with open(file, 'r', encoding="utf-8-sig") as fp: return json.load(fp, **kwargs)
def _lyricReauth(self): """Lyric reauth.""" if (self._token_cache_file is not None and self._token is None and os.path.exists(self._token_cache_file)): with open(self._token_cache_file, "r") as f: self._token = json.load(f) if self._token is not None: auth = HTTPBasicAuth(self._client_id, self._client_secret) headers = {"Accept": "application/json"} self._lyricApi = OAuth2Session( self._client_id, token=self._token, auto_refresh_url=REFRESH_URL, token_updater=self._token_saver, ) token = self._lyricApi.refresh_token( REFRESH_URL, refresh_token=self._token.get("refresh_token"), headers=headers, auth=auth, ) self._token_saver(token)
def json_load(file, *args, **kwargs): if not os.path.exists(file): return None with open(file, "r", encoding="utf-8-sig") as fp: try: return json.load(fp, *args, **kwargs) except json.JSONDecodeError: return None
def _reauth(self): if self._token_cache_file is not None and self._token is None and os.path.exists( self._token_cache_file): with open(self._token_cache_file, 'r') as f: self._token = json.load(f) if self._token is not None: token = self._mindApi.refresh_token( REFRESH_URL, refresh_token=self._token.get("refresh_token")) self._token_saver(token)
def _lyricAuth(self): if (self._token_cache_file is not None and self._token is None and os.path.exists(self._token_cache_file)): with open(self._token_cache_file, 'r') as f: self._token = json.load(f) if self._token is not None: # force token refresh self._token['expires_at'] = time.time() - 10 self._token['expires_in'] = '-30' self._lyricApi = OAuth2Session(self._client_id, token=self._token, auto_refresh_url=REFRESH_URL, token_updater=self._token_saver)
def load_json_dict(filename, *args): """Checks if file exists. Returns {} if something fails.""" data = {} if os.path.exists(filename): lock.acquire() with open(filename, "r") as f: try: data = _json.load(f) if not isinstance(data, dict): data = {} except: data = {} # TODO: issue a warning and bubble it up lock.release() if args: return {key: data[key] for key in args if key in data} return data
def _reauth(self): if (self._token_cache_file is not None and self._token is None and os.path.exists(self._token_cache_file)): with open(self._token_cache_file, 'r') as f: self._token = json.load(f) if self._token is not None: # self._mijnPonApi = OAuth2Session(client=LegacyApplicationClientJWT(client_id=self._client_id), scope=SCOPE, auto_refresh_url=REFRESH_URL, token_updater=self._token_saver, token=self._token) # token = self._mijnPonApi.fetch_token(token_url=TOKEN_URL, username='******'+self._username, password=self._password, client_id=self._client_id, client_secret=self._client_secret, scope=SCOPE) # self._token_saver(token) token = self._mijnPonApi.refresh_token(REFRESH_URL, refresh_token=self._token.get("refresh_token")) self._token_saver(token)
def __init__( self, username, password, auth_callback=None, session=None, access_token=None, access_token_cache_file=None ): self._res = {} self.username = username self.password = password self.auth_callback = auth_callback self._access_token_cache_file = access_token_cache_file if access_token_cache_file is not None and access_token is None and os.path.exists(access_token_cache_file): with open(access_token_cache_file, "r") as f: self._res = json.load(f) self._callback(self._res) if session is not None: session = weakref.ref(session) self._session = session self._adapter = adapters.HTTPAdapter()
def _lyricAuth(self): """Get lyric authorization.""" if (self._token_cache_file is not None and self._token is None and os.path.exists(self._token_cache_file)): with open(self._token_cache_file, "r") as f: self._token = json.load(f) if self._token is not None: # force token refresh self._token["expires_at"] = time.time() - 10 self._token["expires_in"] = "-30" self._lyricApi = OAuth2Session( self._client_id, token=self._token, auto_refresh_url=REFRESH_URL, token_updater=self._token_saver, )
def __init__(self, username, password, auth_callback=None, session=None, access_token=None, access_token_cache_file=None): self._res = {} self.username = username self.password = password self.auth_callback = auth_callback self._access_token_cache_file = access_token_cache_file if (access_token_cache_file is not None and access_token is None and os.path.exists(access_token_cache_file)): with open(access_token_cache_file, 'r') as f: self._res = json.load(f) self._callback(self._res) if session is not None: session = weakref.ref(session) self._session = session self._adapter = adapters.HTTPAdapter()
def test(self): config = _json.load(open(CONFIG_FILE)) with open(CONFIG_FILE, 'w') as f: config.update(plot_options) f.write(_json.dumps(config)) self.assertRaises(PlotlyError, py._plot_option_logic, {})
def task_load_test_data(): global data with open(TEST_DATA_JSON, "r", encoding="utf-8-sig") as fp: data = json.load(fp)