run pyupgrade

This commit is contained in:
Robert Resch 2022-01-30 10:33:37 +01:00
parent bf2514cb09
commit 04bd6b3ef0
29 changed files with 173 additions and 221 deletions

View file

@ -183,7 +183,7 @@ async def shutdown():
bumperlog.info("Coroutine canceled") bumperlog.info("Coroutine canceled")
except Exception as e: except Exception as e:
bumperlog.info("Exception: {}".format(e)) bumperlog.info(f"Exception: {e}")
finally: finally:
bumperlog.info("Shutdown complete") bumperlog.info("Shutdown complete")

View file

@ -127,7 +127,7 @@ class ConfServer:
async def start_server(self): async def start_server(self):
try: try:
confserverlog.info( confserverlog.info(
"Starting ConfServer at {}:{}".format(self.address[0], self.address[1]) f"Starting ConfServer at {self.address[0]}:{self.address[1]}"
) )
self.runner = web.AppRunner(self.app) self.runner = web.AppRunner(self.app)
await self.runner.setup() await self.runner.setup()
@ -157,7 +157,7 @@ class ConfServer:
pass pass
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
asyncio.create_task(bumper.shutdown()) asyncio.create_task(bumper.shutdown())
async def stop_server(self): async def stop_server(self):
@ -165,7 +165,7 @@ class ConfServer:
await self.runner.shutdown() await self.runner.shutdown()
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def handle_base(self, request): async def handle_base(self, request):
try: try:
@ -205,7 +205,7 @@ class ConfServer:
return resp return resp
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
@web.middleware @web.middleware
async def log_all_requests(self, request, handler): async def log_all_requests(self, request, handler):
@ -231,7 +231,7 @@ class ConfServer:
try: try:
postbody = json.loads(await request.text()) postbody = json.loads(await request.text())
except Exception as e: except Exception as e:
confserverlog.error("Request body not json: {} - {}".format(e, e.doc)) confserverlog.error(f"Request body not json: {e} - {e.doc}")
postbody = e.doc postbody = e.doc
else: else:
@ -256,12 +256,12 @@ class ConfServer:
return response return response
except web.HTTPNotFound as notfound: except web.HTTPNotFound as notfound:
confserverlog.debug("Request path {} not found".format(request.raw_path)) confserverlog.debug(f"Request path {request.raw_path} not found")
confserverlog.debug(json.dumps(to_log)) confserverlog.debug(json.dumps(to_log))
return notfound return notfound
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
confserverlog.error(json.dumps(to_log)) confserverlog.error(json.dumps(to_log))
return e return e
@ -319,7 +319,7 @@ class ConfServer:
return web.json_response({"status": "invalid service"}) return web.json_response({"status": "invalid service"})
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
pass pass
async def handle_RemoveBot(self, request): async def handle_RemoveBot(self, request):
@ -332,7 +332,7 @@ class ConfServer:
return web.json_response({"status": "successfully removed bot"}) return web.json_response({"status": "successfully removed bot"})
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
pass pass
async def handle_RemoveClient(self, request): async def handle_RemoveClient(self, request):
@ -345,7 +345,7 @@ class ConfServer:
return web.json_response({"status": "successfully removed client"}) return web.json_response({"status": "successfully removed client"})
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
pass pass
async def handle_login(self, request): async def handle_login(self, request):
@ -354,7 +354,7 @@ class ConfServer:
countrycode = request.match_info.get("country", "us") countrycode = request.match_info.get("country", "us")
apptype = request.match_info.get("apptype", "") apptype = request.match_info.get("apptype", "")
confserverlog.info( confserverlog.info(
"client with devid {} attempting login".format(user_devid) f"client with devid {user_devid} attempting login"
) )
if bumper.use_auth: if bumper.use_auth:
if ( if (
@ -417,7 +417,7 @@ class ConfServer:
) )
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def handle_lookup(self, request): async def handle_lookup(self, request):
try: try:
@ -464,7 +464,7 @@ class ConfServer:
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def handle_newauth(self, request): async def handle_newauth(self, request):
# Bumper is only returning the submitted token. No reason yet to create another new token # Bumper is only returning the submitted token. No reason yet to create another new token
@ -485,7 +485,7 @@ class ConfServer:
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def disconnect(self): async def disconnect(self):
try: try:
@ -493,7 +493,7 @@ class ConfServer:
await self.app.shutdown() await self.app.shutdown()
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
class ConfServer_GeneralFunctions: class ConfServer_GeneralFunctions:
def __init__(self): def __init__(self):
@ -514,16 +514,16 @@ class ConfServer:
return tmpaccesstoken return tmpaccesstoken
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
def generate_authcode(self, user, countrycode, token): def generate_authcode(self, user, countrycode, token):
try: try:
tmpauthcode = "{}_{}".format(countrycode, uuid.uuid4().hex) tmpauthcode = f"{countrycode}_{uuid.uuid4().hex}"
bumper.user_add_authcode(user["userid"], token, tmpauthcode) bumper.user_add_authcode(user["userid"], token, tmpauthcode)
return tmpauthcode return tmpauthcode
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def login(self, request): async def login(self, request):
@ -532,7 +532,7 @@ class ConfServer:
countrycode = request.match_info.get("country", "us") countrycode = request.match_info.get("country", "us")
apptype = request.match_info.get("apptype", "") apptype = request.match_info.get("apptype", "")
confserverlog.info( confserverlog.info(
"client with devid {} attempting login".format(user_devid) f"client with devid {user_devid} attempting login"
) )
if bumper.use_auth: if bumper.use_auth:
if ( if (
@ -595,7 +595,7 @@ class ConfServer:
) )
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def get_AuthCode(self, request): async def get_AuthCode(self, request):
@ -660,7 +660,7 @@ class ConfServer:
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
def check_token(self, apptype, countrycode, user, token): def check_token(self, apptype, countrycode, user, token):
try: try:
@ -705,7 +705,7 @@ class ConfServer:
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
def _auth_any(self, devid, apptype, country, request): def _auth_any(self, devid, apptype, country, request):
try: try:
@ -752,7 +752,7 @@ class ConfServer:
if "did" in bot: if "did" in bot:
bumper.user_add_bot(tmpuser["userid"], bot["did"]) bumper.user_add_bot(tmpuser["userid"], bot["did"])
else: else:
confserverlog.error("No DID for bot: {}".format(bot)) confserverlog.error(f"No DID for bot: {bot}")
if "checkLogin" in request.path: # If request was to check a token do so if "checkLogin" in request.path: # If request was to check a token do so
checkToken = self.check_token( checkToken = self.check_token(
@ -782,7 +782,7 @@ class ConfServer:
return body return body
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
def getUserAccountInfo(self, request): def getUserAccountInfo(self, request):
@ -851,7 +851,7 @@ class ConfServer:
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")
async def logout(self, request): async def logout(self, request):
try: try:
@ -875,4 +875,4 @@ class ConfServer:
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
confserverlog.exception("{}".format(e)) confserverlog.exception(f"{e}")

View file

@ -44,7 +44,7 @@ def user_add(userid):
user = user_get(userid) user = user_get(userid)
if not user: if not user:
bumperlog.info("Adding new user with userid: {}".format(newuser.userid)) bumperlog.info(f"Adding new user with userid: {newuser.userid}")
user_full_upsert(newuser.asdict()) user_full_upsert(newuser.asdict())
@ -122,7 +122,7 @@ def user_remove_bot(userid, did):
def user_get_tokens(userid): def user_get_tokens(userid):
tokens = db_get().table("tokens") tokens = db_get().table("tokens")
return tokens.search((Query().userid == userid)) return tokens.search(Query().userid == userid)
def user_get_token(userid, token): def user_get_token(userid, token):
@ -136,7 +136,7 @@ def user_add_token(userid, token):
tokens = opendb.table("tokens") tokens = opendb.table("tokens")
tmptoken = tokens.get((Query().userid == userid) & (Query().token == token)) tmptoken = tokens.get((Query().userid == userid) & (Query().token == token))
if not tmptoken: if not tmptoken:
bumperlog.debug("Adding token {} for userid {}".format(token, userid)) bumperlog.debug(f"Adding token {token} for userid {userid}")
tokens.insert( tokens.insert(
{ {
"userid": userid, "userid": userid,
@ -214,7 +214,7 @@ def revoke_expired_oauths():
oauth = OAuth(**i) oauth = OAuth(**i)
if datetime.now() >= datetime.fromisoformat(oauth.expire_at): if datetime.now() >= datetime.fromisoformat(oauth.expire_at):
bumperlog.debug( bumperlog.debug(
"Removing oauth {} due to expiration".format(oauth.access_token) f"Removing oauth {oauth.access_token} due to expiration"
) )
table.remove(doc_ids=[i.doc_id]) table.remove(doc_ids=[i.doc_id])
@ -228,7 +228,7 @@ def user_revoke_expired_oauths(userid):
oauth = OAuth(**i) oauth = OAuth(**i)
if datetime.now() >= datetime.fromisoformat(oauth.expire_at): if datetime.now() >= datetime.fromisoformat(oauth.expire_at):
bumperlog.debug( bumperlog.debug(
"Removing oauth {} due to expiration".format(oauth.access_token) f"Removing oauth {oauth.access_token} due to expiration"
) )
table.remove(doc_ids=[i.doc_id]) table.remove(doc_ids=[i.doc_id])
@ -243,7 +243,7 @@ def user_add_oauth(userid) -> OAuth:
return OAuth(**entry) return OAuth(**entry)
else: else:
oauth = OAuth.create_new(userid) oauth = OAuth.create_new(userid)
bumperlog.debug("Adding oauth {} for userid {}".format(oauth.access_token, userid)) bumperlog.debug(f"Adding oauth {oauth.access_token} for userid {userid}")
table.insert(oauth.toDB()) table.insert(oauth.toDB())
return oauth return oauth
@ -260,13 +260,13 @@ def get_disconnected_xmpp_clients():
def check_authcode(uid, authcode): def check_authcode(uid, authcode):
bumperlog.debug("Checking for authcode: {}".format(authcode)) bumperlog.debug(f"Checking for authcode: {authcode}")
tokens = db_get().table("tokens") tokens = db_get().table("tokens")
tmpauth = tokens.get( tmpauth = tokens.get(
(Query().authcode == authcode) (Query().authcode == authcode)
& ( # Match authcode & ( # Match authcode
(Query().userid == uid.replace("fuid_", "")) (Query().userid == uid.replace("fuid_", ""))
| (Query().userid == "fuid_{}".format(uid)) | (Query().userid == f"fuid_{uid}")
) # Userid with or without fuid_ ) # Userid with or without fuid_
) )
if tmpauth: if tmpauth:
@ -276,10 +276,10 @@ def check_authcode(uid, authcode):
def loginByItToken(authcode): def loginByItToken(authcode):
bumperlog.debug("Checking for authcode: {}".format(authcode)) bumperlog.debug(f"Checking for authcode: {authcode}")
tokens = db_get().table("tokens") tokens = db_get().table("tokens")
tmpauth = tokens.get( tmpauth = tokens.get(
(Query().authcode == authcode) Query().authcode == authcode
# & ( # Match authcode # & ( # Match authcode
# (Query().userid == uid.replace("fuid_", "")) # (Query().userid == uid.replace("fuid_", ""))
# | (Query().userid == "fuid_{}".format(uid)) # | (Query().userid == "fuid_{}".format(uid))
@ -292,13 +292,13 @@ def loginByItToken(authcode):
def check_token(uid, token): def check_token(uid, token):
bumperlog.debug("Checking for token: {}".format(token)) bumperlog.debug(f"Checking for token: {token}")
tokens = db_get().table("tokens") tokens = db_get().table("tokens")
tmpauth = tokens.get( tmpauth = tokens.get(
(Query().token == token) (Query().token == token)
& ( # Match token & ( # Match token
(Query().userid == uid.replace("fuid_", "")) (Query().userid == uid.replace("fuid_", ""))
| (Query().userid == "fuid_{}".format(uid)) | (Query().userid == f"fuid_{uid}")
) # Userid with or without fuid_ ) # Userid with or without fuid_
) )
if tmpauth: if tmpauth:
@ -329,7 +329,7 @@ def bot_add(sn, did, devclass, resource, company):
not devclass == "" or "@" not in sn or "tmp" not in sn not devclass == "" or "@" not in sn or "tmp" not in sn
): # try to prevent bad additions to the bot list ): # try to prevent bad additions to the bot list
bumperlog.info( bumperlog.info(
"Adding new bot with SN: {} DID: {}".format(newbot.name, newbot.did) f"Adding new bot with SN: {newbot.name} DID: {newbot.did}"
) )
bot_full_upsert(newbot.asdict()) bot_full_upsert(newbot.asdict())
@ -379,7 +379,7 @@ def bot_full_upsert(vacbot):
if "did" in vacbot: if "did" in vacbot:
bots.upsert(vacbot, Bot.did == vacbot["did"]) bots.upsert(vacbot, Bot.did == vacbot["did"])
else: else:
bumperlog.error("No DID in vacbot: {}".format(vacbot)) bumperlog.error(f"No DID in vacbot: {vacbot}")
def bot_set_nick(did, nick): def bot_set_nick(did, nick):
@ -408,7 +408,7 @@ def client_add(userid, realm, resource):
client = client_get(resource) client = client_get(resource)
if not client: if not client:
bumperlog.info("Adding new client with resource {}".format(newclient.resource)) bumperlog.info(f"Adding new client with resource {newclient.resource}")
client_full_upsert(newclient.asdict()) client_full_upsert(newclient.asdict())

View file

@ -6,7 +6,7 @@ from datetime import datetime, timedelta
import bumper import bumper
class VacBotDevice(object): class VacBotDevice:
def __init__( def __init__(
self, did="", vac_bot_device_class="", resource="", name="", nick="", company="" self, did="", vac_bot_device_class="", resource="", name="", nick="", company=""
): ):
@ -32,7 +32,7 @@ class VacBotDevice(object):
} }
class BumperUser(object): class BumperUser:
def __init__(self, userid=""): def __init__(self, userid=""):
self.userid = userid self.userid = userid
self.devices = [] self.devices = []
@ -50,7 +50,7 @@ class GlobalVacBotDevice(VacBotDevice): # EcoVacs Home
deviceName = "" deviceName = ""
class VacBotClient(object): class VacBotClient:
def __init__(self, userid="", realm="", token=""): def __init__(self, userid="", realm="", token=""):
self.userid = userid self.userid = userid
self.realm = realm self.realm = realm
@ -101,7 +101,7 @@ class OAuth:
oauth = OAuth() oauth = OAuth()
oauth.userId = userId oauth.userId = userId
oauth.access_token = uuid.uuid4().hex oauth.access_token = uuid.uuid4().hex
oauth.expire_at = "{}".format(datetime.utcnow() + timedelta(days=bumper.oauth_validity_days)) oauth.expire_at = f"{datetime.utcnow() + timedelta(days=bumper.oauth_validity_days)}"
oauth.refresh_token = uuid.uuid4().hex oauth.refresh_token = uuid.uuid4().hex
return oauth return oauth

View file

@ -70,7 +70,7 @@ class MQTTHelperBot:
] ]
) )
except Exception as e: except Exception as e:
helperbotlog.exception("{}".format(e)) helperbotlog.exception(f"{e}")
async def _wait_for_resp(self, command_dto: CommandDto, request_id: str): async def _wait_for_resp(self, command_dto: CommandDto, request_id: str):
try: try:
@ -85,7 +85,7 @@ class MQTTHelperBot:
except asyncio.CancelledError as e: except asyncio.CancelledError as e:
helperbotlog.debug("wait_for_resp cancelled by asyncio", e, exc_info=True) helperbotlog.debug("wait_for_resp cancelled by asyncio", e, exc_info=True)
except Exception as e: except Exception as e:
helperbotlog.exception("{}".format(e)) helperbotlog.exception(f"{e}")
return { return {
"id": request_id, "id": request_id,
@ -118,7 +118,7 @@ class MQTTHelperBot:
resp = await self._wait_for_resp(command_dto, requestid) resp = await self._wait_for_resp(command_dto, requestid)
return resp return resp
except Exception as e: except Exception as e:
helperbotlog.exception("{}".format(e)) helperbotlog.exception(f"{e}")
return { return {
"id": requestid, "id": requestid,
"errno": 500, "errno": 500,
@ -185,7 +185,7 @@ class MQTTServer:
self.broker = hbmqtt.broker.Broker(config=self.default_config) self.broker = hbmqtt.broker.Broker(config=self.default_config)
except Exception as e: except Exception as e:
mqttserverlog.exception("{}".format(e)) mqttserverlog.exception(f"{e}")
async def broker_coro(self): async def broker_coro(self):
mqttserverlog.info(f"Starting MQTT Server at {self._host}:{self._port}") mqttserverlog.info(f"Starting MQTT Server at {self._host}:{self._port}")
@ -199,7 +199,7 @@ class MQTTServer:
pass pass
except Exception as e: except Exception as e:
mqttserverlog.exception("{}".format(e)) mqttserverlog.exception(f"{e}")
# asyncio.create_task(bumper.shutdown()) # asyncio.create_task(bumper.shutdown())
pass pass
@ -217,7 +217,7 @@ class BumperMQTTServer_Plugin:
"'bumper' section not found in context configuration" "'bumper' section not found in context configuration"
) )
except Exception as e: except Exception as e:
mqttserverlog.exception("{}".format(e)) mqttserverlog.exception(f"{e}")
async def authenticate(self, *args, **kwargs): async def authenticate(self, *args, **kwargs):
authenticated = False authenticated = False

View file

@ -149,7 +149,7 @@ class portal_api_appsvr(plugins.ConfServerApp):
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
# Return fail for GET # Return fail for GET
body = {"result": "fail", "todo": "result"} body = {"result": "fail", "todo": "result"}
@ -189,7 +189,7 @@ class portal_api_appsvr(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_appsvr_oauth_callback(self, request): async def handle_appsvr_oauth_callback(self, request):
try: try:
@ -205,7 +205,7 @@ class portal_api_appsvr(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = portal_api_appsvr() plugin = portal_api_appsvr()

View file

@ -42,8 +42,8 @@ class portal_api_dim(plugins.ConfServerApp):
json_body, randomid json_body, randomid
) )
body = retcmd body = retcmd
logging.debug("Send Bot - {}".format(json_body)) logging.debug(f"Send Bot - {json_body}")
logging.debug("Bot Response - {}".format(body)) logging.debug(f"Bot Response - {body}")
return web.json_response(body) return web.json_response(body)
else: else:
# No response, send error back # No response, send error back
@ -70,7 +70,7 @@ class portal_api_dim(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = portal_api_dim() plugin = portal_api_dim()

View file

@ -32,7 +32,7 @@ class portal_api_ecms(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = portal_api_ecms() plugin = portal_api_ecms()

View file

@ -41,8 +41,8 @@ class portal_api_iot(plugins.ConfServerApp):
json_body, randomid json_body, randomid
) )
body = retcmd body = retcmd
logging.debug("Send Bot - {}".format(json_body)) logging.debug(f"Send Bot - {json_body}")
logging.debug("Bot Response - {}".format(body)) logging.debug(f"Bot Response - {body}")
return web.json_response(body) return web.json_response(body)
else: else:
# No response, send error back # No response, send error back
@ -75,7 +75,7 @@ class portal_api_iot(plugins.ConfServerApp):
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = portal_api_iot() plugin = portal_api_iot()

View file

@ -64,8 +64,8 @@ class portal_api_lg(plugins.ConfServerApp):
json_body, randomid json_body, randomid
) )
body = retcmd body = retcmd
logging.debug("Send Bot - {}".format(json_body)) logging.debug(f"Send Bot - {json_body}")
logging.debug("Bot Response - {}".format(body)) logging.debug(f"Bot Response - {body}")
logs = [] logs = []
logsroot = ET.fromstring(retcmd["resp"]) logsroot = ET.fromstring(retcmd["resp"])
if logsroot.attrib["ret"] == "ok": if logsroot.attrib["ret"] == "ok":
@ -88,7 +88,7 @@ class portal_api_lg(plugins.ConfServerApp):
else: else:
body = {"ret": "ok", "logs": []} body = {"ret": "ok", "logs": []}
logging.debug("lg logs return: {}".format(json.dumps(body))) logging.debug(f"lg logs return: {json.dumps(body)}")
return web.json_response(body) return web.json_response(body)
else: else:
# No response, send error back # No response, send error back
@ -99,7 +99,7 @@ class portal_api_lg(plugins.ConfServerApp):
) )
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
body = {"id": randomid, "errno": bumper.ERR_COMMON, "ret": "fail"} body = {"id": randomid, "errno": bumper.ERR_COMMON, "ret": "fail"}
return web.json_response(body) return web.json_response(body)

