@staticmethod
    def _generate_urls_for_elements(elements):

        def __generate(elements):
            """ Recursive support function.
            """
            new_urls = [[]]
            for elem in elements:
                if isinstance(elem, (Constant, Variable)):
                    sub_urls = elem.get_regexp()
                    if not isinstance(sub_urls, list):
                        sub_urls = [sub_urls]
                    new_urls = [x + [elem.prefix + y + elem.suffix]
                                for x in new_urls for y in sub_urls]
                elif isinstance(elem, Optional):
                    sub_urls = __generate(elem.args)
                    new_urls.extend([x + y
                                     for x in new_urls
                                     for y in sub_urls])
            return new_urls

        return ["^%s$" % "".join(x) for x in __generate(elements)]
Static method for generating urls from a list of urls_sugar
dataset/ETHPy150Open armisael/django-urls-sugar/urls_sugar/classes.py/UrlSugar._generate_urls_for_elements