# Path: mdn/utils.py
# def is_new_id(_id):
#     """Detect if an ID signifies a new resource.
# 
#     New resource IDs are text strings prefixed with an underscore.
#     """
#     return isinstance(_id, text_type) and _id[0] == '_'
# 
# def normalize_name(name):
#     """Normalize a name for IDs, slugs."""
#     to_remove = ('<code>', '</code>', '&lt;', '&gt;')
#     normalized_name = name.lower()
#     for removal in to_remove:
#         normalized_name = normalized_name.replace(removal, '')
#     return normalized_name
# 
# def slugify(word, length=50, suffix=''):
#     """Create a slugged version of a word or phrase."""
#     raw = word.lower()
#     out = []
#     acceptable = string.ascii_lowercase + string.digits + '_-'
#     for c in raw:
#         if c in acceptable:
#             out.append(c)
#         else:
#             out.append('_')
#     slugged = ''.join(out)
#     while '__' in slugged:
#         slugged = slugged.replace('__', '_')
#     if slugged.endswith('_') and len(slugged) > 1:
#         slugged = slugged[:-1]
#     suffix = text_type(suffix) if suffix else ''
#     with_suffix = slugged[slice(length - len(suffix))] + suffix
#     return with_suffix


from collections import namedtuple
from webplatformcompat.models import (
    Browser, Feature, Section, Specification, Support, Version)
from .utils import is_new_id, normalize_name, slugify
        * slug - A unique slug for this feature
        """
        nname = normalize_name(name)

        # Treat "Basic Support" rows as parent feature
        if nname.lower() == 'basic support':
            return self.FeatureParams(
                parent_feature, parent_feature.id, parent_feature.slug)

        # Initialize subfeature data as needed
        if parent_feature.id not in self.subfeature_data:
            subfeatures = {}
            for feature in Feature.objects.filter(parent=parent_feature):
                if 'zxx' in feature.name:
                    fname = feature.name['zxx']
                else:
                    fname = feature.name['en']
                fname = normalize_name(fname)
                subfeatures[fname] = self.FeatureParams(
                    feature, feature.id, feature.slug)
            self.subfeature_data[parent_feature.id] = subfeatures

        # Select the Feature ID and slug
        subfeatures = self.subfeature_data[parent_feature.id]
        if nname not in subfeatures:
            feature_id = '_' + nname
            attempt = 0
            feature_slug = None
            while not feature_slug:
                base_slug = parent_feature.slug + '_' + nname

# Path: mdn/utils.py
# def is_new_id(_id):
#     """Detect if an ID signifies a new resource.
# 
#     New resource IDs are text strings prefixed with an underscore.
#     """
#     return isinstance(_id, text_type) and _id[0] == '_'
# 
# def normalize_name(name):
#     """Normalize a name for IDs, slugs."""
#     to_remove = ('<code>', '</code>', '&lt;', '&gt;')
#     normalized_name = name.lower()
#     for removal in to_remove:
#         normalized_name = normalized_name.replace(removal, '')
#     return normalized_name
# 
# def slugify(word, length=50, suffix=''):
#     """Create a slugged version of a word or phrase."""
#     raw = word.lower()
#     out = []
#     acceptable = string.ascii_lowercase + string.digits + '_-'
#     for c in raw:
#         if c in acceptable:
#             out.append(c)
#         else:
#             out.append('_')
#     slugged = ''.join(out)
#     while '__' in slugged:
#         slugged = slugged.replace('__', '_')
#     if slugged.endswith('_') and len(slugged) > 1:
#         slugged = slugged[:-1]
#     suffix = text_type(suffix) if suffix else ''
#     with_suffix = slugged[slice(length - len(suffix))] + suffix
#     return with_suffix


# Path: mdn/data.py
from collections import namedtuple
from webplatformcompat.models import (
    Browser, Feature, Section, Specification, Support, Version)
from .utils import is_new_id, normalize_name, slugify

        * slug - A unique slug for this feature
        """
        nname = normalize_name(name)

        # Treat "Basic Support" rows as parent feature
        if nname.lower() == 'basic support':
            return self.FeatureParams(
                parent_feature, parent_feature.id, parent_feature.slug)

        # Initialize subfeature data as needed
        if parent_feature.id not in self.subfeature_data:
            subfeatures = {}
            for feature in Feature.objects.filter(parent=parent_feature):
                if 'zxx' in feature.name:
                    fname = feature.name['zxx']
                else:
                    fname = feature.name['en']
                fname = normalize_name(fname)
                subfeatures[fname] = self.FeatureParams(
                    feature, feature.id, feature.slug)
            self.subfeature_data[parent_feature.id] = subfeatures

        # Select the Feature ID and slug
        subfeatures = self.subfeature_data[parent_feature.id]
        if nname not in subfeatures:
            feature_id = '_' + nname
            attempt = 0
            feature_slug = None
            while not feature_slug:
                base_slug = parent_feature.slug + '_' + nname

                feature_slug = slugify(base_slug, suffix=attempt)