def load_css(self):
        """
        Creates a dict of all icons available in CSS file, and finds out
        what's their common prefix.

        :returns sorted icons dict, common icon prefix
        """
        icons = dict()
        common_prefix = None
        parser = tinycss.make_parser('page3')
        stylesheet = parser.parse_stylesheet_file(self.css_file)

        is_icon = re.compile("\.(.*):before,?")

        for rule in stylesheet.rules:
            selector = rule.selector.as_css()

            # Skip CSS classes that are not icons
            if not is_icon.match(selector):
                continue

            # Find out what the common prefix is
            if common_prefix is None:
                common_prefix = selector[1:]
            else:
                common_prefix = os.path.commonprefix((common_prefix,
                                                      selector[1:]))

            for match in is_icon.finditer(selector):
                name = match.groups()[0]
                for declaration in rule.declarations:
                    if declaration.name == "content":
                        val = declaration.value.as_css()
                        # Strip quotation marks
                        if re.match("^['\"].*['\"]$", val):
                            val = val[1:-1]
                        icons[name] = unichr(int(val[1:], 16))

        common_prefix = common_prefix or ''

        # Remove common prefix
        if not self.keep_prefix and len(common_prefix) > 0:
            non_prefixed_icons = {}
            for name in icons.keys():
                non_prefixed_icons[name[len(common_prefix):]] = icons[name]
            icons = non_prefixed_icons

        sorted_icons = OrderedDict(sorted(icons.items(), key=lambda t: t[0]))

        return sorted_icons, common_prefix
def load_css ( self ) : icons = dict ( ) common_prefix = None parser = tinycss . make_parser ( 'page3' ) stylesheet = parser . parse_stylesheet_file ( self . css_file ) is_icon = re . compile ( "\.(.*):before,?" ) for rule in stylesheet . rules : selector = rule . selector . as_css ( ) if not is_icon . match ( selector ) : continue if common_prefix is None : common_prefix = selector [ 1 : ] else : common_prefix = os . path . commonprefix ( ( common_prefix , selector [ 1 : ] ) ) for match in is_icon . finditer ( selector ) : name = match . groups ( ) [ 0 ] for declaration in rule . declarations : if declaration . name == "content" : val = declaration . value . as_css ( ) if re . match ( "^['\"].*['\"]$" , val ) : val = val [ 1 : - 1 ] icons [ name ] = unichr ( int ( val [ 1 : ] , 16 ) ) common_prefix = common_prefix or '' if not self . keep_prefix and len ( common_prefix ) > 0 : non_prefixed_icons = { } for name in icons . keys ( ) : non_prefixed_icons [ name [ len ( common_prefix ) : ] ] = icons [ name ] icons = non_prefixed_icons sorted_icons = OrderedDict ( sorted ( icons . items ( ) , key = lambda t : t [ 0 ] ) ) return sorted_icons , common_prefix
Creates a dict of all icons available in CSS file, and finds out
        what's their common prefix.

        :returns sorted icons dict, common icon prefix