You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import hashlib
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
def isDict(object):
|
|
|
|
return isinstance(object, dict)
|
|
|
|
|
|
|
|
|
|
|
|
def mergeDicts(a, b):
|
|
|
|
assert isDict(a), isDict(b)
|
|
|
|
dst = a.copy()
|
|
|
|
|
|
|
|
stack = [(dst, b)]
|
|
|
|
while stack:
|
|
|
|
current_dst, current_src = stack.pop()
|
|
|
|
for key in current_src:
|
|
|
|
if key not in current_dst:
|
|
|
|
current_dst[key] = current_src[key]
|
|
|
|
else:
|
|
|
|
if isDict(current_src[key]) and isDict(current_dst[key]) :
|
|
|
|
stack.append((current_dst[key], current_src[key]))
|
|
|
|
else:
|
|
|
|
current_dst[key] = current_src[key]
|
|
|
|
return dst
|
|
|
|
|
|
|
|
def md5(text):
|
|
|
|
return hashlib.md5(text).hexdigest()
|
|
|
|
|
|
|
|
def getExt(filename):
|
|
|
|
return os.path.splitext(filename)[1][1:]
|
|
|
|
|
|
|
|
def cleanHost(host):
|
|
|
|
if not host.startswith(('http://', 'https://')):
|
|
|
|
host = 'http://' + host
|
|
|
|
|
|
|
|
if not host.endswith('/'):
|
|
|
|
host += '/'
|
|
|
|
|
|
|
|
return host
|