<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
 """monkey patched reverse path supports easy patching 3rd party urls if 3rd party app has namespace for example ``catalogue`` and you create FeinCMS plugin with same name as this namespace reverse returns url from ApplicationContent ! """


    if not urlconf:
        urlconf = get_urlconf()
    resolver = get_resolver(urlconf)
    args = args or []
    kwargs = kwargs or {}

    prefix = get_script_prefix()

    if not isinstance(viewname, six.string_types):
        view = viewname
    else:
        parts = viewname.split(':')
        parts.reverse()
        view = parts[0]
        path = parts[1:]

        resolved_path = []
        ns_pattern = ''
        while path:
            ns = path.pop()

            # Lookup the name to see if it could be an app identifier
            try:
                app_list = resolver.app_dict[ns]
                # Yes! Path part matches an app in the current Resolver
                if current_app and current_app in app_list:
                    # If we are reversing for a particular app,
                    # use that namespace
                    ns = current_app
                elif ns not in app_list:
                    # The name isn't shared by one of the instances
                    # (i.e., the default) so just pick the first instance
                    # as the default.
                    ns = app_list[0]
            except KeyError:
                pass

            try:
                extra, resolver = resolver.namespace_dict[ns]
                resolved_path.append(ns)
                ns_pattern = ns_pattern + extra
            except KeyError as key:

                for urlconf, config in six.iteritems(
                        ApplicationWidget._feincms_content_models[0].ALL_APPS_CONFIG):

                    partials = viewname.split(':')
                    app = partials[0]
                    partials = partials[1:]

                    # check if namespace is same as app name and try resolve
                    if urlconf.split(".")[-1] == app:

                        try:
                            return app_reverse(
                                ':'.join(partials),
                                urlconf, args=args, kwargs=kwargs,
                                current_app=current_app)
                        except NoReverseMatch:
                            pass

                if resolved_path:
                    raise NoReverseMatch(
                        "%s is not a registered namespace inside '%s'" %
                        (key, ':'.join(resolved_path)))
                else:
                    raise NoReverseMatch("%s is not a registered namespace" %
                                         key)
        if ns_pattern:
            resolver = get_ns_resolver(ns_pattern, resolver)

    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))