From d4d86172f01db9ce28ade6532fa76d95e72586a1 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Fri, 15 Mar 2019 23:55:23 +0100 Subject: [PATCH] Cmp function backport and Utf8 to Byte response decorator helper funcations --- src/util/helper.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/helper.py b/src/util/helper.py index 1a8cab1e..d84cbc3a 100644 --- a/src/util/helper.py +++ b/src/util/helper.py @@ -289,3 +289,19 @@ def getInterfaceIps(ip_type="ipv4"): res = [re.sub("%.*", "", ip) for ip in res if getIpType(ip) == ip_type and isIp(ip)] return list(set(res)) + + +def cmp(a, b): + return (a > b) - (a < b) + + +def encodeResponse(func): + def wrapper(*args, **kwargs): + back = func(*args, **kwargs) + if "__next__" in dir(back): + for part in back: + yield part.encode() + else: + yield back.encode() + + return wrapper