mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 04:07:52 +00:00
JAG: refactoring extracted string methods to strutil.py module
Signed-off-by: Jed Reynolds <jed@bitratchet.com>
This commit is contained in:
@@ -82,13 +82,11 @@ from enum import Enum
|
|||||||
from enum import IntFlag
|
from enum import IntFlag
|
||||||
import http.client
|
import http.client
|
||||||
from http.client import HTTPResponse
|
from http.client import HTTPResponse
|
||||||
import inspect
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
# from lanforge_client.logg import Logg
|
from .logg import Logg
|
||||||
# from lanforge_client.strutil import *
|
from .strutil import nott, iss
|
||||||
from logg import Logg
|
|
||||||
from pprint import pprint, pformat
|
from pprint import pprint, pformat
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@@ -108,17 +106,6 @@ def _now_sec() -> int:
|
|||||||
return round(time.time() * 1000 * 1000)
|
return round(time.time() * 1000 * 1000)
|
||||||
|
|
||||||
|
|
||||||
def _is(text: str) -> bool:
|
|
||||||
if text is None:
|
|
||||||
return False
|
|
||||||
if (len(text) == 0) or (text.strip() == ""):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def _not(text: str) -> bool:
|
|
||||||
return not _is(text=text)
|
|
||||||
|
|
||||||
|
|
||||||
def default_proxies() -> dict:
|
def default_proxies() -> dict:
|
||||||
return {
|
return {
|
||||||
@@ -277,7 +264,8 @@ class BaseLFJsonRequest:
|
|||||||
:param debug: turn on debugging
|
:param debug: turn on debugging
|
||||||
:return: full url prepended with
|
:return: full url prepended with
|
||||||
"""
|
"""
|
||||||
if _not(url):
|
|
||||||
|
if nott(url):
|
||||||
raise Exception("%s: Bad url[%s]" % (__name__, url))
|
raise Exception("%s: Bad url[%s]" % (__name__, url))
|
||||||
|
|
||||||
corrected_url: str = url
|
corrected_url: str = url
|
||||||
@@ -288,7 +276,7 @@ class BaseLFJsonRequest:
|
|||||||
else:
|
else:
|
||||||
corrected_url = self.session_instance.get_lfclient_url() + '/' + url
|
corrected_url = self.session_instance.get_lfclient_url() + '/' + url
|
||||||
|
|
||||||
if _not(corrected_url):
|
if nott(corrected_url):
|
||||||
raise Exception("%s: Bad url[%s]" % (__name__, url))
|
raise Exception("%s: Bad url[%s]" % (__name__, url))
|
||||||
|
|
||||||
if corrected_url.find('//'):
|
if corrected_url.find('//'):
|
||||||
@@ -479,9 +467,9 @@ class BaseLFJsonRequest:
|
|||||||
|
|
||||||
myrequest.headers['Content-type'] = 'application/json'
|
myrequest.headers['Content-type'] = 'application/json'
|
||||||
sess_id = self.session_instance.get_session_id()
|
sess_id = self.session_instance.get_session_id()
|
||||||
if _is(sess_id):
|
if iss(sess_id):
|
||||||
myrequest.headers[SESSION_HEADER] = str(sess_id)
|
myrequest.headers[SESSION_HEADER] = str(sess_id)
|
||||||
elif _is(session_id_):
|
elif iss(session_id_):
|
||||||
myrequest.headers[SESSION_HEADER] = str(session_id_)
|
myrequest.headers[SESSION_HEADER] = str(session_id_)
|
||||||
else:
|
else:
|
||||||
self.logger.warning("Request sent without X-LFJson-ID header: " + url)
|
self.logger.warning("Request sent without X-LFJson-ID header: " + url)
|
||||||
@@ -769,7 +757,7 @@ class BaseLFJsonRequest:
|
|||||||
if not max_timeout_sec:
|
if not max_timeout_sec:
|
||||||
max_timeout_sec = self.session_instance.max_timeout_sec
|
max_timeout_sec = self.session_instance.max_timeout_sec
|
||||||
|
|
||||||
if _not(url):
|
if nott(url):
|
||||||
raise ValueError("json_get called withou url")
|
raise ValueError("json_get called withou url")
|
||||||
|
|
||||||
url = self.get_corrected_url(url=url)
|
url = self.get_corrected_url(url=url)
|
||||||
|
|||||||
Reference in New Issue
Block a user