Formatting helper
This commit is contained in:
parent
c86afe29ba
commit
c9223686d2
1 changed files with 7 additions and 1 deletions
|
@ -142,6 +142,7 @@ def getFilesize(path):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# Convert hash to hashid for hashfield
|
# Convert hash to hashid for hashfield
|
||||||
def toHashId(hash):
|
def toHashId(hash):
|
||||||
return int(hash[0:4], 16)
|
return int(hash[0:4], 16)
|
||||||
|
@ -206,6 +207,7 @@ def create_connection(address, timeout=None, source_address=None):
|
||||||
sock = socket.create_connection_original(address, timeout, socket.bind_addr)
|
sock = socket.create_connection_original(address, timeout, socket.bind_addr)
|
||||||
return sock
|
return sock
|
||||||
|
|
||||||
|
|
||||||
def socketBindMonkeyPatch(bind_ip, bind_port):
|
def socketBindMonkeyPatch(bind_ip, bind_port):
|
||||||
import socket
|
import socket
|
||||||
logging.info("Monkey patching socket to bind to: %s:%s" % (bind_ip, bind_port))
|
logging.info("Monkey patching socket to bind to: %s:%s" % (bind_ip, bind_port))
|
||||||
|
@ -216,17 +218,20 @@ def socketBindMonkeyPatch(bind_ip, bind_port):
|
||||||
|
|
||||||
def limitedGzipFile(*args, **kwargs):
|
def limitedGzipFile(*args, **kwargs):
|
||||||
import gzip
|
import gzip
|
||||||
|
|
||||||
class LimitedGzipFile(gzip.GzipFile):
|
class LimitedGzipFile(gzip.GzipFile):
|
||||||
def read(self, size=-1):
|
def read(self, size=-1):
|
||||||
return super(LimitedGzipFile, self).read(1024 * 1024 * 25)
|
return super(LimitedGzipFile, self).read(1024 * 1024 * 25)
|
||||||
return LimitedGzipFile(*args, **kwargs)
|
return LimitedGzipFile(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def avg(items):
|
def avg(items):
|
||||||
if len(items) > 0:
|
if len(items) > 0:
|
||||||
return sum(items) / len(items)
|
return sum(items) / len(items)
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def isIp(ip):
|
def isIp(ip):
|
||||||
if ":" in ip: # IPv6
|
if ":" in ip: # IPv6
|
||||||
try:
|
try:
|
||||||
|
@ -242,6 +247,7 @@ def isIp(ip):
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
local_ip_pattern = re.compile(r"^(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])")
|
local_ip_pattern = re.compile(r"^(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])")
|
||||||
def isPrivateIp(ip):
|
def isPrivateIp(ip):
|
||||||
return local_ip_pattern.match(ip)
|
return local_ip_pattern.match(ip)
|
||||||
|
|
Loading…
Reference in a new issue