View file

@ -33,7 +33,7 @@ class portal_api_neng(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_neng_getShareMsgs(self, request): # EcoVacs Home async def handle_neng_getShareMsgs(self, request): # EcoVacs Home
try: try:
@ -65,7 +65,7 @@ class portal_api_neng(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_neng_getlist(self, request): # EcoVacs Home async def handle_neng_getlist(self, request): # EcoVacs Home
try: try:
@ -91,7 +91,7 @@ class portal_api_neng(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = portal_api_neng() plugin = portal_api_neng()

View file

@ -35,7 +35,7 @@ class portal_api_pim(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_pimFile(self, request): async def handle_pimFile(self, request):
try: try:
@ -44,7 +44,7 @@ class portal_api_pim(plugins.ConfServerApp):
return web.FileResponse(os.path.join(bumper.bumper_dir, "bumper", "web", "images", "robotvac_image.jpg")) return web.FileResponse(os.path.join(bumper.bumper_dir, "bumper", "web", "images", "robotvac_image.jpg"))
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getConfignetAll(self, request): async def handle_getConfignetAll(self, request):
try: try:
@ -52,7 +52,7 @@ class portal_api_pim(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getConfigGroups(self, request): async def handle_getConfigGroups(self, request):
try: try:
@ -60,7 +60,7 @@ class portal_api_pim(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getErrDetail(self, request): async def handle_getErrDetail(self, request):
try: try:
@ -72,7 +72,7 @@ class portal_api_pim(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_product_config_batch(self, request): async def handle_product_config_batch(self, request):
try: try:
@ -99,7 +99,7 @@ class portal_api_pim(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = portal_api_pim() plugin = portal_api_pim()

View file

@ -34,6 +34,6 @@ class api_rapp(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = api_rapp() plugin = api_rapp()

View file

@ -110,7 +110,7 @@ class portal_api_users(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
# Return fail for GET # Return fail for GET
body = {"result": "fail", "todo": "result"} body = {"result": "fail", "todo": "result"}

View file

@ -33,7 +33,7 @@ class upload_global(plugins.ConfServerApp):
return web.FileResponse(os.path.join(bumper.bumper_dir,"bumper","web","images","robotvac_image.jpg")) return web.FileResponse(os.path.join(bumper.bumper_dir,"bumper","web","images","robotvac_image.jpg"))
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")

View file

@ -37,7 +37,7 @@ class v1_private_ad(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getBootScreen(self, request): # EcoVacs Home async def handle_getBootScreen(self, request): # EcoVacs Home
try: try:
@ -52,7 +52,7 @@ class v1_private_ad(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_ad() plugin = v1_private_ad()

View file

@ -47,7 +47,7 @@ class v1_private_campaign(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_campaign() plugin = v1_private_campaign()

View file

@ -48,7 +48,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_checkAPPVersion(self, request): # EcoVacs Home async def handle_checkAPPVersion(self, request): # EcoVacs Home
try: try:
@ -73,7 +73,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_uploadDeviceInfo(self, request): # EcoVacs Home async def handle_uploadDeviceInfo(self, request): # EcoVacs Home
try: try:
@ -88,7 +88,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getSystemReminder(self, request): # EcoVacs Home async def handle_getSystemReminder(self, request): # EcoVacs Home
try: try:
@ -110,7 +110,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getConfig(self, request): async def handle_getConfig(self, request):
try: try:
@ -132,7 +132,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getAreas(self, request): async def handle_getAreas(self, request):
try: try:
@ -147,7 +147,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getAgreementURLBatch(self, request): # EcoVacs Home async def handle_getAgreementURLBatch(self, request): # EcoVacs Home
try: try:
@ -179,7 +179,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getTimestamp(self, request): # EcoVacs Home async def handle_getTimestamp(self, request): # EcoVacs Home
try: try:
@ -197,7 +197,7 @@ class v1_private_common(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_common() plugin = v1_private_common()

View file

@ -38,7 +38,7 @@ class v1_private_message(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getMsgList(self, request): # EcoVacs Home async def handle_getMsgList(self, request): # EcoVacs Home
try: try:
@ -53,7 +53,7 @@ class v1_private_message(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_message() plugin = v1_private_message()

View file

@ -42,7 +42,7 @@ class v1_private_shop(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_shop() plugin = v1_private_shop()

View file

@ -76,7 +76,7 @@ class v1_private_user(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_getUserMenuInfo(self, request): async def handle_getUserMenuInfo(self, request):
try: try:
@ -145,7 +145,7 @@ class v1_private_user(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_changeArea(self, request): async def handle_changeArea(self, request):
try: try:
@ -162,7 +162,7 @@ class v1_private_user(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
async def handle_acceptAgreementBatch(self, request): async def handle_acceptAgreementBatch(self, request):
try: try:
@ -177,7 +177,7 @@ class v1_private_user(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_user() plugin = v1_private_user()

View file

@ -52,7 +52,7 @@ class v1_private_userSetting(plugins.ConfServerApp):
return web.json_response(body) return web.json_response(body)
except Exception as e: except Exception as e:
logging.exception("{}".format(e)) logging.exception(f"{e}")
plugin = v1_private_userSetting() plugin = v1_private_userSetting()

View file

@ -29,7 +29,7 @@ class XMPPServer:
async def start_async_server(self): async def start_async_server(self):
try: try:
xmppserverlog.info( xmppserverlog.info(
"Starting XMPP Server at {}:{}".format(self.address[0], self.address[1]) f"Starting XMPP Server at {self.address[0]}:{self.address[1]}"
) )
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
@ -49,7 +49,7 @@ class XMPPServer:
pass pass
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
asyncio.create_task(bumper.shutdown()) asyncio.create_task(bumper.shutdown())
def disconnect(self): def disconnect(self):
@ -71,7 +71,7 @@ class XMPPServer_Protocol(asyncio.Protocol):
def connection_made(self, transport): def connection_made(self, transport):
if self.aclient: # Existing client... upgrading to TLS if self.aclient: # Existing client... upgrading to TLS
xmppserverlog.debug( xmppserverlog.debug(
"Upgraded connection for {}".format(self.aclient.address) f"Upgraded connection for {self.aclient.address}"
) )
self.aclient.transport = transport self.aclient.transport = transport
else: else:
@ -79,7 +79,7 @@ class XMPPServer_Protocol(asyncio.Protocol):
self.aclient = aclient self.aclient = aclient
XMPPServer.clients.append(aclient) XMPPServer.clients.append(aclient)
self.aclient.state = getattr(aclient, "CONNECT") self.aclient.state = getattr(aclient, "CONNECT")
xmppserverlog.debug("New Connection from {}".format(aclient.address)) xmppserverlog.debug(f"New Connection from {aclient.address}")
def connection_lost(self, error): def connection_lost(self, error):
XMPPServer.clients.remove(self.aclient) XMPPServer.clients.remove(self.aclient)
@ -119,7 +119,7 @@ class XMPPAsyncClient:
self.uid = "" self.uid = ""
self.log_sent_message = True # Set to true to log sends self.log_sent_message = True # Set to true to log sends
self.log_incoming_data = True # Set to true to log sends self.log_incoming_data = True # Set to true to log sends
xmppserverlog.debug("new client with ip {}".format(self.address)) xmppserverlog.debug(f"new client with ip {self.address}")
def send(self, command): def send(self, command):
try: try:
@ -133,7 +133,7 @@ class XMPPAsyncClient:
self.transport.write(command.encode()) self.transport.write(command.encode())
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
def _disconnect(self): def _disconnect(self):
try: try:
@ -149,7 +149,7 @@ class XMPPAsyncClient:
self.transport.close() self.transport.close()
except Exception as e: except Exception as e:
xmppserverlog.error("{}".format(e)) xmppserverlog.error(f"{e}")
def _tag_strip_uri(self, tag): def _tag_strip_uri(self, tag):
try: try:
@ -158,7 +158,7 @@ class XMPPAsyncClient:
return tag return tag
except Exception as e: except Exception as e:
xmppserverlog.error("{}".format(e)) xmppserverlog.error(f"{e}")
def _set_state(self, state): def _set_state(self, state):
try: try:
@ -182,7 +182,7 @@ class XMPPAsyncClient:
self._disconnect() self._disconnect()
except Exception as e: except Exception as e:
xmppserverlog.error("{}".format(e)) xmppserverlog.error(f"{e}")
def _handle_ctl(self, xml, data): def _handle_ctl(self, xml, data):
try: try:
@ -244,7 +244,7 @@ class XMPPAsyncClient:
): ):
ctl_to = xml.get("to") ctl_to = xml.get("to")
if not "from" in xml.attrib: if not "from" in xml.attrib:
xml.attrib["from"] = "{}".format(self.bumper_jid) xml.attrib["from"] = f"{self.bumper_jid}"
rxmlstring = ET.tostring(xml).decode("utf-8") rxmlstring = ET.tostring(xml).decode("utf-8")
# clean up string to remove namespaces added by ET # clean up string to remove namespaces added by ET
rxmlstring = rxmlstring.replace("xmlns:ns0=", "xmlns=") rxmlstring = rxmlstring.replace("xmlns:ns0=", "xmlns=")
@ -255,12 +255,12 @@ class XMPPAsyncClient:
if client.type == self.BOT: if client.type == self.BOT:
if client.uid.lower() in ctl_to.lower(): if client.uid.lower() in ctl_to.lower():
xmppserverlog.debug( xmppserverlog.debug(
"Sending ctl to bot: {}".format(rxmlstring) f"Sending ctl to bot: {rxmlstring}"
) )
client.send(rxmlstring) client.send(rxmlstring)
except Exception as e: except Exception as e:
xmppserverlog.error("{}".format(e)) xmppserverlog.error(f"{e}")
def _handle_ping(self, xml, data): def _handle_ping(self, xml, data):
try: try:
@ -276,7 +276,7 @@ class XMPPAsyncClient:
pingto = xml.get("to") pingto = xml.get("to")
pingfrom = self.bumper_jid pingfrom = self.bumper_jid
if not "from" in xml.attrib: if not "from" in xml.attrib:
xml.attrib["from"] = "{}".format(pingfrom) xml.attrib["from"] = f"{pingfrom}"
pingstring = ET.tostring(xml).decode("utf-8") pingstring = ET.tostring(xml).decode("utf-8")
# clean up string to remove namespaces added by ET # clean up string to remove namespaces added by ET
pingstring = pingstring.replace("xmlns:ns0=", "xmlns=") pingstring = pingstring.replace("xmlns:ns0=", "xmlns=")
@ -293,7 +293,7 @@ class XMPPAsyncClient:
client.send(pingstring) client.send(pingstring)
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
async def schedule_ping(self, time): async def schedule_ping(self, time):
if not self.state == 5: # disconnected if not self.state == 5: # disconnected
@ -308,7 +308,7 @@ class XMPPAsyncClient:
try: try:
ctl_to = xml.get("to") ctl_to = xml.get("to")
if not "from" in xml.attrib: if not "from" in xml.attrib:
xml.attrib["from"] = "{}".format(self.bumper_jid) xml.attrib["from"] = f"{self.bumper_jid}"
if "errno" in data: if "errno" in data:
xmppserverlog.error(f"Error from bot - {data}") xmppserverlog.error(f"Error from bot - {data}")
if ( if (
@ -336,14 +336,14 @@ class XMPPAsyncClient:
adduser = '<iq type="set" id="{}" from="{}" to="{}"><query xmlns="com:ctl"><ctl td="AddUser" id="0000" jid="{}" /></query></iq>'.format( adduser = '<iq type="set" id="{}" from="{}" to="{}"><query xmlns="com:ctl"><ctl td="AddUser" id="0000" jid="{}" /></query></iq>'.format(
uuid.uuid4(), adminuser, self.bumper_jid, newuser uuid.uuid4(), adminuser, self.bumper_jid, newuser
) )
xmppserverlog.debug("Adding User to bot - {}".format(adduser)) xmppserverlog.debug(f"Adding User to bot - {adduser}")
self.send(adduser) self.send(adduser)
# Add user ACs - Manage users, settings, and clean (full access) # Add user ACs - Manage users, settings, and clean (full access)
adduseracs = '<iq type="set" id="{}" from="{}" to="{}"><query xmlns="com:ctl"><ctl td="SetAC" id="1111" jid="{}"><acs><ac name="userman" allow="1"/><ac name="setting" allow="1"/><ac name="clean" allow="1"/></acs></ctl></query></iq>'.format( adduseracs = '<iq type="set" id="{}" from="{}" to="{}"><query xmlns="com:ctl"><ctl td="SetAC" id="1111" jid="{}"><acs><ac name="userman" allow="1"/><ac name="setting" allow="1"/><ac name="clean" allow="1"/></acs></ctl></query></iq>'.format(
uuid.uuid4(), adminuser, self.bumper_jid, newuser uuid.uuid4(), adminuser, self.bumper_jid, newuser
) )
xmppserverlog.debug("Add User ACs to bot - {}".format(adduseracs)) xmppserverlog.debug(f"Add User ACs to bot - {adduseracs}")
self.send(adduseracs) self.send(adduseracs)
# GetUserInfo - Just to confirm it set correctly # GetUserInfo - Just to confirm it set correctly
@ -395,7 +395,7 @@ class XMPPAsyncClient:
client.send(rxmlstring) client.send(rxmlstring)
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
def _handle_connect(self, data, xml=None): def _handle_connect(self, data, xml=None):
try: try:
@ -438,7 +438,7 @@ class XMPPAsyncClient:
): # Handle SASL Auth ): # Handle SASL Auth
self._handle_sasl_auth(xml) self._handle_sasl_auth(xml)
else: else:
xmppserverlog.error("Couldn't handle: {}".format(xml)) xmppserverlog.error(f"Couldn't handle: {xml}")
elif self.state == self.INIT: elif self.state == self.INIT:
if xml == None: if xml == None:
@ -465,10 +465,10 @@ class XMPPAsyncClient:
if child == "bind": if child == "bind":
self._handle_bind(xml) self._handle_bind(xml)
else: else:
xmppserverlog.error("Couldn't handle: {}".format(xml)) xmppserverlog.error(f"Couldn't handle: {xml}")
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
async def _handle_starttls(self, data): async def _handle_starttls(self, data):
try: try:
@ -500,7 +500,7 @@ class XMPPAsyncClient:
protocol.connection_made(new_transport) protocol.connection_made(new_transport)
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
def _handle_sasl_auth(self, xml): def _handle_sasl_auth(self, xml):
try: try:
@ -523,7 +523,7 @@ class XMPPAsyncClient:
if self.devclass: # if there is a devclass it is a bot if self.devclass: # if there is a devclass it is a bot
bumper.bot_add(self.uid, self.uid, self.devclass, "atom", "eco-legacy") bumper.bot_add(self.uid, self.uid, self.devclass, "atom", "eco-legacy")
self.type = self.BOT self.type = self.BOT
xmppserverlog.info("bot authenticated SN: {}".format(self.uid)) xmppserverlog.info(f"bot authenticated SN: {self.uid}")
# Send response # Send response
self.send( self.send(
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>' '<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'
@ -542,7 +542,7 @@ class XMPPAsyncClient:
if auth: if auth:
self.type = self.CONTROLLER self.type = self.CONTROLLER
bumper.client_add(self.uid, "bumper", self.clientresource) bumper.client_add(self.uid, "bumper", self.clientresource)
xmppserverlog.info("client authenticated {}".format(self.uid)) xmppserverlog.info(f"client authenticated {self.uid}")
# Client authenticated, move to next state # Client authenticated, move to next state
self._set_state("INIT") self._set_state("INIT")
@ -559,7 +559,7 @@ class XMPPAsyncClient:
) # Fail ) # Fail
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
def _handle_bind(self, xml): def _handle_bind(self, xml):
try: try:
@ -575,7 +575,7 @@ class XMPPAsyncClient:
clientbindxml = xml.getchildren() clientbindxml = xml.getchildren()
clientresourcexml = clientbindxml[0].getchildren() clientresourcexml = clientbindxml[0].getchildren()
if self.devclass: # its a bot if self.devclass: # its a bot
self.name = "XMPP_Client_{}_{}".format(self.uid, self.devclass) self.name = f"XMPP_Client_{self.uid}_{self.devclass}"
self.bumper_jid = "{}@{}.ecorobot.net/atom".format( self.bumper_jid = "{}@{}.ecorobot.net/atom".format(
self.uid, self.devclass self.uid, self.devclass
) )
@ -589,7 +589,7 @@ class XMPPAsyncClient:
) )
elif len(clientresourcexml) > 0: elif len(clientresourcexml) > 0:
self.clientresource = clientresourcexml[0].text self.clientresource = clientresourcexml[0].text
self.name = "XMPP_Client_{}".format(self.clientresource) self.name = f"XMPP_Client_{self.clientresource}"
self.bumper_jid = "{}@{}/{}".format( self.bumper_jid = "{}@{}/{}".format(
self.uid, XMPPServer.server_id, self.clientresource self.uid, XMPPServer.server_id, self.clientresource
) )
@ -602,8 +602,8 @@ class XMPPAsyncClient:
xml.get("id"), self.bumper_jid xml.get("id"), self.bumper_jid
) )
else: else:
self.name = "XMPP_Client_{}_{}".format(self.uid, self.address) self.name = f"XMPP_Client_{self.uid}_{self.address}"
self.bumper_jid = "{}@{}".format(self.uid, XMPPServer.server_id) self.bumper_jid = f"{self.uid}@{XMPPServer.server_id}"
xmppserverlog.debug( xmppserverlog.debug(
"new client ({}:{} | {})".format( "new client ({}:{} | {})".format(
self.address[0], self.address[1], self.bumper_jid self.address[0], self.address[1], self.bumper_jid
@ -617,7 +617,7 @@ class XMPPAsyncClient:
self.send(res) self.send(res)
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
def _handle_session(self, xml): def _handle_session(self, xml):
res = '<iq type="result" id="{}" />'.format(xml.get("id")) res = '<iq type="result" id="{}" />'.format(xml.get("id"))
@ -636,7 +636,7 @@ class XMPPAsyncClient:
# Most likely a bot, possibly hello world in text # Most likely a bot, possibly hello world in text
# Send dummy return # Send dummy return
self.send('<presence to="{}"> dummy </presence>'.format(self.bumper_jid)) self.send(f'<presence to="{self.bumper_jid}"> dummy </presence>')
# If it is a BOT, send extras # If it is a BOT, send extras
if self.type == self.BOT: if self.type == self.BOT:
@ -663,7 +663,7 @@ class XMPPAsyncClient:
# Send dummy return # Send dummy return
self.send( self.send(
'<presence to="{}"> dummy </presence>'.format(self.bumper_jid) f'<presence to="{self.bumper_jid}"> dummy </presence>'
) )
elif xml.get("type") == "unavailable": elif xml.get("type") == "unavailable":
xmppserverlog.debug( xmppserverlog.debug(
@ -682,7 +682,7 @@ class XMPPAsyncClient:
) )
# Send dummy return # Send dummy return
self.send( self.send(
'<presence to="{}"> dummy </presence>'.format(self.bumper_jid) f'<presence to="{self.bumper_jid}"> dummy </presence>'
) )
def _parse_data(self, data): def _parse_data(self, data):
@ -769,13 +769,13 @@ class XMPPAsyncClient:
else: else:
if not (newdata == "" or newdata == " "): if not (newdata == "" or newdata == " "):
xmppserverlog.error( xmppserverlog.error(
"xml parse error - {} - {}".format(newdata, e) f"xml parse error - {newdata} - {e}"
) )
elif "not well-formed (invalid token)" in e.msg: elif "not well-formed (invalid token)" in e.msg:
# If a lone </stream:stream> - client is signalling end of session/disconnect # If a lone </stream:stream> - client is signalling end of session/disconnect
if not "</stream:stream>" in newdata: if not "</stream:stream>" in newdata:
xmppserverlog.error("xml parse error - {} - {}".format(newdata, e)) xmppserverlog.error(f"xml parse error - {newdata} - {e}")
else: else:
self.send("</stream:stream>") # Close stream self.send("</stream:stream>") # Close stream
@ -783,20 +783,20 @@ class XMPPAsyncClient:
if "<stream:stream" in newdata: # Handle start stream and connect if "<stream:stream" in newdata: # Handle start stream and connect
if self.state == self.CONNECT or self.state == self.INIT: if self.state == self.CONNECT or self.state == self.INIT:
xmppserverlog.debug( xmppserverlog.debug(
"Handling connect data - {}".format(newdata) f"Handling connect data - {newdata}"
) )
self._handle_connect(newdata.encode("utf-8")) self._handle_connect(newdata.encode("utf-8"))
else: else:
if not "</stream:stream>" in newdata: if not "</stream:stream>" in newdata:
xmppserverlog.error( xmppserverlog.error(
"xml parse error - {} - {}".format(newdata, e) f"xml parse error - {newdata} - {e}"
) )
else: else:
self.send("</stream:stream>") # Close stream self.send("</stream:stream>") # Close stream
self._set_state("DISCONNECT") self._set_state("DISCONNECT")
except Exception as e: except Exception as e:
xmppserverlog.exception("{}".format(e)) xmppserverlog.exception(f"{e}")
def _handle_iq(self, xml, data): def _handle_iq(self, xml, data):

View file

@ -1,4 +1,4 @@
import mock from unittest import mock
import bumper import bumper
import asyncio import asyncio
import pytest import pytest

View file

@ -79,7 +79,7 @@ def test_user_db():
{ {
"userid": "testuser", "userid": "testuser",
"token": "token_1234", "token": "token_1234",
"expiration": "{}".format(datetime.now() + timedelta(seconds=-10)), "expiration": f"{datetime.now() + timedelta(seconds=-10)}",
} }
) # Add expired token ) # Add expired token
db.close() db.close()
@ -93,7 +93,7 @@ def test_user_db():
{ {
"userid": "testuser", "userid": "testuser",
"token": "token_1234", "token": "token_1234",
"expiration": "{}".format(datetime.now() + timedelta(seconds=-10)), "expiration": f"{datetime.now() + timedelta(seconds=-10)}",
} }
) # Add expired token ) # Add expired token
db.close() db.close()

View file

@ -1,5 +1,5 @@
import mock from unittest import mock
from mock import patch from unittest.mock import patch
import pytest import pytest
from tinydb.storages import MemoryStorage from tinydb.storages import MemoryStorage
from tinydb import TinyDB, Query from tinydb import TinyDB, Query

View file

@ -1,4 +1,4 @@
import mock from unittest import mock
import bumper import bumper
import asyncio import asyncio
import pytest import pytest
@ -398,7 +398,7 @@ async def test_mqttserver():
) )
await test_client.Client.connect( await test_client.Client.connect(
"mqtts://{}:{}/".format(test_client.address[0], test_client.address[1]), f"mqtts://{test_client.address[0]}:{test_client.address[1]}/",
cafile=bumper.ca_cert, cafile=bumper.ca_cert,
) )
assert ( assert (

View file

@ -1,4 +1,4 @@
import mock from unittest import mock
import bumper import bumper
import asyncio import asyncio
import pytest import pytest
@ -66,9 +66,7 @@ async def test_client_connect_no_starttls(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "client" # Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode( test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -88,9 +86,7 @@ async def test_client_connect_no_starttls(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Client sendss auth - Ignoring the starttls, we don't force this with bumper # Client sendss auth - Ignoring the starttls, we don't force this with bumper
test_data = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'.encode( test_data = b'<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -109,7 +105,7 @@ async def test_client_end_stream(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send end stream from "client" # Send end stream from "client"
test_data = "</stream:stream>".encode("utf-8") test_data = b"</stream:stream>"
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -121,14 +117,14 @@ async def test_client_end_stream(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send abnormal stream from "client" # Send abnormal stream from "client"
test_data = "<badstr />".encode("utf-8") test_data = b"<badstr />"
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Reset mock calls # Reset mock calls
mock_send.reset_mock() mock_send.reset_mock()
# Send blank from "client" # Send blank from "client"
test_data = "".encode("utf-8") test_data = b""
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
@ -141,9 +137,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "client" # Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode( test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -165,7 +159,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
mock_tls = xmppclient._handle_starttls = mock.Mock() mock_tls = xmppclient._handle_starttls = mock.Mock()
# Send start tls from "client" # Send start tls from "client"
test_data = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>".encode("utf-8") test_data = b"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# After upgrading connection, server tells client to proceed with auth again # After upgrading connection, server tells client to proceed with auth again
@ -174,9 +168,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
# After TLS is upgraded, Client establishes session again and will auth this time # After TLS is upgraded, Client establishes session again and will auth this time
# Send connect stream from "client" # Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode( test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -195,9 +187,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Client sends auth # Client sends auth
test_data = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'.encode( test_data = b'<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -277,9 +267,7 @@ async def test_client_init(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "client" # Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode( test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -299,9 +287,7 @@ async def test_client_init(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send bind from "client" # Send bind from "client"
test_data = '<iq type="set" id="5E9872D5-547E-49AF-AE51-9EFAA282F952"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>IOSF53D07BA</resource></bind></iq>'.encode( test_data = b'<iq type="set" id="5E9872D5-547E-49AF-AE51-9EFAA282F952"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>IOSF53D07BA</resource></bind></iq>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -314,9 +300,7 @@ async def test_client_init(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send set session from client # Send set session from client
test_data = '<iq type="set" id="FA1041E7-AA27-43DD-BAA3-64DE2DE56AA3"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>'.encode( test_data = b'<iq type="set" id="FA1041E7-AA27-43DD-BAA3-64DE2DE56AA3"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert xmppclient.state == xmppclient.READY # client moved to READY state assert xmppclient.state == xmppclient.READY # client moved to READY state
@ -329,7 +313,7 @@ async def test_client_init(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send presense from client # Send presense from client
test_data = '<presence type="available"/>'.encode("utf-8") test_data = b'<presence type="available"/>'
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -347,9 +331,7 @@ async def test_bot_connect(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "bot" # Send connect stream from "bot"
test_data = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>".encode( test_data = b"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -369,9 +351,7 @@ async def test_bot_connect(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send auth from "bot" # Send auth from "bot"
test_data = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AEUwMDAwMDAwMDAwMDAwMDAxMjM0AGVuY3J5cHRlZF9wYXNz</auth>".encode( test_data = b"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AEUwMDAwMDAwMDAwMDAwMDAxMjM0AGVuY3J5cHRlZF9wYXNz</auth>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -394,9 +374,7 @@ async def test_bot_init(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "bot" # Send connect stream from "bot"
test_data = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>".encode( test_data = b"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
# Expect 2 calls to send # Expect 2 calls to send
@ -416,9 +394,7 @@ async def test_bot_init(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send bind from "bot" # Send bind from "bot"
test_data = "<iq type='set' id='2521'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>atom</resource></bind></iq>".encode( test_data = b"<iq type='set' id='2521'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>atom</resource></bind></iq>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -431,9 +407,7 @@ async def test_bot_init(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send set session from bot # Send set session from bot
test_data = "<iq type='set' id='2522'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>".encode( test_data = b"<iq type='set' id='2522'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert xmppclient.state == xmppclient.READY # Bot moved to READY state assert xmppclient.state == xmppclient.READY # Bot moved to READY state
@ -445,9 +419,7 @@ async def test_bot_init(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Send presense from bot # Send presense from bot
test_data = "<presence><status>hello world</status></presence><iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>".encode( test_data = b"<presence><status>hello world</status></presence><iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>"
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -467,9 +439,7 @@ async def test_ping_server(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data) mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Ping from bot # Ping from bot
test_data = '<iq xmlns:ns0="urn:xmpp:ping" from="E000BVTNX18700260382@159.ecorobot.net/atom" id="2542" to="159.ecorobot.net" type="get"><ping /></iq>'.encode( test_data = b'<iq xmlns:ns0="urn:xmpp:ping" from="E000BVTNX18700260382@159.ecorobot.net/atom" id="2542" to="159.ecorobot.net" type="get"><ping /></iq>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -501,9 +471,7 @@ async def test_ping_client_to_client(*args, **kwargs):
bumper.xmppserver.XMPPServer.clients.append(xmppclient2) bumper.xmppserver.XMPPServer.clients.append(xmppclient2)
# Ping from user to bot # Ping from user to bot
test_data = '<iq id="104934615" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="get"><ping xmlns="urn:xmpp:ping" /></iq>'.encode( test_data = b'<iq id="104934615" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="get"><ping xmlns="urn:xmpp:ping" /></iq>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -512,9 +480,7 @@ async def test_ping_client_to_client(*args, **kwargs):
) # ping response ) # ping response
# Ping response from bot to user # Ping response from bot to user
test_data = "<iq type='result' to='E0000000000000001234@159.ecorobot.net/atom' id='104934615'/>".encode( test_data = b"<iq type='result' to='E0000000000000001234@159.ecorobot.net/atom' id='104934615'/>"
"utf-8"
)
xmppclient2._parse_data(test_data) xmppclient2._parse_data(test_data)
assert ( assert (
@ -547,9 +513,7 @@ async def test_client_send_iq(*args, **kwargs):
bumper.xmppserver.XMPPServer.clients.append(xmppclient2) bumper.xmppserver.XMPPServer.clients.append(xmppclient2)
# Roster IQ - Only seen from Android app so far # Roster IQ - Only seen from Android app so far
test_data = '<iq id="EE0XQ-2" type="get"><query xmlns="jabber:iq:roster" ></query></iq>'.encode( test_data = b'<iq id="EE0XQ-2" type="get"><query xmlns="jabber:iq:roster" ></query></iq>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -561,9 +525,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Bot Command # Bot Command
test_data = '<iq id="7" to="E0000000000000001234@159.ecorobot.net/atom" type="set"><query xmlns="com:ctl"><ctl id="72107787" td="GetCleanState" /></query></iq>'.encode( test_data = b'<iq id="7" to="E0000000000000001234@159.ecorobot.net/atom" type="set"><query xmlns="com:ctl"><ctl id="72107787" td="GetCleanState" /></query></iq>'
"utf-8"
)
xmppclient._parse_data(test_data) xmppclient._parse_data(test_data)
assert ( assert (
@ -575,9 +537,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Bot response to query # Bot response to query
test_data = '<iq xmlns:ns0="com:ctl" id="2679" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="set"><query><ctl td="ChargeState"><charge h="0" r="a" type="Going" /></ctl></query></iq>'.encode( test_data = b'<iq xmlns:ns0="com:ctl" id="2679" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="set"><query><ctl td="ChargeState"><charge h="0" r="a" type="Going" /></ctl></query></iq>'
"utf-8"
)
xmppclient2._parse_data(test_data) xmppclient2._parse_data(test_data)
assert ( assert (
@ -589,9 +549,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Bot result # Bot result
test_data = "<iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>".encode( test_data = b"<iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>"
"utf-8"
)
xmppclient2._parse_data(test_data) xmppclient2._parse_data(test_data)
assert ( assert (
@ -603,9 +561,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Bot iq set # Bot iq set
test_data = "<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='2700'><query xmlns='com:ctl'><ctl td='BatteryInfo'><battery power='100'/></ctl></query></iq>".encode( test_data = b"<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='2700'><query xmlns='com:ctl'><ctl td='BatteryInfo'><battery power='100'/></ctl></query></iq>"
"utf-8"
)
xmppclient2._parse_data(test_data) xmppclient2._parse_data(test_data)
assert ( assert (
@ -617,9 +573,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Bot error report # Bot error report
test_data = "<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='631'><query xmlns='com:ctl'><ctl td='error' errs='102'/></query></iq>".encode( test_data = b"<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='631'><query xmlns='com:ctl'><ctl td='error' errs='102'/></query></iq>"
"utf-8"
)
xmppclient2._parse_data(test_data) xmppclient2._parse_data(test_data)
assert ( assert (
@ -631,9 +585,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock() mock_send.reset_mock()
# Bot "DorpError" to all # Bot "DorpError" to all
test_data = "<iq to='rl.ecorobot.net' type='set' id='1234'><query xmlns='com:sf'><sf td='pub' t='log' ts='1559893796000' tp='p' k='DeviceAlert' v='DorpError' f='E0000000000000001234@159.ecorobot.net' g='fuid_tmpuser@ecouser.net'/></query></iq>".encode( test_data = b"<iq to='rl.ecorobot.net' type='set' id='1234'><query xmlns='com:sf'><sf td='pub' t='log' ts='1559893796000' tp='p' k='DeviceAlert' v='DorpError' f='E0000000000000001234@159.ecorobot.net' g='fuid_tmpuser@ecouser.net'/></query></iq>"
"utf-8"
)
xmppclient2._parse_data(test_data) xmppclient2._parse_data(test_data)
assert ( assert (
mock_send.mock_calls[0].args[0] mock_send.mock_calls[0].args[0]

View file

@ -1,4 +1,4 @@
from mock import patch from unittest.mock import patch
import bumper import bumper