import collections def get_app_url(config): """ Returns the application's URL, based on the given config. """ return '%s://%s' % (config['PREFERRED_URL_SCHEME'], config['SERVER_HOSTNAME']) def slash_join(*args): """ Joins together strings and guarantees there is only one '/' in between the each string joined. Double slashes ('//') are assumed to be intentional and are not deduplicated. """ def rmslash(path): path = path[1:] if path[0] == '/' else path path = path[:-1] if path[-1] == '/' else path return path args = [rmslash(path) for path in args] return '/'.join(args) def canonicalize(json_obj): """ Returns a JSON object sorted by key. """ if isinstance(json_obj, collections.MutableMapping): sorted_obj = sorted({key: canonicalize(val) for key, val in json_obj}.items()) return collections.OrderedDict(sorted_obj) elif isinstance(json_obj, (list, tuple)): return [canonicalize(val) for val in json_obj] return json_obj