From eb2264e91a7fef4170eade4bc6af9c0c4fe9694a Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 12 Sep 2015 17:10:38 +0200 Subject: improve display of non-ascii contents fixes #283 --- libmproxy/utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'libmproxy/utils.py') diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 4b591250..8bd843a0 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import (absolute_import, print_function, division) import os import datetime import re @@ -30,15 +30,16 @@ def isBin(s): """ for i in s: i = ord(i) - if i < 9: - return True - elif i > 13 and i < 32: - return True - elif i > 126: + if i < 9 or 13 < i < 32 or 126 < i: return True return False +def isMostlyBin(s): + s = s[:100] + return sum(isBin(ch) for ch in s)/len(s) > 0.3 + + def isXML(s): for i in s: if i in "\n \t": -- cgit v1.2.3