[docs]defget_class_by_name(name,relative_path=None):""" Resolve class by name :param name: (str) "%s.%s" % (module.name, class.name) :return: (class) """assertnameisnotNonemodule_path,class_name=name.rsplit(".",1)module__=get_module(module_path,relative_path=relative_path)class_=getattr(module__,class_name)returnclass_
[docs]deffile_from_url(url:str)->IOBase:""" Load content from a file specified by a URL. This can be every type of URL supported by pythons urllib (e.g. http://, file://, etc ). Giving the basic auth credentials in the URL in the form http://user:password@hostname:port/path is supported. Returns: file handle on the file """parsed=urllib.parse.urlparse(url)ifparsed.usernameandparsed.password:request=urllib.request.Request(parsed._replace(netloc=parsed.netloc.split("@")[1]).geturl())base64string=base64.b64encode(bytes("%s:%s"%(parsed.username,parsed.password),"ascii"))request.add_header("Authorization","Basic %s"%base64string.decode("utf-8"))f_handle=urllib.request.urlopen(request)else:f_handle=urllib.request.urlopen(url)returnf_handle
[docs]defextend_none_allowed_list(list1:list|None,list2:list|None)->list|None:""" Extend a list with another list which both can be None. If one of the lists is None, the other list is returned. If both lists are None, None is returned. Args: list1: list to extend list2: list to extend with """iflist1isNone:returnlist2iflist2isNone:returnlist1returnlist1+list2