def pack_extension(data): pieces = [] for k in sorted(data.keys()): value = data[k] if isinstance(value, (int, long)): value = "%d" % value assert isinstance(value, str), k assert re.match(r'^[a-zA-Z_\-]+$', k) pieces.append(k + ':' + hashutil.netstring(value)) uri_extension = ''.join(pieces) return uri_extension
def pack_extension(data): pieces = [] for k in sorted(data.keys()): value = data[k] if isinstance(value, (int, long)): value = b"%d" % value if isinstance(k, unicode): k = k.encode("utf-8") assert isinstance(value, bytes), k assert re.match(br'^[a-zA-Z_\-]+$', k) pieces.append(k + b':' + hashutil.netstring(value)) uri_extension = b''.join(pieces) return uri_extension