def parse_URL(cls, URL_IN="", return_type_IN=URL_PARSE_RETURN_DOMAIN, *args, **kwargs): # return reference value_OUT = "" # declare variables network_helper = None # make network helper instance network_helper = Network_Helper() # see what we've been asked to return if return_type_IN == cls.URL_PARSE_RETURN_PATH: # path (everything after the domain, including query string, etc., # not just the path). value_OUT = network_helper.parse_URL(URL_IN, Network_Helper.URL_PARSE_RETURN_ALL_AFTER_DOMAIN) else: # domain value_OUT = network_helper.parse_URL(URL_IN, Network_Helper.URL_PARSE_RETURN_TRIMMED_DOMAIN) # -- END check to see what we return. --# return value_OUT
def parse_and_store_URL(self, URL_IN="", is_redirect_IN=False, *args, **kwargs): """ Accepts a URL. Parses it, places the components in nested django fields. Returns the trimmed domain name. """ # return reference value_OUT = "" # declare variables network_helper = None trimmed_domain = "" path = "" protocol = "" params = "" query_string = "" domain_path = "" # make network helper instance network_helper = Network_Helper() # Got a URL? if (URL_IN) and (URL_IN != None) and (URL_IN != ""): # yes - use call to get domain to parse URL. trimmed_domain = network_helper.parse_URL(URL_IN, Network_Helper.URL_PARSE_RETURN_TRIMMED_DOMAIN) # get path (everything after the domain, not just the path). path = network_helper.parse_URL( URL_IN, Network_Helper.URL_PARSE_RETURN_ALL_AFTER_DOMAIN, use_last_parse_result=True ) # get parse result for the rest. parse_result = network_helper.latest_parse_result # protocol protocol = parse_result.scheme # is this a redirect URL? if is_redirect_IN == True: # redirect - store in redirect fields. self.redirect_domain_name = trimmed_domain self.redirect_domain_path = path self.redirect_full_url = URL_IN self.redirect_protocol = protocol else: # not redirect - store in redirect fields. self.domain_name = trimmed_domain self.domain_path = path self.full_url = URL_IN self.protocol = protocol # -- END check to see where we store the values. --# # return trimmed domain. value_OUT = trimmed_domain else: # domain value_OUT = "" # -- END check to see what we return. --# return value_OUT