def __new__(cls, prefix=None):
        obj = object.__new__(cls)
        obj.pluggable_unique_identifier = '/@@pluggableapp@@/%s/' % str(uuid.uuid4())
        obj.pluggable_prefix = prefix
        view_prefix = cls.urlpatterns[0]
        urlpatterns = []
        for pattern_type, pattern_args, pattern_kwargs in copy.deepcopy(cls.urlpatterns[1:]):
            if pattern_type == 'url':
                view = pattern_args[1]
                if type(view) == list:
                    raise Exception("Pluggable applications do not support 'include(...)' url definitions.")

                # Handle a view directly
                if callable(view):
                    pattern_args[1] = pluggable_view(view, obj)
                # Handle a view_prefix combined with function name or a full view path
                elif isinstance(view, (str, unicode)) and (view_prefix or '.' in view):
                    view_name = view_prefix and '%s.%s' % (view_prefix, view) or view
                    try:
                        pattern_args[1] = pluggable_view(get_callable(view), obj)
                    except __HOLE__, e:
                        mod_name, _ = get_mod_func(view)
                        raise ViewDoesNotExist("Could not import %s. Error was: %s" % (mod_name, str(e)))
                    except AttributeError, e:
                        mod_name, func_name = get_mod_func(view)
                        raise ViewDoesNotExist("Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e)))
                # Handle class view.
                elif isinstance(view, (str, unicode)) and hasattr(obj, view):
                    # Avoid reapplying pluggable view decorator when it has aready been applied. (i.e. the same function is reused in the same configuration.
                    if not getattr(getattr(obj, view), 'pluggable_unique_identifier', '') == obj.pluggable_unique_identifier:
                        setattr(obj, view, pluggable_class_view(getattr(obj, view), obj))
                    pattern_args[1] = getattr(obj, view)
                else:
                    raise ViewDoesNotExist('Invalid view type. %s' % view)

                if 'name' in pattern_kwargs:
                    pattern_kwargs['name'] = '%s%s' % (obj.pluggable_prefix and '%s_' % obj.pluggable_prefix or '', pattern_kwargs['name'])

                urlpatterns.append(defaults.url(*pattern_args, **pattern_kwargs))
            elif pattern_type == 'include':
                urlpatterns.append(defaults.include(*pattern_args, **pattern_kwargs))
            else:
                raise Exception('Invalid url pattern type.')
        urlpatterns.append(defaults.url(r'^.*%s$' % obj.pluggable_unique_identifier, pluggable_placeholder, name='%s%s' % (obj.pluggable_prefix and '%s_' % obj.pluggable_prefix or '', obj.pluggable_unique_identifier)))
        obj.urlpatterns = defaults.patterns('', *urlpatterns)
        return obj
dataset/ETHPy150Open nowells/django-pluggables/pluggables/__init__.py/PluggableApp.__new__